/**
  * prompts for a username to set as active user on performing updates. this must be an admin user.
  * the user account will be returned. this method can be called by cli only, so a exception will 
  * be thrown if not running on cli
  * 
  * @throws Tinebase_Exception
  * @return Tinebase_Model_FullUser
  */
 public function promptForUsername()
 {
     if (php_sapi_name() == 'cli') {
         if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
             Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Prompting for username on CLI');
         }
         $userFound = NULL;
         do {
             try {
                 if ($userFound === FALSE) {
                     echo PHP_EOL;
                     echo 'The user could not be found!' . PHP_EOL . PHP_EOL;
                 }
                 $user = Tinebase_Server_Cli::promptInput('Please enter an admin username to perform updates ');
                 $userAccount = Tinebase_User::getInstance()->getFullUserByLoginName($user);
                 if (!$userAccount->hasRight('Tinebase', Tinebase_Acl_Rights::ADMIN)) {
                     $userFound = NULL;
                     echo PHP_EOL;
                     echo 'The user "' . $user . '" could be found, but this is not an admin user!' . PHP_EOL . PHP_EOL;
                 } else {
                     Tinebase_Core::set(Tinebase_Core::USER, $userAccount);
                     $userFound = TRUE;
                 }
             } catch (Tinebase_Exception_NotFound $e) {
                 $userFound = FALSE;
             }
         } while (!$userFound);
     } else {
         throw new Setup_Exception_PromptUser('no CLI call');
     }
     return $userAccount;
 }
Beispiel #2
0
 /**
  * create admin user / activate existing user / allow to reset password
  * 
  * @param Zend_Console_Getopt $_opts
  */
 protected function _createAdminUser(Zend_Console_Getopt $_opts)
 {
     if (!Setup_Controller::getInstance()->isInstalled('Tinebase')) {
         die('Install Tinebase first.');
     }
     echo "Please enter a username. If the user already exists, he is reactivated and you can reset the password.\n";
     $username = Tinebase_Server_Cli::promptInput('Username');
     $tomorrow = Tinebase_DateTime::now()->addDay(1);
     try {
         $user = Tinebase_User::getInstance()->getFullUserByLoginName($username);
         echo "User {$username} already exists.\n";
         $user->accountExpires = $tomorrow;
         $user->accountStatus = Tinebase_Model_User::ACCOUNT_STATUS_ENABLED;
         Tinebase_User::getInstance()->updateUser($user);
         echo "Activated admin user '{$username}' (expires tomorrow).\n";
         $resetPw = Tinebase_Server_Cli::promptInput('Do you want to reset the password (default: "no", "y" or "yes" for reset)?');
         if ($resetPw === 'y' or $resetPw === 'yes') {
             $password = $this->_promptPassword();
             Tinebase_User::getInstance()->setPassword($user, $password);
             echo "User password has been reset.\n";
         }
         // check admin group membership
         $adminGroup = Tinebase_Group::getInstance()->getDefaultAdminGroup();
         $memberships = Tinebase_Group::getInstance()->getGroupMemberships($user);
         if (!in_array($adminGroup->getId(), $memberships)) {
             try {
                 Tinebase_Group::getInstance()->addGroupMember($adminGroup, $user);
                 echo "Added user to default admin group\n";
             } catch (Zend_Ldap_Exception $zle) {
                 echo "Could not add user to default admin group: " . $zle->getMessage();
             }
         }
     } catch (Tinebase_Exception_NotFound $tenf) {
         if (Tinebase_User::getConfiguredBackend() === Tinebase_User::LDAP) {
             die('It is not possible to create a new user with LDAP user backend here.');
         }
         // create new admin user that expires tomorrow
         $password = $this->_promptPassword();
         Tinebase_User::createInitialAccounts(array('adminLoginName' => $username, 'adminPassword' => $password, 'expires' => $tomorrow));
         echo "Created new admin user '{$username}' that expires tomorrow.\n";
     }
 }
 /**
  * create admin user / activate existing user / allow to reset password
  * 
  * @param Zend_Console_Getopt $_opts
  * 
  * @todo check role by rights and not by name
  * @todo replace echos with stdout logger
  */
 protected function _createAdminUser(Zend_Console_Getopt $_opts)
 {
     if (!Setup_Controller::getInstance()->isInstalled('Tinebase')) {
         die('Install Tinebase first.');
     }
     echo "Please enter a username. If the user already exists, he is reactivated and you can reset the password.\n";
     $username = strtolower(Tinebase_Server_Cli::promptInput('Username'));
     $tomorrow = Tinebase_DateTime::now()->addDay(1);
     try {
         $user = Tinebase_User::getInstance()->getFullUserByLoginName($username);
         echo "User {$username} already exists.\n";
         Tinebase_User::getInstance()->setStatus($user->getId(), Tinebase_Model_User::ACCOUNT_STATUS_ENABLED);
         echo "Activated admin user '{$username}'.\n";
         $expire = Tinebase_Server_Cli::promptInput('Should the admin user expire tomorrow (default: "no", "y" or "yes" for expiry)?');
         if ($expire === 'y' or $expire === 'yes') {
             Tinebase_User::getInstance()->setExpiryDate($user->getId(), $tomorrow);
             echo "User expires tomorrow at {$tomorrow}.\n";
         }
         $resetPw = Tinebase_Server_Cli::promptInput('Do you want to reset the password (default: "no", "y" or "yes" for reset)?');
         if ($resetPw === 'y' or $resetPw === 'yes') {
             $password = $this->_promptPassword();
             Tinebase_User::getInstance()->setPassword($user, $password);
             echo "User password has been reset.\n";
         }
         $this->_checkAdminGroupMembership($user);
         $this->_checkAdminRole($user);
     } catch (Tinebase_Exception_NotFound $tenf) {
         // create new admin user that expires tomorrow
         $password = $this->_promptPassword();
         Tinebase_User::createInitialAccounts(array('adminLoginName' => $username, 'adminPassword' => $password, 'expires' => $tomorrow));
         echo "Created new admin user '{$username}' that expires tomorrow.\n";
     }
 }
Beispiel #4
0
try {
    $opts = new Zend_Console_Getopt(array('help|h' => 'Display this help Message', 'verbose|v' => 'Output messages', 'dry|d' => "Dry run - don't change anything", 'info|i' => 'Get usage description of method', 'method=s' => 'Method to call [required]', 'username=s' => 'Username [required]', 'password=s' => 'Password', 'passwordfile=s' => 'Name of file that contains password'));
    $opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
    echo $e->getMessage() . "\n";
    echo $e->getUsageMessage();
    exit;
}
if (count($opts->toArray()) === 0 || $opts->h || empty($opts->method)) {
    echo $opts->getUsageMessage();
    exit;
}
// get username / password if not already set
if (!in_array($opts->method, $anonymousMethods)) {
    if (empty($opts->username)) {
        $opts->username = Tinebase_Server_Cli::promptInput('username');
    }
    if (empty($opts->username)) {
        echo "error: username must be given! exiting \n";
        exit(1);
    }
    if (empty($opts->password)) {
        if (empty($opts->passwordfile)) {
            $opts->password = Tinebase_Server_Cli::promptInput('password', TRUE);
        } else {
            $opts->password = Tinebase_Server_Cli::getPasswordFromFile($opts->passwordfile);
        }
    }
}
Tinebase_Core::set('opts', $opts);
Tinebase_Core::dispatchRequest();