* WolfPanel is licensed under a
 * Creative Commons Attribution-NonCommercial 4.0 International License.
 * 
 * You should have received a copy of the license along with this
 * work. If not, see <http://creativecommons.org/licenses/by-nc/4.0/>. 
 */
include "../core.php";
// Admin Check
$user = UserManager::getLocalUser();
if (!$user->isAdmin()) {
    PageManager::displayErrorPage("access");
    return;
}
$id = isset($_GET["serverid"]) && is_numeric($_GET["serverid"]) ? $_GET["serverid"] : -1;
$port = isset($_GET["port"]) && is_numeric($_GET["port"]) ? $_GET["port"] : -1;
if (!PhysicalServerManager::existsById($id)) {
    Page::renderJson(array("status" => "error", "message" => "Server doesnt exist"));
    return;
}
if ($port < Core::getConfig("port_min") || $port > Core::getConfig("port_max")) {
    Page::renderJson(array("status" => "error", "message" => "Invalid Port"));
    return;
}
$server = new PhysicalServer($id);
if ($server->isPortFree($port)) {
    Page::renderJson(array("status" => "success", "message" => "Port is available"));
    return;
} else {
    Page::renderJson(array("status" => "error", "message" => "Port is not available"));
    return;
}
Beispiel #2
0
                    if ($do == "UpdateServer") {
                        $errors = array();
                        $sid = isset($_POST['serverid']) ? $_POST['serverid'] : "";
                        if (empty($sid)) {
                            $errors[] = "Es wurde keine Server-ID angegeben.";
                        } else {
                            if (!is_numeric($sid)) {
                                $errors[] = "Es wurde eine ungültige Server-ID angegeben.";
                            } else {
                                if (!PhysicalServerManager::existsById($sid)) {
                                    $errors[] = "Die angegebene Server-ID existiert nicht.";
                                }
                            }
                        }
                        if (count($errors) == 0) {
                            $server = new PhysicalServer($sid);
                            $page->assign("t_Report", Reporting::success("Der Server \"" . $server->getData("name") . "\" wird demnächst aktualisiert. (Task geplant)"));
                            $server->addTask(TASK_SERVER_UPDATE);
                            //header("Location: " . Core::GetConfig("dirRoot") . "Server");
                        } else {
                            $page->assign("t_Report", Reporting::error(Utils::buildErrorString($errors)));
                        }
                    }
                }
            }
        }
    }
}
$sc = PhysicalServerManager::getCount();
$smarty->assign("servercount", $sc);
$smarty->assign("physicalServerStates", $physicalServerStates);
Beispiel #3
0
         $page->assign("t_Report", Reporting::error("No Template ID given..."));
     }
 } else {
     if ("InstallTemplateOnServer" == $do) {
         $errors = array();
         $sid = isset($_POST['servertargetid']) ? $_POST['servertargetid'] : "";
         if (empty($sid)) {
             $errors[] = "No server id set..";
         } else {
             if (!is_numeric($sid)) {
                 $errors[] = "The given server id was invalid.";
             } else {
                 if (!PhysicalServerManager::existsById($sid)) {
                     $errors[] = "The given server id doesn't exist.";
                 } else {
                     $server = new PhysicalServer($sid);
                 }
             }
         }
         if (isset($server) && $server->getData("status") == 0) {
             $error[] = "The server wasnt initialized yet.";
         }
         $templateid = isset($_POST['templateID']) ? $_POST['templateID'] : "";
         if (empty($templateid)) {
             $errors[] = "No template id set.";
         } else {
             if (!is_numeric($sid)) {
                 $errors[] = "The given template id was invalid.";
             } else {
                 if (!TemplateManager::existsById($templateid)) {
                     $errors[] = "The given template id doesn't exist.";
 $error = array();
 $template = null;
 $userName = "";
 $user = null;
 $server = null;
 $serverPort = 0;
 $serverIP = 0;
 // Server ID
 $err = @Utils::checkInput($_POST['servertargetid'], "Server ID", 1, 64, INPUT_TYPE_NUMERIC);
 if (strlen($err) != 0) {
     $error[] = $err;
 } else {
     if (!PhysicalServerManager::existsById($_POST['servertargetid'])) {
         $error[] = "The given Server doesnt exist.";
     } else {
         $server = new PhysicalServer($_POST['servertargetid']);
         $serverName = $server->getData("name");
         $serverIP = $server->getData("ip");
     }
 }
 // Port
 $err = @Utils::checkInput($_POST['port'], "Port", 1, 64, INPUT_TYPE_NUMERIC);
 if (strlen($err) != 0) {
     if (strlen($_POST['port']) == 0) {
         $serverPort = $server->getRandomFreePort();
         if ($serverPort === false) {
             $error[] = "The given Server doesnt have any free port.";
         }
     } else {
         $error[] = $err;
     }
Beispiel #5
0
 public function execute()
 {
     $done = true;
     if (!$this->_validate()) {
         return $this->delete();
     }
     try {
         switch ($this->getData("type")) {
             case TASK_SERVER_INIT:
                 $err = $this->server->initializeForUse();
                 if (strlen($err) == 0) {
                     Core::addToTaskLog("Server " . $this->getData("serverID") . " has been initialized.");
                 } else {
                     Core::addToTaskLog("Server " . $this->getData("serverID") . " could not be initialized. Reason: {$err}.");
                 }
                 break;
             case TASK_SERVER_UPDATE:
                 $server = new PhysicalServer($this->getData('serverID'));
                 $server->updateServer();
                 Core::addToTaskLog("Server " . $this->getData("serverID") . " has been updated");
                 break;
             case TASK_SERVER_INSTALL_TEMPLATE:
                 if (!PhysicalServerManager::existsById($this->getData("serverID"))) {
                     $this->delete();
                 }
                 if (!TemplateManager::existsById($this->getData("addInfo"))) {
                     $this->delete();
                 }
                 $server = new PhysicalServer($this->getData("serverID"));
                 $template = new Template($this->getData("addInfo"));
                 $template->installOnServer($server);
                 Core::addToTaskLog("Template (" . $template->getData("id") . ", " . $template->getData("gameName") . ") installed on server " . $server->getData("id") . " (" . $server->getData("name") . ")");
                 break;
             case TASK_TEMPLATES_INSTALL_FROM_REMOTE:
                 $template = TemplateManager::loadTemplateByRemote($this->getData("addInfo"));
                 Core::addToTaskLog("Gameserver templated downloaded. (" . $template->getData("gameName") . ")");
                 break;
             case TASK_GAMESERVER_UPDATESETTINGS:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     echo "Updating Config.";
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->settingsUpdateOnServer();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver settings saved. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_INSTALL:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->install();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver installed. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_UNINSTALL:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $done = $gameserver->delete();
                     $id = $gameserver->getData("id");
                     if ($done) {
                         Core::addToTaskLog("Gameserver deleted. (ID: {$id})");
                     }
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_START:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->start();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver started. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_STOP:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->stop();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver stopped. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             case TASK_GAMESERVER_DISABLE:
                 if (GameserverManager::existsById($this->getData("addInfo"))) {
                     $gameserver = new Gameserver($this->getData("addInfo"));
                     $gameserver->disable();
                     $id = $gameserver->getData("id");
                     Core::addToTaskLog("Gameserver disabled. (ID: {$id})");
                 } else {
                     $id = $this->getData("addInfo");
                     Core::addToTaskLog("Gameserver Install Task couldnt be executed. Gameserver doesnt exist (ID: {$id})", LOGLEVEL_WARNING);
                 }
                 break;
             default:
                 $id = $this->getData("id");
                 Core::addToTaskLog("Task couldnt be executed. Unknown Job. (ID: {$id})", LOGLEVEL_WARNING);
                 $this->delete();
                 return;
         }
         if ($done) {
             $con = Database::getCon();
             $con->query("UPDATE tasks SET done = 1 WHERE id = " . $this->getData("id"));
         }
     } catch (Exception $e) {
         echo "Task couldnt be executed. (ID: " . $this->getData("id") . ") Message: " . $e->getMessage();
         Core::addToTaskLog("Task couldnt be executed. (ID: " . $this->getData("id") . ") Message: " . $e->getMessage(), LOGLEVEL_ERROR);
     }
 }