コード例 #1
0
 $Settings->setSetting('lastbatch', $batchID);
 $failedUsers = 0;
 for ($i = 0; $i < $user['numberoftickets']; $i++) {
     // Creating lots of users at once could timeout a script. Maybe add a set_time_limit(1) on each loop?
     if ($Settings->getSetting('simpleUsername')) {
         $username = \Grase\Util::randomLowercase($Settings->getSetting('usernameLength'));
     } else {
         $username = \Grase\Util::randomUsername($Settings->getSetting('usernameLength'));
     }
     if ($Settings->getSetting('numericPassword')) {
         $password = \Grase\Util::randomNumericPassword($Settings->getSetting('passwordLength'));
     } else {
         $password = \Grase\Util::randomPassword($Settings->getSetting('passwordLength'));
     }
     // Attempt to create user. Will error if it's not a unique username
     if (DatabaseFunctions::getInstance()->createUser($username, $password, $MaxMb, $MaxTime, expiry_for_group($group, $groupSettings), $groupSettings[$group]['ExpireAfter'], \Grase\Clean::text($_POST['Group']), \Grase\Clean::text($_POST['Comment']))) {
         AdminLog::getInstance()->log("Created new user {$username}");
         $Settings->addUserToBatch($batchID, $username);
         $createdUsernames[] = $username;
     } else {
         // Failed to create. Most likely not a unique username.
         // Try again but only for so long (i.e. all usernames are in use)
         $i--;
         // This really chokes up the logs, maybe don't log this? TODO
         AdminLog::getInstance()->log("Failed to created new user {$username}. Probably duplicate username");
         $failedUsers++;
         if ($failedUsers > 20) {
             AdminLog::getInstance()->log("Too many failed usernames, stopping batch creation");
             $error[] = sprintf(T_("Too many users failed to create. Batch creation stopped. %s users have been successfully created"), $i);
             break;
         }
コード例 #2
0
         }
     }
     $templateEngine->assign('selectedgateway', $_SESSION['selectedpaymentgateway']);
     $templateEngine->assign('selectedvoucher', $_SESSION['selectedvoucher']);
     $templateEngine->display('wizard_confirmselection.tpl');
     break;
 case 'paymentpage':
     //TODO Create user account and lock it here, so it's ready for the plugin to do with as needed (i.e. send details)
     //var_dump($_SESSION);
     //var_dump($_POST);
     //var_dump($vouchers);
     if (!isset($_SESSION['PendingAccount'])) {
         /* Create our locked random user */
         $MaxMb = $vouchers[$_SESSION['selectedvoucher']]['MaxMb'];
         $MaxTime = $vouchers[$_SESSION['selectedvoucher']]['MaxTime'];
         $Expiry = expiry_for_group($vouchers[$_SESSION['selectedvoucher']]['VoucherGroup']);
         $Comment = $_SESSION['selectedvoucher'] . " Voucher purchased " . date();
         $Username = \Grase\Util::randomUsername(5);
         $Password = \Grase\Util::randomPassword(6);
         // TODO Maybe set expiry to a few days so if payment isn't valid then we expire soon, and after sucessful payment we update expiry?
         DatabaseFunctions::getInstance()->createUser($Username, $Password, $MaxMb, $MaxTime, $Expiry, false, $vouchers[$_SESSION['selectedvoucher']]['VoucherGroup'], $Comment);
         // Lock user account
         DatabaseFunctions::getInstance()->lockUser($Username, T_('Account Pending Payment and Activation'));
         // Store user account in session
         $_SESSION['PendingAccount'] = array('Username' => $Username, 'Password' => $Password);
     }
     /* */
     require_once 'paymentgateways/PaymentGatewayPlugin.class.php';
     if (!is_file('paymentgateways/' . $paymentgateways[$_SESSION['selectedpaymentgateway']]['pluginfile'])) {
         die('Invalid payment plugin<br/><form action="" method="POST"><input type="hidden" name="pgformsubmission" value="1"/><input name="restartwizard" type="submit" value="Restart Wizard"/>');
     }
