diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index 064db48..dd1268a 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -63,8 +63,8 @@ class Container extends CPHPDatabaseRecordClass case "sBandwidthUsed": return $this->GetBandwidthUsed(); break; - case "sStatus": - return (int)$this->GetStatus(); + case "sCurrentStatus": + return (int)$this->GetCurrentStatus(); break; case "sStatusText": return $this->GetStatusText(); @@ -80,7 +80,7 @@ class Container extends CPHPDatabaseRecordClass return ($this->sOutgoingTrafficUsed + $this->IncomingTrafficUsed) / (1024 * 1024); } - public function GetStatus() + public function GetCurrentStatus() { $command = "vzctl status {$this->sInternalId}"; @@ -103,15 +103,8 @@ class Container extends CPHPDatabaseRecordClass public function GetStatusText() { - if(isset($this->sStatus)) - { - $status = $this->sStatus; - } - else - { - $status = $this->GetStatus(); - } - + $status = $this->sCurrentStatus; + if($status == CVM_STATUS_STARTED) { return "running"; diff --git a/frontend/cron.15.php b/frontend/cron.15.php new file mode 100644 index 0000000..195025c --- /dev/null +++ b/frontend/cron.15.php @@ -0,0 +1,14 @@ + diff --git a/frontend/images/errorhandler_error.png b/frontend/images/errorhandler_error.png new file mode 100644 index 0000000..296415e Binary files /dev/null and b/frontend/images/errorhandler_error.png differ diff --git a/frontend/images/errorhandler_info.png b/frontend/images/errorhandler_info.png new file mode 100644 index 0000000..83de654 Binary files /dev/null and b/frontend/images/errorhandler_info.png differ diff --git a/frontend/images/errorhandler_success.png b/frontend/images/errorhandler_success.png new file mode 100644 index 0000000..743ef89 Binary files /dev/null and b/frontend/images/errorhandler_success.png differ diff --git a/frontend/images/errorhandler_warning.png b/frontend/images/errorhandler_warning.png new file mode 100644 index 0000000..1c6b8eb Binary files /dev/null and b/frontend/images/errorhandler_warning.png differ diff --git a/frontend/includes/include.base.php b/frontend/includes/include.base.php index 576bb16..133ed35 100644 --- a/frontend/includes/include.base.php +++ b/frontend/includes/include.base.php @@ -15,6 +15,7 @@ if(!isset($_CVM)) { die("Unauthorized."); } $_CPHP = true; require("cphp/base.php"); +require("include.config.php"); require("include.exceptions.php"); require("include.constants.php"); require("include.parsing.php"); diff --git a/frontend/includes/include.config.php b/frontend/includes/include.config.php new file mode 100644 index 0000000..a991646 --- /dev/null +++ b/frontend/includes/include.config.php @@ -0,0 +1,18 @@ + diff --git a/frontend/js/cvm.js b/frontend/js/cvm.js index be19542..b0758b9 100644 --- a/frontend/js/cvm.js +++ b/frontend/js/cvm.js @@ -10,7 +10,7 @@ $(function(){ return false; }); - $(this).children('.button-icon').addClass('running')[0].src = "images/loading.gif"; + $(this).children('.button-icon').addClass('running')[0].src = "/images/loading.gif"; command_running = true; } }); diff --git a/frontend/module.home.php b/frontend/module.home.php new file mode 100644 index 0000000..a933ade --- /dev/null +++ b/frontend/module.home.php @@ -0,0 +1,17 @@ + diff --git a/frontend/module.vps.overview.php b/frontend/module.vps.overview.php new file mode 100644 index 0000000..832ff48 --- /dev/null +++ b/frontend/module.vps.overview.php @@ -0,0 +1,43 @@ +uParameters[2])) +{ + if($router->uParameters[2] == "start") + { + require("submodule.start.php"); + } + elseif($router->uParameters[2] == "stop") + { + require("submodule.stop.php"); + } + elseif($router->uParameters[2] == "restart") + { + require("submodule.restart.php"); + } +} + +$sPageContents = Templater::InlineRender("vps.overview", $locale->strings, array( + 'id' => $sContainer->sId, + 'server-location' => $sContainer->sNode->sPhysicalLocation, + 'operating-system' => $sContainer->sTemplate->sName, + 'guaranteed-ram' => "{$sContainer->sGuaranteedRam}MB", + 'burstable-ram' => "{$sContainer->sBurstableRam}MB", + 'disk-space' => "{$sContainer->sDiskSpace}MB", + 'total-traffic-limit' => "{$sContainer->sTotalTrafficLimit} bytes", + 'bandwidth-limit' => "100mbit", + 'status' => Templater::InlineRender("status.{$sContainer->sStatusText}", $locale->strings) +)); +?> diff --git a/frontend/module.vps.php b/frontend/module.vps.php new file mode 100644 index 0000000..e0737f1 --- /dev/null +++ b/frontend/module.vps.php @@ -0,0 +1,46 @@ +uParameters[1]); + + $sError = ""; + $sPageContents = ""; + + $router = new CPHPRouter(); + + $router->routes = array( + 0 => array( + '^/([0-9]+)/?$' => "module.vps.overview.php", + '^/([0-9]+)/(start)/?$' => "module.vps.overview.php", + '^/([0-9]+)/(stop)/?$' => "module.vps.overview.php", + '^/([0-9]+)/(restart)/?$' => "module.vps.overview.php" + ) + ); + + $router->RouteRequest(); + + $sMainContents = Templater::InlineRender("main.vps", $locale->strings, array( + 'error' => $sError, + 'contents' => $sPageContents, + 'id' => $sContainer->sId + )); +} +catch(NotFoundException $e) +{ + $sMainContents = Templater::InlineRender("error.vps.notfound"); +} +?> diff --git a/frontend/rewrite.php b/frontend/rewrite.php new file mode 100644 index 0000000..ef84085 --- /dev/null +++ b/frontend/rewrite.php @@ -0,0 +1,45 @@ +routes = array( + 0 => array( + '^/?$' => "module.home.php", + '^/login/?$' => "module.login.php", + '^/logout/?$' => "module.logout.php", + '^/([0-9]+)(/.*)?$' => "module.vps.php" + ) +); + +$mainrouter->RouteRequest(); + +echo(Templater::InlineRender("main", $locale->strings, array( + 'title' => $sPageTitle, + 'main' => $sMainContents +))); + +?> diff --git a/frontend/submodule.restart.php b/frontend/submodule.restart.php new file mode 100644 index 0000000..e6e38b9 --- /dev/null +++ b/frontend/submodule.restart.php @@ -0,0 +1,39 @@ +Stop(); + } + catch(ContainerStopException $e) + { + // we can make this silently fail, as the only important thing is that it starts again + } + + $sContainer->Start(); + $sContainer->sCurrentStatus = CVM_STATUS_STARTED; + + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Container restarted", "Your container was successfully restarted."); + $sError .= $err->Render(); +} +catch(ContainerStartException $e) +{ + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container failed to start", "Your container could not be started. If this error persists, please file a support ticket."); + $sError .= $err->Render(); +} + +?> diff --git a/frontend/submodule.start.php b/frontend/submodule.start.php new file mode 100644 index 0000000..3989b9a --- /dev/null +++ b/frontend/submodule.start.php @@ -0,0 +1,38 @@ +sCurrentStatus != CVM_STATUS_STARTED) +{ + try + { + $sContainer->Start(); + $sContainer->sCurrentStatus = CVM_STATUS_STARTED; + + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Container started", "Your container was successfully started."); + $sError .= $err->Render(); + } + catch(ContainerStartException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container failed to start", "Your container could not be started. If this error persists, please file a support ticket."); + $sError .= $err->Render(); + } +} +else +{ + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container can't be started", "Your container cannot be started because it is already running."); + $sError .= $err->Render(); +} + +?> diff --git a/frontend/submodule.stop.php b/frontend/submodule.stop.php new file mode 100644 index 0000000..c651401 --- /dev/null +++ b/frontend/submodule.stop.php @@ -0,0 +1,38 @@ +sCurrentStatus != CVM_STATUS_STOPPED) +{ + try + { + $sContainer->Stop(); + $sContainer->sCurrentStatus = CVM_STATUS_STOPPED; + + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Container stopped", "Your container was successfully stopped."); + $sError .= $err->Render(); + } + catch(ContainerStartException $e) + { + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container failed to stop", "Your container could not be stopped. If this error persists, please file a support ticket."); + $sError .= $err->Render(); + } +} +else +{ + $err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container can't be stopped", "Your container cannot be stopped because it is not running."); + $sError .= $err->Render(); +} + +?> diff --git a/frontend/templates/error.vps.notfound.tpl b/frontend/templates/error.vps.notfound.tpl new file mode 100644 index 0000000..9bd0a88 --- /dev/null +++ b/frontend/templates/error.vps.notfound.tpl @@ -0,0 +1 @@ +The specified VPS was not found. diff --git a/frontend/templates/errorhandler.error.tpl b/frontend/templates/errorhandler.error.tpl new file mode 100644 index 0000000..1cb4e71 --- /dev/null +++ b/frontend/templates/errorhandler.error.tpl @@ -0,0 +1,4 @@ +
Status | +<%?status> | +
---|---|
Server location | +<%?server-location> | +
Operating system | +<%?operating-system> | +
IPv4 Addresses | +98.142.213.226, 204.12.235.84 | +
IPv6 Addresses | +2607:f7a0:1:1::24:6 | +
Guaranteed RAM | +<%?guaranteed-ram> | +
Burstable RAM | +<%?burstable-ram> | +
Disk space | +<%?disk-space> | +
Traffic | +<%?total-traffic-limit> | +
Bandwidth | +<%?bandwidth-limit> | +