From 8b95e131bfd921244e655e940ed86f35af0dfd0d Mon Sep 17 00:00:00 2001 From: Stephen J Carnam Date: Fri, 15 Sep 2023 13:10:39 -0700 Subject: [PATCH] update --- conf-web/nginx.conf | 2 +- conf-web/nginx.ssl.conf | 2 +- vscode.php | 188 +--------------------------------------- 3 files changed, 5 insertions(+), 187 deletions(-) diff --git a/conf-web/nginx.conf b/conf-web/nginx.conf index 957fbbe..c068bb4 100644 --- a/conf-web/nginx.conf +++ b/conf-web/nginx.conf @@ -12,7 +12,7 @@ server { location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; - proxy_pass http://127.0.0.1:%port%; + proxy_pass http://localhost:%port%; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; diff --git a/conf-web/nginx.ssl.conf b/conf-web/nginx.ssl.conf index 6ecfcbb..aa4a576 100644 --- a/conf-web/nginx.ssl.conf +++ b/conf-web/nginx.ssl.conf @@ -22,7 +22,7 @@ server { location / { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; - proxy_pass http://127.0.0.1:%port%; + proxy_pass http://localhost:%port%; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; diff --git a/vscode.php b/vscode.php index 335bf52..9179054 100644 --- a/vscode.php +++ b/vscode.php @@ -229,9 +229,9 @@ public function setup( $user ) { // Generate website cert if it doesn't exist for Personal Web Server edition. if ( property_exists( $hcpp, 'cg_pws' ) ) { - if ( !is_dir( "/home/$user/conf/web/vscode-$user.$domain/ssl" ) ) { - $hcpp->cg_pws->generate_website_cert( $user, ["vscode-$user.$domain"] ); - } + + // Always regenerate the cert to ensure it's up to date. + $hcpp->cg_pws->generate_website_cert( $user, ["vscode-$user.$domain"] ); }else{ // Force SSL on non-Personal Web Server edition. @@ -382,185 +382,3 @@ public function render_list_web( $args ) { } new VSCode(); } - -// if ( ! class_exists( 'VSCode') ) { -// class VSCode { -// /** -// * Constructor, register our actions. -// */ -// public function __construct() { -// global $hcpp; -// $hcpp->vscode = $this; -// $hcpp->add_action( 'priv_unsuspend_domain', [ $this, 'priv_unsuspend_domain' ] ); -// $hcpp->add_action( 'hcpp_new_domain_ready', [ $this, 'hcpp_new_domain_ready' ] ); -// $hcpp->add_action( 'priv_delete_user', [ $this, 'priv_delete_user' ] ); -// $hcpp->add_action( 'hcpp_invoke_plugin', [ $this, 'hcpp_invoke_plugin' ] ); -// $hcpp->add_action( 'hcpp_render_body', [ $this, 'hcpp_render_body' ] ); -// } - -// // Trigger setup and configuration when domain is created. -// public function hcpp_new_domain_ready( $args ) { -// global $hcpp; -// $user = $args[0]; -// $domain = $args[1]; -// $this->setup( $user ); -// $this->configure( $user, $domain ); -// return $args; -// } - -// // On domain unsuspend, re-run setup and configuration. -// public function priv_unsuspend_domain( $args ) { -// global $hcpp; -// $user = $args[0]; -// $domain = $args[1]; -// $this->setup( $user ); -// $this->configure( $user, $domain ); -// return $args; -// } - -// // Return requests for the VSCode Server token for the given user. -// public function hcpp_invoke_plugin( $args ) { -// if ( $args[0] !== 'vscode_get_token' ) return $args; -// $user = $args[1]; -// echo file_get_contents( "/home/$user/.openvscode-server/data/token" ); -// return $args; -// } - -// // Setup the VSCode Server instance for the user. -// public function setup( $user ) { -// global $hcpp; -// $hostname = $hcpp->delLeftMost( $hcpp->getLeftMost( $_SERVER['HTTP_HOST'], ':' ), '.' ); - -// // Create the configuration folder -// if ( ! is_dir( "/home/$user/conf/web/vscode-$user.$hostname" ) ) { -// mkdir( "/home/$user/conf/web/vscode-$user.$hostname" ); - -// // Run pm2 first time -// $cmd = "runuser -s /bin/bash -l $user -c \"cd /home/$user && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ; pm2 status\""; -// $hcpp->log( $cmd ); -// $hcpp->log( shell_exec( $cmd ) ); -// } - -// // Get user account first IP address. -// $ip = array_key_first( -// json_decode( shell_exec( '/usr/local/hestia/bin/v-list-user-ips ' . $user . ' json' ), true ) -// ); - -// // Create the nginx.conf file. -// $conf = "/home/$user/conf/web/vscode-$user.$hostname/nginx.conf"; -// $content = file_get_contents( __DIR__ . '/conf-web/nginx.conf' ); -// $content = str_replace( -// ['%ip%', '%user%', '%hostname%'], -// [$ip, $user, $hostname], -// $content -// ); -// file_put_contents( $conf, $content ); - -// // Create the nginx.conf_nodeapp file. -// $conf = "/home/$user/conf/web/vscode-$user.$hostname/nginx.conf_nodeapp"; -// $content = file_get_contents( __DIR__ . '/conf-web/nginx.conf_nodeapp' ); -// file_put_contents( $conf, $content ); - -// // Allocate a port for the VSCode Server instance. -// $hcpp->allocate_port( "vscode_port", $user, "vscode-$user.$hostname" ); - -// // Create the nginx.forcessl.conf_ports file. -// $conf = "/home/$user/conf/web/vscode-$user.$hostname/nginx.forcessl.conf_ports"; -// $content = file_get_contents( __DIR__ . '/conf-web/nginx.forcessl.conf_ports' ); -// $content = str_replace( -// ['%user%', '%hostname%'], -// [$user, $hostname], -// $content -// ); -// file_put_contents( $conf, $content ); - -// // Create the NGINX configuration symbolic link. -// $link = "/etc/nginx/conf.d/domains/vscode-$user.$hostname.conf"; -// if ( ! is_link( $link ) ) { -// symlink( "/home/$user/conf/web/vscode-$user.$hostname/nginx.conf", $link ); -// } - -// // Start the VSCode Server instance -// $cmd = "runuser -s /bin/bash -l $user -c \"cd /opt/vscode && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ; pm2 pid vscode-$user.$hostname\""; -// if ( trim( shell_exec( $cmd ) ) === '' ) { -// $cmd = "runuser -s /bin/bash -l $user -c \"cd /opt/vscode && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ; pm2 start vscode.config.js\""; -// $hcpp->log( shell_exec( $cmd ) ); -// // }else{ -// // $this->update_token( $user ); -// } -// } - -// // Update the VSCode Server access token; this invokes watch's restart. -// public function update_token( $user ) { -// global $hcpp; -// $token = $hcpp->nodeapp->random_chars( 32 ); -// $cmd = "echo \"$token\" > \/home\/$user\/.openvscode-server\/data\/token && "; -// $cmd .= "chown $user:$user \/home\/$user\/.openvscode-server\/data\/token && "; -// $cmd .= "chmod 600 \/home\/$user\/.openvscode-server\/data\/token"; -// shell_exec( $cmd ); -// } - -// // Delete the NGINX configuration reference and server when the user is deleted. -// public function priv_delete_user( $args ) { -// global $hcpp; -// $user = $args[0]; -// $hostname = trim( $hcpp->delLeftMost( shell_exec( 'hostname -f' ), '.' ) ); -// $link = "/etc/nginx/conf.d/domains/vscode-$user.$hostname.conf"; -// if ( is_link( $link ) ) { -// unlink( $link ); -// } - -// // Delete the VSCode Server instance -// $cmd = "runuser -s /bin/bash -l $user -c \"cd \/opt\/vscode && export NVM_DIR=/opt/nvm && source /opt/nvm/nvm.sh ;pm2 delete vscode-$user.$hostname;pm2 save --force\""; -// shell_exec( $cmd ); -// return $args; -// } - -// // Configure VSCode for the given domain. -// public function configure( $user, $domain ) { - -// // TODO: write .vscode/settings.json and .vscode/launch.json -// // -// // { -// // // Use IntelliSense to learn about possible attributes. -// // // Hover to view descriptions of existing attributes. -// // // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 -// // "version": "0.2.0", -// // "configurations": [ -// // { -// // "name": "Listen for Xdebug", -// // "type": "php", -// // "request": "launch", -// // "hostname": "127.0.0.1", -// // "port": 12003, -// // "pathMappings": { -// // "/home/farmer/web/test3.openmy.info/public_html/": "${workspaceFolder}/" -// // } -// // } -// // ] -// // } - -// // { -// // // Use IntelliSense to learn about possible attributes. -// // // Hover to view descriptions of existing attributes. -// // // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 -// // "version": "0.2.0", -// // "configurations": [ -// // { -// // "type": "node", -// // "request": "attach", -// // "name": "Debug NodeJS", -// // "port": 53001 -// // } -// // ] -// // } - - - - -// } - - -// } -// new VSCode(); -// }