Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
aarpon committed Mar 13, 2017
2 parents 47a4ecd + 4972628 commit 4d0aedb
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 32 deletions.
28 changes: 18 additions & 10 deletions inc/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
2 changes: 2 additions & 0 deletions inc/OmeroConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/
namespace hrm;

require_once dirname(__FILE__) . '/bootstrap.php';

/**
* Handles communication to an Omero server.
*
Expand Down
29 changes: 22 additions & 7 deletions inc/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion inc/stats/Stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ private function isAdmin()
{
$user = new UserV2();
$user->setName($this->m_Username);
$user->isAdmin();
return $user->isAdmin();
}

/**
Expand Down
23 changes: 19 additions & 4 deletions inc/user/proxy/DatabaseProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use hrm\DatabaseConnection;
use hrm\Log;
use hrm\System;
use hrm\user\UserManager;
use hrm\user\UserConstants;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand Down
13 changes: 12 additions & 1 deletion inc/user/proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// Include the HRM configuration files.
use hrm\DatabaseConnection;
use hrm\Log;
use hrm\System;

require_once dirname(__FILE__) . '/../../bootstrap.php';

Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions resources/checkConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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(
Expand Down Expand Up @@ -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") {
Expand Down
8 changes: 5 additions & 3 deletions servers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down

0 comments on commit 4d0aedb

Please sign in to comment.