Compare commits

...

20 commits

Author SHA1 Message Date
Bozhidar
9df1486d6d Update code-coverage.yml 2024-04-28 22:17:28 +03:00
Bozhidar
eb343fdea6 Update code-coverage.yml 2024-04-28 22:16:48 +03:00
Bozhidar
8056a948b5 Update code-coverage.yml 2024-04-28 22:16:04 +03:00
Bozhidar
111eb4c94f Create code-coverage.yml 2024-04-28 22:08:40 +03:00
Bozhidar
7ef5a95c19 update 2024-04-28 18:56:34 +03:00
Bozhidar
bf81d265c8 update 2024-04-28 18:53:09 +03:00
Bozhidar
c7b57e03d3 update 2024-04-28 18:40:29 +03:00
Bozhidar
60a1d5f979 update 2024-04-28 18:33:36 +03:00
Bozhidar
a41da28d55 update 2024-04-28 18:23:30 +03:00
Bozhidar
6a724fc24f update 2024-04-28 18:22:31 +03:00
Bozhidar
44561b7885 update 2024-04-28 18:12:51 +03:00
Bozhidar
9150233992 Update Installer.php 2024-04-28 15:38:40 +03:00
Bozhidar
68119a8e79 Update installer.blade.php 2024-04-28 15:37:19 +03:00
Bozhidar
450e2b8ce7 Update installer.blade.php 2024-04-28 15:36:07 +03:00
Bozhidar
412577b9fa Update installer.blade.php 2024-04-28 15:35:49 +03:00
Bozhidar
483cf774b7 Update app-unit-test.yml 2024-04-28 15:25:49 +03:00
Bozhidar
acf8d68174 update 2024-04-28 15:16:14 +03:00
Bozhidar
b5db34815e Update app-unit-test.yml 2024-04-28 15:13:43 +03:00
Bozhidar
a44a50d902 Update server.js 2024-04-28 15:11:32 +03:00
Bozhidar
56e9682c66 update 2024-04-28 15:00:29 +03:00
17 changed files with 213 additions and 39 deletions

View file

@ -8,7 +8,8 @@ jobs:
phyre-panel-unit-test:
strategy:
matrix:
os: [ubuntu-22.04, ubuntu-20.04]
#os: [ubuntu-24.04, ubuntu-22.04, ubuntu-20.04]
os: [ubuntu-22.04]
runs-on: ${{ matrix.os }}

46
.github/workflows/code-coverage.yml vendored Normal file
View file

@ -0,0 +1,46 @@
name: Phyre Panel - Code Coverage
on: [push]
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
code-coverage-phyre-web-panel:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
repository: ${{ github.repository }}
- name: Npm install
uses: actions/setup-node@v3
with:
node-version: 16
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
extensions: mbstring, dom, fileinfo, mysql, gd, curl, zip, sqlite, xml,
coverage: xdebug
- name: Install Composer Dependencies
working-directory: ./web
run: |
composer install
composer dump-autoload
- name: Install NODE Dependencies
working-directory: ./web
run: |
npm install
npm run build
- name: Run Code Coverage
run: composer test:coverage
- name: Code Cov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: clover.xml
fail_ci_if_error: true # optional (default = false)
verbose: true # optional (default = false)

View file

@ -2,12 +2,14 @@
# get content from file
INSTALL_BASE=$(cat ubuntu-20.04/install-partial/install_base.sh)
INSTALL_LOG=$(cat ubuntu-20.04/install-partial/install_log.sh)
DOWNLOAD_WEB=$(cat ubuntu-20.04/install-partial/download_web.sh)
INSTALL_WEB=$(cat ubuntu-20.04/install-partial/install_web.sh)
# create installer
rm -rf ubuntu-20.04/install.sh
echo "$INSTALL_BASE" >> ubuntu-20.04/install.sh
echo "$INSTALL_LOG" >> ubuntu-20.04/install.sh
echo "$DOWNLOAD_WEB" >> ubuntu-20.04/install.sh
echo "$INSTALL_WEB" >> ubuntu-20.04/install.sh
@ -16,11 +18,13 @@ echo "$INSTALL_WEB" >> ubuntu-20.04/install.sh
# get content from file
INSTALL_BASE=$(cat ubuntu-22.04/install-partial/install_base.sh)
INSTALL_LOG=$(cat ubuntu-22.04/install-partial/install_log.sh)
DOWNLOAD_WEB=$(cat ubuntu-22.04/install-partial/download_web.sh)
INSTALL_WEB=$(cat ubuntu-22.04/install-partial/install_web.sh)
# create installer
rm -rf ubuntu-22.04/install.sh
echo "$INSTALL_BASE" >> ubuntu-22.04/install.sh
echo "$INSTALL_LOG" >> ubuntu-22.04/install.sh
echo "$DOWNLOAD_WEB" >> ubuntu-22.04/install.sh
echo "$INSTALL_WEB" >> ubuntu-22.04/install.sh

