diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index cfc368a..8caac08 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -629,8 +629,10 @@ class Container extends CPHPDatabaseRecordClass public function SetRootPassword($password) { + $sPassword = escapeshellarg($password); + $this->SetOptions(array( - 'userpasswd' => "root:{$password}" + 'userpasswd' => "root:{$sPassword}" )); } diff --git a/frontend/locales/english.lng b/frontend/locales/english.lng index b557f17..0f78722 100644 --- a/frontend/locales/english.lng +++ b/frontend/locales/english.lng @@ -26,9 +26,11 @@ event-years-ago; %1$d years ago title-overview; Overview title-login; Login to your VPS panel title-reinstall; Reinstall your VPS +title-password; Set new root password button-login; Login button-reinstall; Reinstall +button-password; Set new root password notfound; The specified VPS was not found. footer; CPHP is a free and open source VPS control panel. Want to contribute? @@ -46,7 +48,7 @@ menu-console; Console menu-ip; IP Allocation menu-alerts; Alerts menu-api; API -menu-password; Password +menu-password; Root Password login-username; Username login-password; Password @@ -86,3 +88,6 @@ list-status-suspended; Suspended reinstall-warning; I understand that by reinstalling my VPS, all data on the VPS is permanently lost and cannot be recovered. There will be no further confirmations, after clicking the Reinstall button the reinstallation process cannot be aborted. reinstall-patience; (be patient; this may take a while) + +password-field-password; New root password +password-field-confirm; Confirm password diff --git a/frontend/module.vps.password.php b/frontend/module.vps.password.php new file mode 100644 index 0000000..0a03c4e --- /dev/null +++ b/frontend/module.vps.password.php @@ -0,0 +1,69 @@ +SetRootPassword($_POST['password']); + + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Password configuration succeeded!", "Your new root password was successfully configured. Please ensure to change your root password again from your container after logging in."); + $sPageContents .= $err->Render(); + } + else + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Passwords do not match", "Both entries should be identical. Please try again."); + $sPageContents .= $err->Render(); + } + } + else + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Fields missing", "Both fields are required. Please try again."); + $sPageContents .= $err->Render(); + } + } + catch (ContainerSuspendedException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Failed to configure root password", "You can not configure the root password for this VPS, because it is suspended. If you believe this is in error, please contact support."); + $sPageContents .= $err->Render(); + } + catch (ContainerTerminatedException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Failed to configure root password", "You can not configure the root password for this VPS, because it is suspended. If you believe this is in error, please contact support."); + $sPageContents .= $err->Render(); + } + catch (SshExitException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Failed to configure root password", "Your password may be in an invalid format. Try again with a different password."); + $sPageContents .= $err->Render(); + } +} + +if($display_form === true) +{ + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_WARNING, "Security warning", "Configuring your root password through this panel may expose it to the VPS provider. Only use this feature in an emergency situation, and always change your password again afterwards, from within your container."); + $sPageContents .= $err->Render(); + + $sPageContents .= Templater::InlineRender("vps.password", $locale->strings, array( + 'id' => $sContainer->sId + )); +} +?> diff --git a/frontend/module.vps.php b/frontend/module.vps.php index 2d9f7b9..c9dc1c0 100644 --- a/frontend/module.vps.php +++ b/frontend/module.vps.php @@ -37,7 +37,8 @@ try '^/([0-9]+)/(start)/?$' => "module.vps.overview.php", '^/([0-9]+)/(stop)/?$' => "module.vps.overview.php", '^/([0-9]+)/(restart)/?$' => "module.vps.overview.php", - '^/([0-9]+)/reinstall/?$' => "module.vps.reinstall.php" + '^/([0-9]+)/reinstall/?$' => "module.vps.reinstall.php", + '^/([0-9]+)/password/?$' => "module.vps.password.php" ) ); diff --git a/frontend/templates/vps.password.tpl b/frontend/templates/vps.password.tpl new file mode 100644 index 0000000..7f2b672 --- /dev/null +++ b/frontend/templates/vps.password.tpl @@ -0,0 +1,14 @@ +