CC-3178 : airtime-user command switches
This commit is contained in:
parent
9bbe1d14fa
commit
7234b7f772
1 changed files with 90 additions and 70 deletions
|
@ -23,54 +23,35 @@ if (isset($arr["DOCUMENT_ROOT"]) && ($arr["DOCUMENT_ROOT"] != "") ) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
function printUsage()
|
$shortopts = "u:p:t:f:l:";
|
||||||
{
|
|
||||||
echo "\n";
|
|
||||||
echo "airtime-user\n";
|
|
||||||
echo "===============\n";
|
|
||||||
echo " This program allows you to manage Airtime users.\n";
|
|
||||||
echo "\n";
|
|
||||||
echo "OPTIONS:\n";
|
|
||||||
echo " --addupdate <username>\n";
|
|
||||||
echo " Add the user or update user information.\n";
|
|
||||||
echo " --delete <username>\n";
|
|
||||||
echo " Remove the user.\n";
|
|
||||||
echo "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$longopts = array(
|
||||||
* Ensures that the user is running this PHP script with root
|
"username:",
|
||||||
* permissions. If not running with root permissions, causes the
|
"password:",
|
||||||
* script to exit.
|
"type:",
|
||||||
*/
|
"first-name:",
|
||||||
function exitIfNotRoot()
|
"last-name:",
|
||||||
{
|
"addupdate",
|
||||||
// Need to check that we are superuser before running this.
|
"delete",
|
||||||
if(exec("whoami") != "root"){
|
);
|
||||||
echo "Must be root user.\n";
|
$options = getopt($shortopts, $longopts);
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($argv) != 3) {
|
$action = null;
|
||||||
|
if (isset($options["addupdate"])) {
|
||||||
|
$action = "addupdate";
|
||||||
|
}
|
||||||
|
else if (isset($options["delete"])) {
|
||||||
|
$action = "delete";
|
||||||
|
}
|
||||||
|
else {
|
||||||
printUsage();
|
printUsage();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($options["u"]) || isset($options["username"])) {
|
||||||
$action = null;
|
$username = $options["u"] ?: $options["username"];
|
||||||
switch ($argv[1]) {
|
|
||||||
case '--addupdate':
|
|
||||||
$action = "addupdate";
|
|
||||||
break;
|
|
||||||
case '--delete':
|
|
||||||
$action = "delete";
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
$username = $argv[2];
|
|
||||||
|
|
||||||
if (is_null($action)) {
|
|
||||||
printUsage();
|
printUsage();
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -92,43 +73,52 @@ if ($action == "addupdate") {
|
||||||
echo "Creating user\n";
|
echo "Creating user\n";
|
||||||
$user = new Application_Model_User("");
|
$user = new Application_Model_User("");
|
||||||
$user->setLogin($username);
|
$user->setLogin($username);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
echo "Updating user\n";
|
echo "Updating user\n";
|
||||||
$user = new Application_Model_User($id);
|
$user = new Application_Model_User($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
do{
|
//setting password
|
||||||
echo "Enter password (min 6 characters): ";
|
if (isset($options["p"]) || isset($options["password"])) {
|
||||||
$line = trim(fgets(fopen("php://stdin","r")));
|
|
||||||
}while(strlen($line) < 6);
|
$password = $options["p"] ?: $options["password"];
|
||||||
$user->setPassword($line);
|
$user->setPassword($password);
|
||||||
|
}
|
||||||
do{
|
|
||||||
echo "Enter first name: ";
|
//setting first-name
|
||||||
$line = trim(fgets(fopen("php://stdin","r")));
|
if (isset($options["f"]) || isset($options["first-name"])) {
|
||||||
}while(strlen($line) < 1);
|
|
||||||
$user->setFirstName($line);
|
$firstname = $options["f"] ?: $options["first-name"];
|
||||||
|
$user->setFirstName($firstname);
|
||||||
do{
|
}
|
||||||
echo "Enter last name: ";
|
|
||||||
$line = trim(fgets(fopen("php://stdin","r")));
|
//setting last-name
|
||||||
}while(strlen($line) < 1);
|
if (isset($options["l"]) || isset($options["last-name"])) {
|
||||||
$user->setLastName($line);
|
|
||||||
|
$lastname = $options["l"] ?: $options["last-name"];
|
||||||
do{
|
$user->setLastName($lastname);
|
||||||
echo "Enter user type [(A)dmin|(P)rogram Manager|(D)J|(G)uest]: ";
|
}
|
||||||
$line = trim(fgets(fopen("php://stdin","r")));
|
|
||||||
} while($line != "A" && $line != "P" && $line != "D" && $line != "G");
|
|
||||||
|
|
||||||
$types = array("A"=>"A", "P"=>"P", "D"=>"H", "G"=>"G",);
|
$types = array("A"=>"A", "P"=>"P", "D"=>"H", "G"=>"G",);
|
||||||
$user->setType($types[$line]);
|
//setting type
|
||||||
|
if (isset($options["t"]) || isset($options["type"])) {
|
||||||
|
|
||||||
|
$type = $options["t"] ?: $options["type"];
|
||||||
|
if (in_array($type, $types)) {
|
||||||
|
$user->setType($type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
}
|
||||||
} elseif ($action == "delete") {
|
else if ($action == "delete") {
|
||||||
if ($id < 0){
|
|
||||||
|
if ($id < 0){
|
||||||
echo "Username not found!\n";
|
echo "Username not found!\n";
|
||||||
exit;
|
exit;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
echo "Deleting user\n";
|
echo "Deleting user\n";
|
||||||
$user = new Application_Model_User($id);
|
$user = new Application_Model_User($id);
|
||||||
$user->delete();
|
$user->delete();
|
||||||
|
@ -146,3 +136,33 @@ function GetAirtimeConf()
|
||||||
|
|
||||||
return $ini;
|
return $ini;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function printUsage()
|
||||||
|
{
|
||||||
|
echo "\n";
|
||||||
|
echo "airtime-user\n";
|
||||||
|
echo "===============\n";
|
||||||
|
echo " This program allows you to manage Airtime users.\n";
|
||||||
|
echo "\n";
|
||||||
|
echo "OPTIONS:\n";
|
||||||
|
echo " airtime-user --addupdate -u|--username <USERNAME> [-p|--password <PASSWORD>] [-t|--type <A|P|D|G>] [-f|--first-name 'Name'] [-l|--last-name 'Name'] \n";
|
||||||
|
echo " Add the user or update user information.\n";
|
||||||
|
echo "\n";
|
||||||
|
echo " airtime-user --delete -u|--username <USERNAME>\n";
|
||||||
|
echo " Remove the user.\n";
|
||||||
|
echo "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ensures that the user is running this PHP script with root
|
||||||
|
* permissions. If not running with root permissions, causes the
|
||||||
|
* script to exit.
|
||||||
|
*/
|
||||||
|
function exitIfNotRoot()
|
||||||
|
{
|
||||||
|
// Need to check that we are superuser before running this.
|
||||||
|
if(exec("whoami") != "root"){
|
||||||
|
echo "Must be root user.\n";
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue