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 @@ +
+
<%?title>
+
<%?message>
+
diff --git a/frontend/templates/errorhandler.info.tpl b/frontend/templates/errorhandler.info.tpl new file mode 100644 index 0000000..9155c80 --- /dev/null +++ b/frontend/templates/errorhandler.info.tpl @@ -0,0 +1,4 @@ +
+
<%?title>
+
<%?message>
+
diff --git a/frontend/templates/errorhandler.success.tpl b/frontend/templates/errorhandler.success.tpl new file mode 100644 index 0000000..57313b5 --- /dev/null +++ b/frontend/templates/errorhandler.success.tpl @@ -0,0 +1,4 @@ +
+
<%?title>
+
<%?message>
+
diff --git a/frontend/templates/errorhandler.warning.tpl b/frontend/templates/errorhandler.warning.tpl new file mode 100644 index 0000000..b39e8e6 --- /dev/null +++ b/frontend/templates/errorhandler.warning.tpl @@ -0,0 +1,4 @@ +
+
<%?title>
+
<%?message>
+
diff --git a/frontend/templates/main.tpl b/frontend/templates/main.tpl index 2d981e5..36d1e5f 100644 --- a/frontend/templates/main.tpl +++ b/frontend/templates/main.tpl @@ -3,14 +3,14 @@ CVM - + - +
- +
You are logged in as joepie91.
Account overview | My VPSes
diff --git a/frontend/templates/main.vps.tpl b/frontend/templates/main.vps.tpl new file mode 100644 index 0000000..cb48891 --- /dev/null +++ b/frontend/templates/main.vps.tpl @@ -0,0 +1,14 @@ + + +<%?error> + +<%?contents> diff --git a/frontend/templates/status.running.tpl b/frontend/templates/status.running.tpl new file mode 100644 index 0000000..94b952c --- /dev/null +++ b/frontend/templates/status.running.tpl @@ -0,0 +1 @@ +Running diff --git a/frontend/templates/status.stopped.tpl b/frontend/templates/status.stopped.tpl new file mode 100644 index 0000000..0080ca8 --- /dev/null +++ b/frontend/templates/status.stopped.tpl @@ -0,0 +1 @@ +Stopped diff --git a/frontend/templates/status.suspended.tpl b/frontend/templates/status.suspended.tpl new file mode 100644 index 0000000..f686718 --- /dev/null +++ b/frontend/templates/status.suspended.tpl @@ -0,0 +1 @@ +Suspended diff --git a/frontend/templates/status.unknown.tpl b/frontend/templates/status.unknown.tpl new file mode 100644 index 0000000..105cd63 --- /dev/null +++ b/frontend/templates/status.unknown.tpl @@ -0,0 +1 @@ +Unknown diff --git a/frontend/templates/vps.overview.tpl b/frontend/templates/vps.overview.tpl new file mode 100644 index 0000000..e8512cc --- /dev/null +++ b/frontend/templates/vps.overview.tpl @@ -0,0 +1,89 @@ +

Overview

+ + +
+
+

Disk space

+
+
+
55/100GB
+
+
+
+

RAM

+
+
+
241/1024MB
+
+
+
+

Traffic

+
+
+
80/1000GB
+
+
+
+
+ + + +
+

