Example #1
0
ini_set('display_startup_errors', 1);
error_reporting(-1);
require '../DataHandlers/Main.php';
require_once '../Data_Building/Entities/ApplicationSupportedEntity.php';
require_once '../Data_Building/Entities/ServersEntity.php';
set_include_path(get_include_path() . PATH_SEPARATOR . '../libs/phpseclib');
include '../libs/phpseclib/Net/SSH2.php';
$Main = new Main();
$name = $_POST['name'];
$value = $_POST['value'];
$jsonDecoded = json_decode($value, true);
switch (strtolower($name)) {
    case "add_application_support":
        if (isset($jsonDecoded['Name']) && isset($jsonDecoded['Install_Commands']) && isset($jsonDecoded['Execute_Commands']) && isset($jsonDecoded['OS'])) {
            $entryData = array("Name" => $jsonDecoded['Name'], "Description" => $jsonDecoded['Description'], "Installation" => json_encode($jsonDecoded['Install_Commands']), "Execution" => json_encode($jsonDecoded['Execute_Commands']), "OS" => json_encode($jsonDecoded['OS']));
            $applicationEntity = new ApplicationSupportedEntity();
            $applicationEntity->exchangeArray($entryData);
            $Main->applicationSupportInfo->addApplicationSupport($applicationEntity);
        }
        break;
    case "deploy_server":
        if (isset($jsonDecoded['Name']) && isset($jsonDecoded['Node']) && isset($jsonDecoded['Application'])) {
            $chosenNode = $Main->nodesInfo->fetchNodeByID($jsonDecoded['Node']);
            $server = $Main->serversInfo->addServer($jsonDecoded['Name'], $chosenNode->getHost(), $chosenNode->getID(), $Main->clientInfo->getClient()->getUserID(), $jsonDecoded['Application']);
            define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
            $applicationEntity = $Main->applicationSupportInfo->fetchApplicationsSupportedByID($jsonDecoded['Application']);
            $ssh = new Net_SSH2($chosenNode->getHost());
            if (!$ssh->login('PanelAgent', $chosenNode->getPassword())) {
                exit('Login Failed');
            }
            /*
 public function fetchApplicationsSupportedByOS($os)
 {
     $dataFetcher = new Data_Fetcher();
     $data = $dataFetcher->fetchData($this->Interface . "/os/" . $os, array());
     $array = array();
     if (isset($data['results'])) {
         $data = $data['results'];
         for ($var = 0; $var < count($data); $var++) {
             $entity = new ApplicationSupportedEntity();
             $entity->exchangeArray($data[$var]);
             array_push($array, $entity);
         }
     } else {
         $array = $data;
     }
     return $array;
 }