コード例 #3
0
    }
    // If Time Limit is changed and Not added too, Change Time Limit
    if ($maxTime !== '' && !$addTime && $maxTime != $user['MaxTime']) {
        if (!\Grase\Validate::numericLimit($maxTime)) {
            $error[] = sprintf(T_("Invalid value '%s' for Time Limit"), $maxTime);
        } else {
            DatabaseFunctions::getInstance()->setUserTimeLimit($username, $maxTime);
            DatabaseFunctions::getInstance()->setUserExpiry($username, expiry_for_group(DatabaseFunctions::getInstance()->getUserGroup($username)));
            // TODO: Check return for success
            $success[] = T_("Max Time Limit Updated");
            AdminLog::getInstance()->log(sprintf(T_("Max Time Limit changed for %s"), $username));
        }
    }
}
if (isset($_POST['unexpiresubmit'])) {
    DatabaseFunctions::getInstance()->setUserExpiry($username, expiry_for_group(DatabaseFunctions::getInstance()->getUserGroup($username)));
    $success[] = T_("Expiry updated");
}
// Delete User
if (isset($_POST['deleteusersubmit'])) {
    DatabaseFunctions::getInstance()->deleteUser($username);
    // TODO: Check for success
    $success[] = sprintf(T_("User '%s' Deleted"), $username);
    AdminLog::getInstance()->log("User {$username} deleted");
    $templateEngine->assign("error", $error);
    $templateEngine->assign("success", $success);
    require 'display.php';
    die;
    // TODO: Recode so don't need die (too many nests?)
}
$templateEngine->assign("error", $error);
コード例 #4
0
        $groupSettings = $Settings->getGroup($user['Group']);
        // TODO: Create function to make these the same across all locations
        // Check if we are using the dropdown, or inherit to override the input field
        if (is_numeric($user['Max_Mb'])) {
            $user['MaxMb'] = $user['Max_Mb'];
        } elseif ($user['Max_Mb'] == 'inherit') {
            $user['MaxMb'] = $groupSettings[$user['Group']]['MaxMb'];
        }
        // Check if we are using the dropdown, or inherit to override the input field
        if (is_numeric($user['Max_Time'])) {
            $user['MaxTime'] = $user['Max_Time'];
        } elseif ($user['Max_Time'] == 'inherit') {
            $user['MaxTime'] = $groupSettings[$user['Group']]['MaxTime'];
        }
        // TODO: Check if valid
        DatabaseFunctions::getInstance()->createUser($user['Username'], $user['Password'], $user['MaxMb'], $user['MaxTime'], expiry_for_group($user['Group'], $groupSettings), $groupSettings[$user['Group']]['ExpireAfter'], $user['Group'], $user['Comment']);
        $success[] = sprintf(T_("User %s Successfully Created"), $user['Username']);
        $success[] = "<a target='_tickets' href='export.php?format=html&user={$user['Username']}'>" . sprintf(T_("Print Ticket for %s"), $user['Username']) . "</a>";
        AdminLog::getInstance()->log(sprintf(T_("Created new user %s"), $user['Username']));
        $templateEngine->assign("success", $success);
        // We are now loading the form afresh, ensure we clear the $user array
        $user = array();
    }
}
$user['Password'] = \Grase\Util::randomPassword($Settings->getSetting('passwordLength'));
// TODO: make default settings customisable
$user['Max_Mb'] = 'inherit';
$user['Max_Time'] = 'inherit';
$user['Expiration'] = "--";
$templateEngine->assign("user", $user);
$templateEngine->displayPage($templateFile);
コード例 #5
0
 private function processPaymentPage()
 {
     //TODO Create user account and lock it here, so it's ready for the plugin to do with as needed (i.e. send details)
     if ($this->state->pendingAccount === false) {
         /* Create our locked random user */
         $MaxMb = $this->vouchers[$this->state->selectedVoucher]['MaxMb'];
         $MaxTime = $this->vouchers[$this->state->selectedVoucher]['MaxTime'];
         $Expiry = expiry_for_group($this->vouchers[$this->state->selectedVoucher]['VoucherGroup']);
         $Comment = $this->state->selectedVoucher . " Voucher purchased " . date('c');
         $Username = Util::randomUsername(5);
         $Password = Util::randomPassword(6);
         // TODO Maybe set expiry to a few days so if payment isn't valid then we expire soon, and after sucessful payment we update expiry?
         // TODO: Check if valid
         $this->DBF->createUser($Username, $Password, $MaxMb, $MaxTime, $Expiry, false, $this->vouchers[$this->state->selectedVoucher]['VoucherGroup'], $Comment);
         // Lock user account
         $this->DBF->lockUser($Username, T_('Account Pending Payment and Activation'));
         // Store user account in session
         $this->state->pendingAccount = array('Username' => $Username, 'Password' => $Password);
     }
     /* */
     require_once 'paymentgateways/PaymentGatewayPlugin.class.php';
     if (!is_file('paymentgateways/' . $paymentgateways[$this->state->selectedPaymentGateway]['pluginfile'])) {
         die('Invalid payment plugin<br/><form action="" method="POST"><input type="hidden" name="pgformsubmission" value="1"/><input name="restartwizard" type="submit" value="Restart Wizard"/>');
     }
     // TODO Clean up and make error detection lots lots better
     require_once 'paymentgateways/' . $paymentgateways[$this->state->selectedPaymentGateway]['pluginfile'];
     // Recreate object each time
     $classname = "PG_" . $this->state->selectedPaymentGateway;
     $paymentplugin = new $classname($_SESSION['PendingAccount'], $_SESSION['selectedvoucher']);
     //$paymentplugin-> // Load voucher and user details (at initilisation) TODO
     // Load state from SESSION
     if (isset($_SESSION['paymentGatewayPluginState'])) {
         $paymentplugin->setState($_SESSION['paymentGatewayPluginState']);
     }
     $nextpage = $paymentplugin->currentPage();
     // Check if payment is complete
     if (!$paymentplugin->isPaymentCompleted()) {
         // Payment isn't completed
         // Check for page submission
         if (isset($_POST['pgformsubmission'])) {
             $nextpage = $paymentplugin->processPage($nextpage);
             // TODO After processing page, again check if payment is complete
         }
     }
     // Page has been processed, we now check if payment is complete and do what we need
     if ($paymentplugin->isPaymentCompleted() && !isset($_SESSION['AccountActivated'])) {
         // Payment completed, display user details, activate user, cleanup
         // Activate the account. It's upto the plugin to display things
         $this->DBF->unlockUser($_SESSION['PendingAccount']['Username']);
         $_SESSION['AccountActivated'] = true;
         // Expire session after 5 minutes to prevent others from seeing saved login details
         // TODO provide link to clear details
         $_SESSION['ExpireSession'] = time() + 300;
         /* TODO Store purchase details in database, along with payment details
          * including price and plugin used, and any receipt number
          */
         //print $paymentplugin->getPaymentDetails(); TODO TODO TODO TODO
     }
     /* Regardless of payment completion and page processing, we now display the page.
      * If anything is wrong with the processing this page will let us know as the plugin
      * handles which state we are in.
      */
     $pagecontents = $paymentplugin->getPageContents($nextpage);
     echo '<form action="" method="POST"><input type="hidden" name="pgformsubmission" value="1"/>';
     echo $pagecontents;
     // Store state into SESSION
     $_SESSION['paymentGatewayPluginState'] = $paymentplugin->getState();
     // Load payment gateway based on $this->selectedPaymentGateway
 }