VPS configuration

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Status<%?status>
Server location<%?server-location>
Operating system<%?operating-system>
IPv4 Addresses98.142.213.226, 204.12.235.84
IPv6 Addresses2607:f7a0:1:1::24:6
Guaranteed RAM<%?guaranteed-ram>
Burstable RAM<%?burstable-ram>
Disk space<%?disk-space>
Traffic<%?total-traffic-limit>
Bandwidth<%?bandwidth-limit>
+
diff --git a/sshd/id_rsa.sshd b/sshd/id_rsa.sshd new file mode 100644 index 0000000..108adb0 --- /dev/null +++ b/sshd/id_rsa.sshd @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEpAIBAAKCAQEAzVGn22oP7Na8NYNuLlnqApMPzldYt3TQMGXvb3B1nBjU3Eha +VYKvl2HHQdH7tIAkk9WUXTO4d24Z+YKGdCgNgJIlF6iMswZBqBCHgyhWobeJxAzg +2tQbKyDyPoYpR5TDVOkAwDwL6auIlKgOPsmmde+zIovvUa0xEKEAD3sFykKAqXHW +i1CR/fyvfGiidSgfNoNApvJthP9PIs3w/b21vj8HmZ2hdo6WIF9mZK+snjiWiGqn +xBwhB9mjzfWnngxVLASDw1D9abSEVnX1pGrYSWescLjKp5QfN3xKv69EiDZUkQz0 +dVKOSq15bbhAdntQI2Nu3K7NbkJsT3pE33pPqQIDAQABAoIBAQCfTA4+5xBKAeTu +Y/V1Ut+DddQalJxJYgEwu7XEMW2eWYm1CxHDLGzNt9gf0ipG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4RPFbLiTp5wyEmay60n/+GUA+bZLlUFl7yVsZWOl +i9nW021Q/VsE39kvcIX+HcCWWog5vCB4XMF4czsDMgTkRX+gxtIUjQ== +-----END RSA PRIVATE KEY----- diff --git a/sshd/id_rsa.sshd.pub b/sshd/id_rsa.sshd.pub new file mode 100644 index 0000000..c5e8a52 --- /dev/null +++ b/sshd/id_rsa.sshd.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDNUafbag/s1rw1g24uWeoCkw/OV1i3dNAwZe9vcHWcGNTcSFpVgq+XYcdB0fu0gCST1ZRdM7h3bhn5goZ0KA2AkiUXqIyzBkGoEIeDKFaht4nEDODa1BsrIPI+hilHlMNU6QDAPAvpq4iUqA4+yaZ177Mii+9RrTEQoQAPewXKQoCpcdaLUJH9/K98aKJ1KB82g0Cm8m2E/08izfD9vbW+PweZnaF2jpYgX2Zkr6yeOJaIaqfEHCEH2aPN9aeeDFUsBIPDUP1ptIRWdfWkathJZ6xwuMqnlB83fEq/r0SINlSRDPR1Uo5KrXltuEB2e1AjY27crs1uQmxPekTfek+p occupy@edge13.mydomain.internal diff --git a/sshd/sshd.py b/sshd/sshd.py new file mode 100644 index 0000000..49fa7e4 --- /dev/null +++ b/sshd/sshd.py @@ -0,0 +1,39 @@ +from twisted.cred.portal import Portal +from twisted.conch.ssh.factory import SSHFactory +from twisted.internet import reactor +from twisted.conch.ssh.keys import Key +from twisted.conch.interfaces import IConchUser +from twisted.conch.avatar import ConchUser +from twisted.cred.checkers import AllowAnonymousAccess + +with open('id_rsa.sshd') as privateBlobFile: + privateBlob = privateBlobFile.read() + privateKey = Key.fromString(data=privateBlob) + +with open('id_rsa.sshd.pub') as publicBlobFile: + publicBlob = publicBlobFile.read() + publicKey = Key.fromString(data=publicBlob) + +class StandardRealm(object): + def requestAvatar(self, avatarId, mind, *interfaces): + return IConchUser, ConchUser(), nothing + +class CVMChecker: + implements(ICredentialsChecker) + credentialInterfaces = ICVMUser, + + def requestAvatarId(self, credentials): + return defer.succeed("hai") + +class ICVMUser(ICredentials): + pass + +factory = SSHFactory() +factory.privateKeys = {'ssh-rsa': privateKey} +factory.publicKeys = {'ssh-rsa': publicKey} +factory.portal = Portal(StandardRealm()) + +factory.portal.registerChecker(CVMChecker()) + +reactor.listenTCP(2022, factory) +reactor.run()