diff --git a/inc/Database.php b/inc/Database.php index 912f48225..82257ccfc 100644 --- a/inc/Database.php +++ b/inc/Database.php @@ -2226,20 +2226,28 @@ public function getGPUID($server) */ public function addServer($serverName, $huPath, $gpuId) { - if (!is_numeric($gpuId)) { + if ($gpuId != "" && !is_numeric($gpuId)) { return "error: invalid GPU ID"; } - /* This allows for multiple entries for the same machine. */ - /* The queue manager only looks at the machine name and rejecting - anything after the blank. */ - $server = "$serverName $gpuId"; - - $query = "INSERT INTO server VALUES " . - "('$server','$huPath','free','NULL','$gpuId')"; - $result = $this->queryLastValue($query); + $tableName = "server"; - return intval($result); + /* This allows for multiple entries for the same machine. */ + /* The queue manager only looks at the machine name, rejecting + anything after the blank. */ + if ($gpuId != "") { + $serverName = "$serverName $gpuId"; + $record['gpuId'] = $gpuId; + } + + $record['name'] = $serverName; + $record['huscript_path'] = $huPath; + $record['status'] = 'free'; + + $insertSQL = $this->connection->GetInsertSQL($tableName, $record); + $status = $this->connection->Execute($insertSQL); + + return $status; } diff --git a/inc/OmeroConnection.php b/inc/OmeroConnection.php index e51028439..8ed087525 100644 --- a/inc/OmeroConnection.php +++ b/inc/OmeroConnection.php @@ -9,6 +9,8 @@ */ namespace hrm; +require_once dirname(__FILE__) . '/bootstrap.php'; + /** * Handles communication to an Omero server. * diff --git a/inc/QueueManager.php b/inc/QueueManager.php index 23ccbed74..efe9ea499 100644 --- a/inc/QueueManager.php +++ b/inc/QueueManager.php @@ -1488,13 +1488,28 @@ private function fillInSuperAdminInfoInTheDatabase() $success = true; $db = new DatabaseConnection(); - $role = UserConstants::ROLE_SUPERADMIN; - $sql = "SELECT email FROM username WHERE name='admin' AND role='$role';"; - $email = $db->queryLastValue($sql); - // If the e-mail is not in the database yet, we store it. - if ($email == "") { - $sqlUp = "UPDATE username SET email='$email_admin' WHERE name='admin' AND role='$role';"; - $success &= $db->execute($sqlUp); + + // This is a corner case: if the QM is started before the + // database update to version 15, the sql query that relies on the + // role to be set will fail and the QM will fail. + // @TODO Remove this at next database revision 16. + if (System::getDBCurrentRevision() < 15) { + $sql = "SELECT email FROM username WHERE name='admin';"; + $email = $db->queryLastValue($sql); + // If the e-mail is not in the database yet, we store it. + if ($email == "") { + $sqlUp = "UPDATE username SET email='$email_admin' WHERE name='admin';"; + $success &= $db->execute($sqlUp); + } + } else { + $role = UserConstants::ROLE_SUPERADMIN; + $sql = "SELECT email FROM username WHERE name='admin' AND role='$role';"; + $email = $db->queryLastValue($sql); + // If the e-mail is not in the database yet, we store it. + if ($email == "") { + $sqlUp = "UPDATE username SET email='$email_admin' WHERE name='admin' AND role='$role';"; + $success &= $db->execute($sqlUp); + } } return $success; } diff --git a/inc/System.php b/inc/System.php index 1791a758a..e340c75df 100644 --- a/inc/System.php +++ b/inc/System.php @@ -41,7 +41,7 @@ class System * developers! * @var int */ - const HRM_VERSION_MAINTENANCE = 0; + const HRM_VERSION_MAINTENANCE = 1; /** * Database revision needed by current HRM version. This value has to be diff --git a/inc/stats/Stats.php b/inc/stats/Stats.php index 682d0c77d..70fc0ad21 100644 --- a/inc/stats/Stats.php +++ b/inc/stats/Stats.php @@ -355,7 +355,7 @@ private function isAdmin() { $user = new UserV2(); $user->setName($this->m_Username); - $user->isAdmin(); + return $user->isAdmin(); } /** diff --git a/inc/user/proxy/DatabaseProxy.php b/inc/user/proxy/DatabaseProxy.php index 1242860c9..9d9b9cbbb 100644 --- a/inc/user/proxy/DatabaseProxy.php +++ b/inc/user/proxy/DatabaseProxy.php @@ -12,6 +12,7 @@ use hrm\DatabaseConnection; use hrm\Log; +use hrm\System; use hrm\user\UserManager; use hrm\user\UserConstants; @@ -83,10 +84,15 @@ public function authenticate($username, $password) { } // Authentication worked. So now we upgrade the password. - $newHashedPassword = password_hash($password, - UserConstants::HASH_ALGORITHM, - array('cost' => UserConstants::HASH_ALGORITHM_COST)); - $this->setPassword($username, $newHashedPassword); + // The database check is for the corner case where the admin + // logs in to upgrade the database from revision 14 to 15! + // @TODO Remove this at next database revision 16. + if (System::getDBCurrentRevision() >= 15) { + $newHashedPassword = password_hash($password, + UserConstants::HASH_ALGORITHM, + array('cost' => UserConstants::HASH_ALGORITHM_COST)); + $this->setPassword($username, $newHashedPassword); + } // Change the status to active $this->setActive($username); @@ -174,6 +180,15 @@ public function getGroup($username) { * @return bool True if the user is outdated, false otherwise. */ public function isOutdated($username) { + + // Workaround for a corner case: when the admin tries to + // log in to upgrade the database between revision 14 + // and 15, his information is OUTDATED, but this cannot + // yet be obtained from UserManager;;getUserStatus method! + // @TODO Remove this in the future. + if (System::getDBCurrentRevision() < 15) { + return true; + } return (UserManager::getUserStatus($username) == UserConstants::STATUS_OUTDATED); } diff --git a/inc/user/proxy/ProxyFactory.php b/inc/user/proxy/ProxyFactory.php index cacd04aec..418376265 100644 --- a/inc/user/proxy/ProxyFactory.php +++ b/inc/user/proxy/ProxyFactory.php @@ -13,6 +13,7 @@ // Include the HRM configuration files. use hrm\DatabaseConnection; use hrm\Log; +use hrm\System; require_once dirname(__FILE__) . '/../../bootstrap.php'; @@ -80,7 +81,17 @@ public static function getAuthenticationModeForUser($username) { $sql = "SELECT authentication FROM username WHERE name=?;"; $result = $db->connection()->Execute($sql, array($username)); if ($result === false) { - return self::getDefaultAuthenticationMode(); + + // This is a corner case: if the admin is logging in before the + // database update to version 15, there will be no authentication + // mode set for him and the default authentication mode could be + // different from integrated. + // @TODO Remove this at next database revision 16. + if (System::getDBCurrentRevision() < 15 && $username == "admin") { + return "integrated"; + } else { + return self::getDefaultAuthenticationMode(); + } } $rows = $result->GetRows(); $authMode = null; diff --git a/resources/checkConfig.php b/resources/checkConfig.php index 24e324397..7c153489f 100644 --- a/resources/checkConfig.php +++ b/resources/checkConfig.php @@ -23,8 +23,8 @@ // END function displayUsage() { - echo PHP_EOL . "Usage: php check.php /path/to/config/file" . PHP_EOL . PHP_EOL . - "Example: php check.php /var/www/html/hrm/config/hrm_server_config.inc" . + echo PHP_EOL . "Usage: php checkConfig.php /path/to/config/file" . PHP_EOL . PHP_EOL . + "Example: php checkConfig.php /var/www/html/hrm/config/hrm_server_config.inc" . PHP_EOL . PHP_EOL; } @@ -34,9 +34,9 @@ function checkConfigFile($configFile) { return; } - echo "Check against HRM v3.4.x." . PHP_EOL; + echo "Checking against HRM v3.4.x." . PHP_EOL; - require_once($configFile); + include($configFile); // Variables that must exist $variables = array( @@ -84,7 +84,6 @@ function checkConfigFile($configFile) { // Check the values of the $authenticateAgainst variable $numVariableToFix = 0; - global $authenticateAgainst; if (!is_array($authenticateAgainst)) { echo "* * * Error: variable 'authenticateAgainst' must be an array!" . PHP_EOL; if ($authenticateAgainst == "MYSQL") { diff --git a/servers.php b/servers.php index 5410839d1..60852c562 100644 --- a/servers.php +++ b/servers.php @@ -27,9 +27,11 @@ if (isset($_GET["add"]["name"]) && !empty($_GET["add"]["name"])) { if (!isset($_GET["add"]["path"]) || empty($_GET["add"]["path"])) { - $message .= "One or more invalid fields: no servers to add.\n"; - } elseif (!isset($_GET["add"]["gpuId"]) || !is_numeric($_GET["add"]["gpuId"])) { - $message .= "One or more invalid fields: no servers to add.\n"; + $message .= "Invalid HuCore path: no servers to add.\n"; + } elseif (isset($_GET["add"]["gpuId"]) + && $_GET["add"]["gpuId"] != "" + && !is_numeric($_GET["add"]["gpuId"])) { + $message .= "Invalid GPU ID: no servers to add.\n"; } else { $serverName = $_GET["add"]["name"]; $huPath = $_GET["add"]["path"];