/** * --- Update bundles --- * Updates the hosters current amount of bundles the overriding the existing list with * the bundles returned by the nimbusec API */ function updateBundles() { // -- Retrieves crednetials -- $credentials = getCredentials(); $packageExt = new PackageExtensions($credentials['key'], $credentials['secret']); $packageExt->updatePackageExtensions(); }
function __construct($key, $secret, $extensionSettingPath = null, $extensionTemplatePath = null) { $this->api = new NimbusecAPI($key, $secret); if (!empty($extensionSettingPath)) { self::$extensionSettingPath = $extensionSettingPath; } if (!empty($extensionTemplatePath)) { self::$extensionTemplatePath = $extensionTemplatePath; } }
// Define token name $name = "cPanelToken_" . date('Y/m/d-H:i:s'); $token = array("name" => $name); list($serverAgentKey, $serverAgentSecret) = $serverAgent->createAgentToken($token); // Create array for calling whm api $serverAgentArr = array(array("NIMBUSEC_SERVERAGENTKEY", $serverAgentKey), array("NIMBUSEC_SERVERAGENTSECRET", $serverAgentSecret)); // Call method to save credentials in non-volatile datastores (nvdata) $whmApi->setNVData($serverAgentArr); $logger->info("Server agent token created"); // Default param $server $serverAgent->createConfigFile($serverAgentKey, $serverAgentSecret); $logger->info("Server agent config file created"); array_push($responseArray['content'], "Server agent installation finished"); $logger->progress("Server agent installation finished"); // ################################## 2.) Package extensions ################################## $packageExt = new PackageExtensions($apiKey, $apiSecret); $res1 = copy("/usr/local/nimbusec/nimbusec/package_extensions/nimbusec", PackageExtensions::$extensionSettingPath); $res2 = copy("/usr/local/nimbusec/nimbusec/package_extensions/nimbusec.tt2", PackageExtensions::$extensionTemplatePath); if (!$res1 || !$res2) { throw new Exception(__METHOD__ . " - Package extension: Couldn't copy extention files.\nStatus setting: " . json_encode($res1) . "\nStatus template: " . json_encode($res2) . "\n"); } $logger->info("Pacakge extensions copied"); $packageExt->updatePackageExtensions(); $logger->progress("Package extentions installed and updated"); array_push($responseArray['content'], "Package extentions installed and updated"); // ################################## 3.) Cron job ################################## if (file_put_contents("/etc/cron.daily/nimbusec", "#!/bin/bash") === false) { throw new Exception(__METHOD__ . " - file_put_contents: creating cron job failed"); } if (!chmod("/etc/cron.daily/nimbusec", 0755)) { throw new Exception(__METHOD__ . " - chmod: setting permissions failed");