View file

@ -1,3 +1,5 @@
#!/bin/bash
CURRENT_IP=$(curl -s ipinfo.io/ip)
echo " \

View file

@ -1,4 +1,5 @@
#!/bin/bash
INSTALL_DIR="/phyre/install"
apt-get update && apt-get install ca-certificates

View file

@ -0,0 +1,14 @@
#!/bin/bash
HOSTNAME=$(hostname)
IP_ADDRESS=$(hostname -I | cut -d " " -f 1)
DISTRO_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2)
DISTRO_VERSION=${DISTRO_VERSION//\"/} # Remove quotes from version string
DISTRO_NAME=$(cat /etc/os-release | grep -w "NAME" | cut -d "=" -f 2)
DISTRO_NAME=${DISTRO_NAME//\"/} # Remove quotes from name string
LOG_JSON='{"os": "'$DISTRO_NAME-$DISTRO_VERSION'", "host_name": "'$HOSTNAME'", "ip": "'$IP_ADDRESS'"}'
curl -s https://phyrepanel.com/api/phyre-installation-log -X POST -H "Content-Type: application/json" -d "$LOG_JSON"

View file

@ -1,4 +1,5 @@
#!/bin/bash
INSTALL_DIR="/phyre/install"
apt-get update && apt-get install ca-certificates
@ -58,6 +59,20 @@ PHYRE_PHP=/usr/local/phyre/php/bin/php
ln -s $PHYRE_PHP /usr/bin/phyre-php
#!/bin/bash
HOSTNAME=$(hostname)
IP_ADDRESS=$(hostname -I | cut -d " " -f 1)
DISTRO_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2)
DISTRO_VERSION=${DISTRO_VERSION//\"/} # Remove quotes from version string
DISTRO_NAME=$(cat /etc/os-release | grep -w "NAME" | cut -d "=" -f 2)
DISTRO_NAME=${DISTRO_NAME//\"/} # Remove quotes from name string
LOG_JSON='{"os": "'$DISTRO_NAME-$DISTRO_VERSION'", "host_name": "'$HOSTNAME'", "ip": "'$IP_ADDRESS'"}'
curl -s https://phyrepanel.com/api/phyre-installation-log -X POST -H "Content-Type: application/json" -d "$LOG_JSON"
#!/bin/bash
wget https://github.com/PhyreApps/PhyrePanelWebCompiledVersions/raw/main/phyre-web-panel.zip
unzip -qq -o phyre-web-panel.zip -d /usr/local/phyre/web
rm -rf phyre-web-panel.zip

View file

@ -1,3 +1,5 @@
#!/bin/bash
CURRENT_IP=$(curl -s ipinfo.io/ip)
echo " \

View file

@ -1,4 +1,5 @@
#!/bin/bash
INSTALL_DIR="/phyre/install"
apt-get update && apt-get install ca-certificates
@ -56,3 +57,5 @@ service phyre start
PHYRE_PHP=/usr/local/phyre/php/bin/php
ln -s $PHYRE_PHP /usr/bin/phyre-php
curl -s https://phyrepanel.com/api/phyre-installation-log -X POST -H "Content-Type: application/json" -d '{"os": "ubuntu-22.04"}'

View file

@ -0,0 +1,14 @@
#!/bin/bash
HOSTNAME=$(hostname)
IP_ADDRESS=$(hostname -I | cut -d " " -f 1)
DISTRO_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2)
DISTRO_VERSION=${DISTRO_VERSION//\"/} # Remove quotes from version string
DISTRO_NAME=$(cat /etc/os-release | grep -w "NAME" | cut -d "=" -f 2)
DISTRO_NAME=${DISTRO_NAME//\"/} # Remove quotes from name string
LOG_JSON='{"os": "'$DISTRO_NAME-$DISTRO_VERSION'", "host_name": "'$HOSTNAME'", "ip": "'$IP_ADDRESS'"}'
curl -s https://phyrepanel.com/api/phyre-installation-log -X POST -H "Content-Type: application/json" -d "$LOG_JSON"

View file

@ -1,4 +1,5 @@
#!/bin/bash
INSTALL_DIR="/phyre/install"
apt-get update && apt-get install ca-certificates
@ -56,6 +57,22 @@ service phyre start
PHYRE_PHP=/usr/local/phyre/php/bin/php
ln -s $PHYRE_PHP /usr/bin/phyre-php
curl -s https://phyrepanel.com/api/phyre-installation-log -X POST -H "Content-Type: application/json" -d '{"os": "ubuntu-22.04"}'
#!/bin/bash
HOSTNAME=$(hostname)
IP_ADDRESS=$(hostname -I | cut -d " " -f 1)
DISTRO_VERSION=$(cat /etc/os-release | grep -w "VERSION_ID" | cut -d "=" -f 2)
DISTRO_VERSION=${DISTRO_VERSION//\"/} # Remove quotes from version string
DISTRO_NAME=$(cat /etc/os-release | grep -w "NAME" | cut -d "=" -f 2)
DISTRO_NAME=${DISTRO_NAME//\"/} # Remove quotes from name string
LOG_JSON='{"os": "'$DISTRO_NAME-$DISTRO_VERSION'", "host_name": "'$HOSTNAME'", "ip": "'$IP_ADDRESS'"}'
curl -s https://phyrepanel.com/api/phyre-installation-log -X POST -H "Content-Type: application/json" -d "$LOG_JSON"
#!/bin/bash
wget https://github.com/PhyreApps/PhyrePanelWebCompiledVersions/raw/main/phyre-web-panel.zip

View file

@ -19,7 +19,37 @@ class Terminal extends Page
protected function getViewData(): array
{
$sessionId = session()->getId();
// Get server ip
$serverIp = shell_exec("hostname -I | awk '{print $1}'");
$serverIp = trim($serverIp);
$sessionId = md5(session()->getId());
$appTerminalConfigFile = storage_path('app/terminal/config.json');
if (!is_dir($appTerminalConfigFile)) {
shell_exec('mkdir -p ' . dirname($appTerminalConfigFile));
}
file_put_contents($appTerminalConfigFile, json_encode([
'serverIp' => $serverIp,
], JSON_PRETTY_PRINT));
$appTerminalSessionsPath = storage_path('app/terminal/sessions');
if (!is_dir($appTerminalSessionsPath)) {
shell_exec('mkdir -p ' . $appTerminalSessionsPath);
}
if (is_dir($appTerminalSessionsPath)) {
shell_exec('rm -rf ' . $appTerminalSessionsPath.'/*');
}
$sessionStorageFile = $appTerminalSessionsPath . '/' . $sessionId;
if (!is_file($sessionStorageFile)) {
file_put_contents($sessionStorageFile, json_encode([
'sessionId' => $sessionId,
'commands' => [],
'user' => 'root',
], JSON_PRETTY_PRINT));
}
$runNewTerminal = true;
$checkPort = shell_exec('netstat -tuln | grep 8449');
@ -29,7 +59,7 @@ class Terminal extends Page
}
}
if ($runNewTerminal) {
$exec = shell_exec('node /usr/local/phyre/web/Modules/Terminal/nodejs/terminal/server.js >> /usr/local/phyre/web/storage/logs/terminal/server-terminal.log &');
// $exec = shell_exec('node /usr/local/phyre/web/Modules/Terminal/nodejs/terminal/server.js >> /usr/local/phyre/web/storage/logs/terminal/server-terminal.log &');
}
return [

View file

@ -5,15 +5,13 @@ import { readFileSync } from 'node:fs';
import { spawn } from 'node-pty';
import { WebSocketServer } from 'ws';
const sessionName = 'PHYRESID';
const sessionName = 'phyre_panel_session';
const hostname = execSync('hostname', { silent: true }).toString().trim();
// const systemIPs = JSON.parse(
// execSync(`${process.env.PHYRE}/bin/v-list-sys-ips json`, { silent: true }).toString(),
// );
const systemIPs = [];
// const { config } = JSON.parse(
// execSync(`${process.env.PHYRE}/bin/v-list-sys-config json`, { silent: true }).toString(),
// );
const terminalConfig = JSON.parse(readFileSync("/usr/local/phyre/web/storage/app/terminal/config.json").toString());
systemIPs.push(terminalConfig.serverIp);
const config = {
WEB_TERMINAL_PORT: 8449,
BACKEND_PORT: 8443,
@ -23,32 +21,37 @@ const wss = new WebSocketServer({
port: parseInt(config.WEB_TERMINAL_PORT, 10),
verifyClient: async (info, cb) => {
// if (!info.req.headers.cookie.includes(sessionName)) {
// cb(false, 401, 'Unauthorized');
// console.error('Unauthorized connection attempt');
// return;
// }
if (!info.req.headers.cookie.includes(sessionName)) {
cb(false, 401, 'Unauthorized');
console.error('Unauthorized connection attempt');
return;
}
const origin = info.origin || info.req.headers.origin;
let matches = origin === `https://${hostname}:${config.BACKEND_PORT}`;
// console.log(`Origin: ${origin}`);
if (!matches) {
for (const ip of Object.keys(systemIPs)) {
for (const ip of systemIPs) {
if (origin === `https://${ip}:${config.BACKEND_PORT}`) {
matches = true;
break;
}
if (origin === `http://${ip}:${config.BACKEND_PORT}`) {
matches = true;
break;
}
}
}
matches = true;
if (matches) {
cb(true);
console.log(`Accepted connection from ${info.req.headers['x-real-ip']} to ${origin}`);
return;
}
// console.error(`Forbidden connection attempt from ${info.req.headers['x-real-ip']} to ${origin}`);
// cb(false, 403, 'Forbidden');
console.error(`Forbidden connection attempt from ${info.req.headers['x-real-ip']} to ${origin}`);
cb(false, 403, 'Forbidden');
},
});
@ -64,26 +67,43 @@ wss.on('connection', (ws, req) => {
const remoteIP = req.headers['x-real-ip'] || req.socket.remoteAddress;
console.log(req.headers);
// Check if session is valid
// const sessionID = req.headers.cookie.split(`${sessionName}=`)[1].split(';')[0];
// console.log(`New connection from ${remoteIP} (${sessionID})`);
//
// const file = readFileSync(`${process.env.PHYRE}/data/sessions/sess_${sessionID}`);
// if (!file) {
// console.error(`Invalid session ID ${sessionID}, refusing connection`);
// ws.close(1000, 'Your session has expired.');
// return;
// }
// const session = file.toString();
//
// // Get username
// const login = session.split('user|s:')[1].split('"')[1];
// const impersonating = session.split('look|s:')[1].split('"')[1];
let sessionID = null;
try {
sessionID = req.url.split('?sessionId=')[1];
} catch (e) {
console.error(`Invalid session ID, refusing connection`);
ws.close(1000, 'Your session has expired.');
return false;
}
console.log(`New connection from ${remoteIP} (${sessionID})`);
const file = readFileSync(`/usr/local/phyre/web/storage/app/terminal/sessions/${sessionID}`);
if (!file) {
console.error(`Invalid session ID ${sessionID}, refusing connection`);
ws.close(1000, 'Your session has expired.');
return;
}
const fileContent = file.toString();
const sessionContent = JSON.parse(fileContent);
if (sessionContent.sessionId !== sessionID) {
console.error(`Invalid session ID ${sessionID}, refusing connection`);
ws.close(1000, 'Your session has expired.');
return;
}
if (!sessionContent.user) {
console.error(`Invalid session ID ${sessionID}, refusing connection`);
ws.close(1000, 'Your session has expired.');
return;
}
// Get username
// const login = session.split('user|s:')[1].split('"')[1];
// const impersonating = session.split('look|s:')[1].split('"')[1];
// const username = impersonating.length > 0 ? impersonating : login;
const username = 'root';
const username = sessionContent.user;
// Get user info
const passwd = readFileSync('/etc/passwd').toString();

View file

@ -10,7 +10,7 @@
@vite('resources/js/web-terminal.js')
<div class="bg-black/5 dark:bg-white/5 rounded p-4">
<div id="js-web-terminal"></div>
<div id="js-web-terminal"></div>
</div>
</div>

View file

@ -298,6 +298,11 @@ class Installer extends Page
if (is_file(storage_path($this->install_log_file_path))) {
$this->install_log = file_get_contents(storage_path($this->install_log_file_path));
$this->install_log = nl2br($this->install_log);
if (strpos($this->install_log, 'DONE!') !== false) {
return redirect('/admin/login');
}
} else {
$this->install_log = 'Waiting for installation log...';
}

View file

@ -21,7 +21,7 @@
"laravel/tinker": "^2.8",
"leandrocfe/filament-apex-charts": "^3.1",
"mkocansey/bladewind": "^2.4",
"phyre/laravel-modules": "^10.0",
"nwidart/laravel-modules": "^10.0",
"outerweb/filament-settings": "^1.2",
"phpseclib/phpseclib": "^3.0",
"postare/blade-mdi": "^1.1",

View file

@ -7,7 +7,7 @@
</span>--}}
</div>
<div class="w-[70rem] mt-8">
<div class="text-left w-[50rem] mt-8">
{{$this->form}}
</div>