コード例 #1
0
ファイル: updateSetting.php プロジェクト: GzPanel/GzPanel
switch (strtolower($name)) {
    case "check_db":
        if (isset($jsonDecoded['Username']) && isset($jsonDecoded['Password']) && isset($jsonDecoded['Host']) && isset($jsonDecoded['Port']) && isset($jsonDecoded['Database_Name'])) {
            $dbConnection = new DbConnection($jsonDecoded['Username'], $jsonDecoded['Password'], $jsonDecoded['Database_Name'], $jsonDecoded['Host'], $jsonDecoded['Port']);
            if ($dbConnection->DbConnection != null) {
                echo true;
            } else {
                echo 0;
            }
        } else {
            echo 0;
        }
        break;
    case "set_dbinfo":
        if (isset($jsonDecoded['Username']) && isset($jsonDecoded['Password']) && isset($jsonDecoded['Host']) && isset($jsonDecoded['Port']) && isset($jsonDecoded['Database_Name'])) {
            $dbConnection = new DbConnection($jsonDecoded['Username'], $jsonDecoded['Password'], $jsonDecoded['Database_Name'], $jsonDecoded['Host'], $jsonDecoded['Port']);
            if ($dbConnection->DbConnection != null) {
                // Save DB info and build Db.
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Login_Attempts`(\n                    `Attempt_ID` INT( 11 ) AUTO_INCREMENT,\n                     `IP_Address` VARCHAR ( 100 ) NOT NULL,\n                     `Attempt_Date` DATETIME NOT NULL,\n                     PRIMARY KEY (`Attempt_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Configuration`(\n                    `ID` INT( 11 ) AUTO_INCREMENT,\n                     `Name` VARCHAR( 100 ) NOT NULL,\n                     `Value` VARCHAR( 2048 ) NOT NULL,\n                     PRIMARY KEY (`ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Accounts`(\n                    `User_ID` INT( 11 ) AUTO_INCREMENT,\n                     `Username` VARCHAR( 100 ) NOT NULL,\n                     `Email_Address` VARCHAR( 100 ) NOT NULL,\n                     `Password` VARCHAR( 60 ) NOT NULL,\n                     PRIMARY KEY (`User_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Accounts_Data`(\n                    `User_ID` INT( 11 ) AUTO_INCREMENT,\n                     `Creation_Date` DATETIME NOT NULL,\n                     `Last_Login_Date` DATETIME NOT NULL,\n                     PRIMARY KEY (`User_ID`))", array());
                // This session table will be cleared regulary to avoid overload - It keeps records of all sessions.
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Sessions_Data`(\n                    `Session_ID` INT( 11 ) AUTO_INCREMENT,\n                     `User_ID` INT ( 11 ) NOT NULL,\n                     `Session_Start` DATETIME NOT NULL,\n                     `Session_Key` VARCHAR( 60 ) NOT NULL,\n                     `Session_IP` VARCHAR( 45 ) NOT NULL,\n                     PRIMARY KEY (`Session_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Support_Tickets`(\n                    `Ticket_ID` INT( 11 ) AUTO_INCREMENT,\n                     `Ticket_Author` INT ( 11 ) NOT NULL,\n                     `Ticket_Creation` DATETIME NOT NULL,\n                     `Ticket_Title` VARCHAR( 200 ) NULL,\n                     `Ticket_Content` VARCHAR( 10000 ) NOT NULL,\n                     `Ticket_Priority` VARCHAR( 1 ) NULL,\n                     `Ticket_Parent` INT( 11 ) NULL,\n                     PRIMARY KEY (`Ticket_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Servers`(\n                    `ID` INT( 11 ) AUTO_INCREMENT,\n                     `Owner` INT ( 11 ) NOT NULL,\n                     `Creation` DATETIME NOT NULL,\n                     `Name` VARCHAR( 200 ) NOT NULL,\n                     `Host` VARCHAR( 100 ) NOT NULL,\n                     `App_ID` INT( 11 ) NOT NULL,\n                     `Node` INT( 11 ) NOT NULL,\n                     PRIMARY KEY (`ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Servers_Status`(\n                    `Ping_ID` INT( 11 ) AUTO_INCREMENT,\n                    `Server_ID` INT( 11 ) NOT NULL,\n                     `Time_Pinged` DATETIME NOT NULL,\n                     `Data` VARCHAR (1000) NULL,\n                     PRIMARY KEY (`Ping_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Nodes`(\n                    `Node` INT( 11 ) AUTO_INCREMENT,\n                     `Name` VARCHAR ( 100 ) NOT NULL,\n                     `Creation` DATETIME NOT NULL,\n                     `Host` VARCHAR( 200 ) NOT NULL,\n                     `Port` VARCHAR( 5 ) NOT NULL,\n                     `Password` VARCHAR( 100 ) NOT NULL,\n                     `Directory` VARCHAR( 100 ) NOT NULL,\n                     `OS` VARCHAR( 50 ) NOT NULL,\n                     `Active` VARCHAR( 1 ) NOT NULL,\n                     `Online` VARCHAR( 1 ) NOT NULL,\n                     PRIMARY KEY (`Node`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Nodes_Status`(\n                    `Ping_ID` INT( 11 ) AUTO_INCREMENT,\n                    `Node` INT( 11 ) NOT NULL,\n                     `Time_Pinged` DATETIME NOT NULL,\n                     `Ping` VARCHAR (4) NOT NULL,\n                     `Load_AVG` VARCHAR( 10 ) NOT NULL,\n                     `HDD_Space` VARCHAR( 150 ) NOT NULL,\n                     `RAM` VARCHAR( 100 ) NOT NULL,\n                     PRIMARY KEY (`Ping_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Special_Tokens`(\n                    `Token_ID` INT( 11 ) AUTO_INCREMENT,\n                     `Generated` VARCHAR ( 100 ) NOT NULL,\n                     `Creation` DATETIME NOT NULL,\n                     `Type` VARCHAR ( 20 ) NOT NULL,\n                     `Linked` INT ( 11 ) DEFAULT NULL,\n                     PRIMARY KEY (`Token_ID`))", array());
                $dbConnection->query("CREATE TABLE IF NOT EXISTS `Supported_Servers` (\n                    `App_ID` INT( 11 ) AUTO_INCREMENT,\n                    `Name` VARCHAR(128),\n                    `Description` VARCHAR(512),\n                    `Installation` VARCHAR(2048),\n                    `Execution` VARCHAR(2048),\n                    `OS` VARCHAR(50),\n                    PRIMARY KEY (`App_ID`))", array());
コード例 #2
0
ファイル: index.php プロジェクト: GzPanel/GzPanel
$app = new \Slim\Slim();
$app->view(new JsonApiView());
$app->add(new JsonApiMiddleware());
// Set-up the database info, if it fails then do NOT set-up the api.
$dbConnection = null;
if (!file_exists("../Configuration/internal_data.json")) {
    $failMessage = 'Failed to connect to database. Verify your database information in the configuration.';
} else {
    $string = file_get_contents("../Configuration/internal_data.json");
    $jsonConf = json_decode($string, true);
    $database = $jsonConf;
    //Needs fixes.
    if (!isset($database['name']) || !isset($database['host']) || !isset($database['port']) || !isset($database['username']) || !isset($database['password'])) {
        $failMessage = 'Failed to connect to database. Verify your database information in the configuration.';
    }
    $dbConnection = new DbConnection($database['username'], $database['password'], $database['name'], $database['host'], $database['port']);
    if ($dbConnection->DbConnection == null) {
        $failMessage = 'Failed to connect to database. Verify your database information in the configuration.';
    }
    $rows = $dbConnection->query("SELECT COUNT(*) AS totalTables FROM information_schema.tables WHERE table_schema = '" . $database['name'] . "' and TABLE_TYPE='BASE TABLE'")[0]['totalTables'];
    if ($rows == 0) {
        $failMessage = 'Databases are not set-up. Please re-initiate installation.';
        $dbConnection = null;
    }
}
if ($dbConnection != null) {
    // Version group
    $app->group('/v1', function () use($app, $dbConnection) {
        // Check API key
        $keyValidate = new KeyValidation($dbConnection);
        $app->group('/nodes', function () use($app, $keyValidate, $dbConnection) {