diff --git a/application/models/Users.php b/application/models/Users.php index 8a2574505..05b057ba2 100644 --- a/application/models/Users.php +++ b/application/models/Users.php @@ -171,5 +171,14 @@ class User { return $CC_DBC->GetRow($sql); } + + public static function GetUserID($login){ + $user = CcSubjsQuery::create()->findOneByDbLogin($login); + if (is_null($user)){ + return -1; + } else { + return $user->getDbId(); + } + } } diff --git a/install/airtime-user.php b/install/airtime-user.php index 6c4b0c0f0..3ccb17462 100644 --- a/install/airtime-user.php +++ b/install/airtime-user.php @@ -1,7 +1,12 @@ #!/usr/bin/php \n"; - echo " Add the user or update the password for the user.\n"; + echo " --addupdate \n"; + echo " Add the user or update user information.\n"; echo " --delete \n"; echo " Remove the user.\n"; echo "\n"; } -$parsedCommandLine = Console_Getopt::getopt($argv, null, array("addupdate", "delete")); -if (PEAR::isError($parsedCommandLine)) { - printUsage(); - exit(1); -} -$cmdLineOptions = $parsedCommandLine[0]; -if (count($parsedCommandLine[1]) == 0) { +if (count($argv) != 3) { printUsage(); exit; } + $action = null; -foreach ($cmdLineOptions as $tmpValue) { - $optionName = $tmpValue[0]; - $optionValue = $tmpValue[1]; - switch ($optionName) { - case '--addupdate': - $action = "addupdate"; - break 2; - case "--delete": - $action = "delete"; - break 2; - } +switch ($argv[1]) { + case '--addupdate': + $action = "addupdate"; + break; + case '--delete': + $action = "delete"; + break; } +$username = $argv[2]; + if (is_null($action)) { printUsage(); exit; } -if (count($parsedCommandLine) < 1) { - printUsage(); - exit; -} - -$username = $parsedCommandLine[1][0]; -$password = $parsedCommandLine[1][1]; - PEAR::setErrorHandling(PEAR_ERROR_RETURN); $CC_DBC = DB::connect($CC_CONFIG['dsn'], TRUE); if (PEAR::isError($CC_DBC)) { @@ -75,28 +65,51 @@ if (PEAR::isError($CC_DBC)) { } $CC_DBC->setFetchMode(DB_FETCHMODE_ASSOC); + // Check if the user exists -$user = Subjects::GetSubject($username); +$id = User::GetUserID($username); if ($action == "addupdate") { - if (empty($password)) { - printUsage(); - exit; - } - if (empty($user)) { - // Add the user. - $r = Subjects::AddSubj($username, $password); + + if ($id < 0) { + echo "Creating user\n"; + $user = new User(""); + $user->setLogin($username); } else { - // Update the password - $r = Subjects::Passwd($username, NULL, $password); - } -} elseif (($action == "delete") && (is_array($user))) { - // Delete the user - $r = Subjects::RemoveSubj($username); -} + echo "Updating user\n"; + $user = new User($id); + } -if (PEAR::isError($r)) { - die($r->getMessage()); + echo "Enter password: "; + $line = trim(fgets(fopen("php://stdin","r"))); + $user->setPassword($line); + + do{ + echo "Enter first name: "; + $line = trim(fgets(fopen("php://stdin","r"))); + }while(strlen($line) < 1); + $user->setFirstName($line); + + do{ + echo "Enter last name: "; + $line = trim(fgets(fopen("php://stdin","r"))); + }while(strlen($line) < 1); + $user->setLastName($line); + + do{ + echo "Enter user type [(A)dmin|(H)ost|(G)uest]: "; + $line = trim(fgets(fopen("php://stdin","r"))); + } while($line != "A" && $line != "H" && $line != "G"); + $user->setType($line); + $user->save(); + +} elseif ($action == "delete") { + if ($id < 0){ + echo "Username not found!\n"; + exit; + } else { + echo "Deleting user\n"; + $user = new User($id); + $user->delete(); + } } -exit(0); -