diff --git a/Makefile b/Makefile index 1340399..89b2704 100644 --- a/Makefile +++ b/Makefile @@ -239,6 +239,7 @@ set_permissions: chmod 0775 $(TEMP_DIR)/bin/install 2>/dev/null || [ $$? -eq 1 ] chmod 0644 $(TEMP_DIR)/bin/install/database.sql 2>/dev/null || [ $$? -eq 1 ] + chmod 0644 $(TEMP_DIR)/bin/install/proxy.tar.gz 2>/dev/null || [ $$? -eq 1 ] chmod 0750 $(TEMP_DIR)/bin/maxmind 2>/dev/null || [ $$? -eq 1 ] chmod 0750 $(TEMP_DIR)/bin/maxmind/GeoIP2-ISP.mmdb 2>/dev/null || [ $$? -eq 1 ] diff --git a/src/bin/install/proxy.tar.gz b/src/bin/install/proxy.tar.gz new file mode 100644 index 0000000..11c44a2 Binary files /dev/null and b/src/bin/install/proxy.tar.gz differ diff --git a/src/includes/cli/balancer.php b/src/includes/cli/balancer.php index 671270a..dc87ea2 100644 --- a/src/includes/cli/balancer.php +++ b/src/includes/cli/balancer.php @@ -28,13 +28,8 @@ if ($argc && $argc >= 6) { $rInstallDir = BIN_PATH . 'install/'; if ($rType == 1) { - $rPackages = array('iproute2', 'net-tools', 'libcurl4', 'libxslt1-dev', 'libonig-dev', 'e2fsprogs', 'wget', 'sysstat', 'mcrypt', 'python3', 'certbot', 'iptables-persistent', 'libjpeg-dev', 'libpng-dev', 'php-ssh2', 'xz-utils', 'zip', 'unzip'); - $UpdateData = $gitRelease->getUpdateFile("proxy", XC_VM_VERSION); - - $rInstallFiles = $UpdateData['url']; - $hash = $UpdateData['md5']; - - exit(); // заглушка чтобы процесс не продолжался + $rPackages = array('iproute2', 'net-tools', 'libcurl4', 'libxslt1-dev', 'libonig-dev', 'e2fsprogs', 'wget', 'sysstat', 'mcrypt', 'python3', 'certbot', 'iptables-persistent', 'libjpeg-dev', 'libpng-dev', 'php-ssh2', 'xz-utils', 'zip', 'unzip', 'cron'); + $rInstallFiles = 'proxy.tar.gz'; } elseif ($rType == 2) { $rPackages = array('cpufrequtils', 'iproute2', 'python', 'net-tools', 'dirmngr', 'gpg-agent', 'software-properties-common', 'libmaxminddb0', 'libmaxminddb-dev', 'mmdb-bin', 'libcurl4', 'libgeoip-dev', 'libxslt1-dev', 'libonig-dev', 'e2fsprogs', 'wget', 'sysstat', 'alsa-utils', 'v4l-utils', 'mcrypt', 'python3', 'certbot', 'iptables-persistent', 'libjpeg-dev', 'libpng-dev', 'php-ssh2', 'xz-utils', 'zip', 'unzip', 'cron', 'libfribidi-dev', 'libharfbuzz-dev', 'libogg0'); $UpdateData = $gitRelease->getUpdateFile("lb", XC_VM_VERSION); @@ -85,27 +80,46 @@ if ($argc && $argc >= 6) { runCommand($rConn, 'sudo rm -rf ' . BIN_PATH); } - echo 'Download archive' . "\n"; - runCommand($rConn, 'wget --timeout=2 -O /tmp/XC_VM.tar.gz -o /dev/null "' . $rInstallFiles . '"'); - $fileHash = runCommand($rConn, 'md5=($(md5sum /tmp/XC_VM.tar.gz)); echo $md5;'); - if (!empty($fileHash['output']) && $hash == trim($fileHash['output'])) { - echo 'Extracting to directory' . "\n"; - $rRet = runCommand($rConn, 'sudo rm -rf ' . MAIN_HOME . 'status'); - $rRet = runCommand($rConn, 'sudo tar -zxvf "/tmp/XC_VM.tar.gz" -C "' . MAIN_HOME . '"'); - if (file_exists(MAIN_HOME . 'status')) { - runCommand($rConn, 'sudo rm -f "/tmp/XC_VM.tar.gz"'); + if ($rType == 1) { + if (sendfile($rConn, $rInstallDir . $rInstallFiles, '/tmp/' . $rInstallFiles, true)) { + echo 'Extracting to directory' . "\n"; + $rRet = runCommand($rConn, 'sudo rm -rf ' . MAIN_HOME . 'status'); + $rRet = runCommand($rConn, 'sudo tar -zxvf "/tmp/' . $rInstallFiles . '" -C "' . MAIN_HOME . '"'); + if (file_exists(MAIN_HOME . 'status')) { + // runCommand($rConn, 'sudo rm -f "/tmp/' . $rInstallFiles . '.tar.gz"'); + } else { + $db->query('UPDATE `servers` SET `status` = 4 WHERE `id` = ?;', $rServerID); + echo 'Failed to extract files! Exiting' . "\n"; + exit(); + } } else { $db->query('UPDATE `servers` SET `status` = 4 WHERE `id` = ?;', $rServerID); - echo 'Failed to extract files! Exiting' . "\n"; + echo 'Invalid MD5 checksum! Exiting' . "\n"; exit(); } } else { - $db->query('UPDATE `servers` SET `status` = 4 WHERE `id` = ?;', $rServerID); - echo 'Invalid MD5 checksum! Exiting' . "\n"; - exit(); + echo 'Download archive' . "\n"; + runCommand($rConn, 'wget --timeout=2 -O /tmp/XC_VM.tar.gz -o /dev/null "' . $rInstallFiles . '"'); + $fileHash = runCommand($rConn, 'md5=($(md5sum /tmp/XC_VM.tar.gz)); echo $md5;'); + if (!empty($fileHash['output']) && $hash == trim($fileHash['output'])) { + echo 'Extracting to directory' . "\n"; + $rRet = runCommand($rConn, 'sudo rm -rf ' . MAIN_HOME . 'status'); + $rRet = runCommand($rConn, 'sudo tar -zxvf "/tmp/XC_VM.tar.gz" -C "' . MAIN_HOME . '"'); + if (file_exists(MAIN_HOME . 'status')) { + runCommand($rConn, 'sudo rm -f "/tmp/XC_VM.tar.gz"'); + } else { + $db->query('UPDATE `servers` SET `status` = 4 WHERE `id` = ?;', $rServerID); + echo 'Failed to extract files! Exiting' . "\n"; + exit(); + } + } else { + $db->query('UPDATE `servers` SET `status` = 4 WHERE `id` = ?;', $rServerID); + echo 'Invalid MD5 checksum! Exiting' . "\n"; + exit(); + } } - if ($rType == 2) { + if ($rType == 2) { if (stripos(runCommand($rConn, 'sudo cat /etc/fstab')['output'], STREAMS_PATH) !== true) { echo 'Adding ramdisk mounts' . "\n"; runCommand($rConn, 'sudo echo "tmpfs ' . STREAMS_PATH . ' tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=90% 0 0" >> /etc/fstab'); @@ -154,12 +168,14 @@ if ($argc && $argc >= 6) { runCommand($rConn, 'sudo systemctl enable xc_vm'); if ($rType == 1) { runCommand($rConn, 'sudo rm /home/xc_vm/bin/nginx/conf/servers/*.conf'); + $rServices = 1; foreach ($rParentIDs as $rParentID) { if ($rPrivateIP) { $rIP = CoreUtilities::$rServers[$rParentID]['private_ip'] . ':' . CoreUtilities::$rServers[$rParentID]['http_broadcast_port']; } else { $rIP = CoreUtilities::$rServers[$rParentID]['server_ip'] . ':' . CoreUtilities::$rServers[$rParentID]['http_broadcast_port']; } + $rKey = ''; if (CoreUtilities::$rServers[$rParentID]['is_main']) { $rConfigText = 'location / {' . "\n" . ' include options.conf;' . "\n" . ' proxy_pass http://' . $rIP . '$1;' . "\n" . '}'; } else { @@ -180,30 +196,28 @@ if ($argc && $argc >= 6) { sendfile($rConn, MAIN_HOME . 'bin/nginx/conf/realip_xc_vm.conf', MAIN_HOME . 'bin/nginx/conf/realip_xc_vm.conf'); runCommand($rConn, 'sudo echo "" > "/home/xc_vm/bin/nginx/conf/limit.conf"'); runCommand($rConn, 'sudo echo "" > "/home/xc_vm/bin/nginx/conf/limit_queue.conf"'); - if ($rType == 2) { - $rIP = '127.0.0.1:' . CoreUtilities::$rServers[$rServerID]['http_broadcast_port']; - runCommand($rConn, 'sudo echo "on_play http://' . $rIP . '/stream/rtmp; on_publish http://' . $rIP . '/stream/rtmp; on_play_done http://' . $rIP . '/stream/rtmp;" > "/home/xc_vm/bin/nginx_rtmp/conf/live.conf"'); - $rServices = (intval(runCommand($rConn, 'sudo cat /proc/cpuinfo | grep "^processor" | wc -l')['output']) ?: 4); - runCommand($rConn, 'sudo rm ' . MAIN_HOME . 'bin/php/etc/*.conf'); - $rNewScript = '#! /bin/bash' . "\n"; - $rNewBalance = 'upstream php {' . "\n" . ' least_conn;' . "\n"; - $rTemplate = file_get_contents(MAIN_HOME . 'bin/php/etc/template'); - foreach (range(1, $rServices) as $i) { - $rNewScript .= 'start-stop-daemon --start --quiet --pidfile ' . MAIN_HOME . 'bin/php/sockets/' . $i . '.pid --exec ' . MAIN_HOME . 'bin/php/sbin/php-fpm -- --daemonize --fpm-config ' . MAIN_HOME . 'bin/php/etc/' . $i . '.conf' . "\n"; - $rNewBalance .= ' server unix:' . MAIN_HOME . 'bin/php/sockets/' . $i . '.sock;' . "\n"; - $rTmpPath = TMP_PATH . md5(time() . $i . '.conf'); - file_put_contents($rTmpPath, str_replace('#PATH#', MAIN_HOME, str_replace('#ID#', $i, $rTemplate))); - sendfile($rConn, $rTmpPath, MAIN_HOME . 'bin/php/etc/' . $i . '.conf'); - } - $rNewBalance .= '}'; - $rTmpPath = TMP_PATH . md5(time() . 'daemons.sh'); - file_put_contents($rTmpPath, $rNewScript); - sendfile($rConn, $rTmpPath, MAIN_HOME . 'bin/daemons.sh'); - $rTmpPath = TMP_PATH . md5(time() . 'balance.conf'); - file_put_contents($rTmpPath, $rNewBalance); - sendfile($rConn, $rTmpPath, MAIN_HOME . 'bin/nginx/conf/balance.conf'); - runCommand($rConn, 'sudo chmod +x ' . MAIN_HOME . 'bin/daemons.sh'); + $rIP = '127.0.0.1:' . CoreUtilities::$rServers[$rServerID]['http_broadcast_port']; + runCommand($rConn, 'sudo echo "on_play http://' . $rIP . '/stream/rtmp; on_publish http://' . $rIP . '/stream/rtmp; on_play_done http://' . $rIP . '/stream/rtmp;" > "/home/xc_vm/bin/nginx_rtmp/conf/live.conf"'); + $rServices = (intval(runCommand($rConn, 'sudo cat /proc/cpuinfo | grep "^processor" | wc -l')['output']) ?: 4); + runCommand($rConn, 'sudo rm ' . MAIN_HOME . 'bin/php/etc/*.conf'); + $rNewScript = '#! /bin/bash' . "\n"; + $rNewBalance = 'upstream php {' . "\n" . ' least_conn;' . "\n"; + $rTemplate = file_get_contents(MAIN_HOME . 'bin/php/etc/template'); + foreach (range(1, $rServices) as $i) { + $rNewScript .= 'start-stop-daemon --start --quiet --pidfile ' . MAIN_HOME . 'bin/php/sockets/' . $i . '.pid --exec ' . MAIN_HOME . 'bin/php/sbin/php-fpm -- --daemonize --fpm-config ' . MAIN_HOME . 'bin/php/etc/' . $i . '.conf' . "\n"; + $rNewBalance .= ' server unix:' . MAIN_HOME . 'bin/php/sockets/' . $i . '.sock;' . "\n"; + $rTmpPath = TMP_PATH . md5(time() . $i . '.conf'); + file_put_contents($rTmpPath, str_replace('#PATH#', MAIN_HOME, str_replace('#ID#', $i, $rTemplate))); + sendfile($rConn, $rTmpPath, MAIN_HOME . 'bin/php/etc/' . $i . '.conf'); } + $rNewBalance .= '}'; + $rTmpPath = TMP_PATH . md5(time() . 'daemons.sh'); + file_put_contents($rTmpPath, $rNewScript); + sendfile($rConn, $rTmpPath, MAIN_HOME . 'bin/daemons.sh'); + $rTmpPath = TMP_PATH . md5(time() . 'balance.conf'); + file_put_contents($rTmpPath, $rNewBalance); + sendfile($rConn, $rTmpPath, MAIN_HOME . 'bin/nginx/conf/balance.conf'); + runCommand($rConn, 'sudo chmod +x ' . MAIN_HOME . 'bin/daemons.sh'); } $rSystemConf = runCommand($rConn, 'sudo cat "/etc/systemd/system.conf"')['output']; if (strpos($rSystemConf, 'DefaultLimitNOFILE=1048576') !== false) { diff --git a/src/includes/libs/GithubReleases.php b/src/includes/libs/GithubReleases.php index 22b8133..58c314c 100644 --- a/src/includes/libs/GithubReleases.php +++ b/src/includes/libs/GithubReleases.php @@ -365,12 +365,6 @@ class GitHubReleases { case "lb_update": $update_file = "loadbalancer_update.tar.gz"; break; - case "proxy": - $update_file = "proxy.tar.gz"; - break; - case "proxy_update": - $update_file = "proxy_update.tar.gz"; - break; default: throw new Exception("Not valid file type"); } diff --git a/src/www/admin/proxy_api.php b/src/www/admin/proxy_api.php index dbf1061..0900ce2 100644 --- a/src/www/admin/proxy_api.php +++ b/src/www/admin/proxy_api.php @@ -7,6 +7,7 @@ $rSignals = array(); if (CoreUtilities::isProxy($_SERVER['REMOTE_ADDR'])) { $db = new Database($_INFO['username'], $_INFO['password'], $_INFO['database'], $_INFO['hostname'], $_INFO['port']); CoreUtilities::$db = &$db; + $rServers = CoreUtilities::$rServers; $rServerID = intval($_POST['server_id']); $rStats = $_POST['stats']; $db->query('SELECT `bytes_sent_total`, `bytes_received_total`, `time` FROM `servers_stats` WHERE `server_id` = ? ORDER BY `id` DESC LIMIT 1;', $rServerID);