Beispiel #1
0
 /**
  * Attempt to authenticate the current user.  Throws exception if login fails.
  *
  * @param \Zend\Http\PhpEnvironment\Request $request Request object containing
  * account credentials.
  *
  * @throws AuthException
  * @return \VuFind\Db\Row\User Object representing logged-in user.
  */
 public function authenticate($request)
 {
     $username = trim($request->getPost()->get('username', ''));
     $password = trim($request->getPost()->get('password', ''));
     if ($username == '' || $password == '') {
         throw new AuthException('authentication_error_blank');
     }
     // Attempt SIP2 Authentication
     $mysip = new \sip2();
     $config = $this->getConfig();
     if (isset($config->SIP2)) {
         $mysip->hostname = $config->SIP2->host;
         $mysip->port = $config->SIP2->port;
     }
     if (!$mysip->connect()) {
         throw new AuthException('authentication_error_technical');
     }
     //send selfcheck status message
     $in = $mysip->msgSCStatus();
     $msg_result = $mysip->get_message($in);
     // Make sure the response is 98 as expected
     if (!preg_match("/^98/", $msg_result)) {
         $mysip->disconnect();
         throw new AuthException('authentication_error_technical');
     }
     $result = $mysip->parseACSStatusResponse($msg_result);
     //  Use result to populate SIP2 setings
     $mysip->AO = $result['variable']['AO'][0];
     $mysip->AN = $result['variable']['AN'][0];
     $mysip->patron = $username;
     $mysip->patronpwd = $password;
     $in = $mysip->msgPatronStatusRequest();
     $msg_result = $mysip->get_message($in);
     // Make sure the response is 24 as expected
     if (!preg_match("/^24/", $msg_result)) {
         $mysip->disconnect();
         throw new AuthException('authentication_error_technical');
     }
     $result = $mysip->parsePatronStatusResponse($msg_result);
     $mysip->disconnect();
     if ($result['variable']['BL'][0] == 'Y' and $result['variable']['CQ'][0] == 'Y') {
         // Success!!!
         $user = $this->processSIP2User($result, $username, $password);
         // Set login cookie for 1 hour
         $user->password = $password;
         // Need this for Metalib
     } else {
         throw new AuthException('authentication_error_invalid');
     }
     return $user;
 }
function runCheckout($patronCode, $itemCode, $sipServer, $sipPort, $sipPatron, $sipPassword)
{
    $mysip = new sip2();
    $mysip->hostname = $sipServer;
    $mysip->port = $sipPort;
    $result = $mysip->connect();
    if (!$result) {
        $mysip->disconnect();
        return false;
    }
    $sc_login = $mysip->msgLogin($sipPatron, $sipPassword);
    $result = $mysip->parseLoginResponse($mysip->get_message($sc_login));
    $mysip->patron = $patronCode;
    $cko_action = $mysip->msgCheckout($itemCode);
    $cko_msg = $mysip->get_message($cko_action);
    if ($mysip->parseCheckoutResponse($cko_msg)['fixed']['Ok'] == 2) {
        $mysip->disconnect();
        return $mysip->parseCheckoutResponse($cko_msg);
    } else {
        $mysip->disconnect();
        return $cko_msg;
    }
}
 /**
  * Attempt to authenticate the current user.
  *
  * @return object User object if successful, PEAR_Error otherwise.
  * @access public
  */
 public function authenticate()
 {
     global $configArray;
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         if ($username != '' && $password != '') {
             // Attempt SIP2 Authentication
             $mysip = new sip2();
             $mysip->hostname = $configArray['SIP2']['host'];
             $mysip->port = $configArray['SIP2']['port'];
             if ($mysip->connect()) {
                 //send selfcheck status message
                 $in = $mysip->msgSCStatus();
                 $msg_result = $mysip->get_message($in);
                 // Make sure the response is 98 as expected
                 if (preg_match("/^98/", $msg_result)) {
                     $result = $mysip->parseACSStatusResponse($msg_result);
                     //  Use result to populate SIP2 setings
                     $mysip->AO = $result['variable']['AO'][0];
                     $mysip->AN = $result['variable']['AN'][0];
                     $mysip->patron = $username;
                     $mysip->patronpwd = $password;
                     $in = $mysip->msgPatronStatusRequest();
                     $msg_result = $mysip->get_message($in);
                     // Make sure the response is 24 as expected
                     if (preg_match("/^24/", $msg_result)) {
                         $result = $mysip->parsePatronStatusResponse($msg_result);
                         if ($result['variable']['BL'][0] == 'Y' and $result['variable']['CQ'][0] == 'Y') {
                             // Success!!!
                             $user = $this->_processSIP2User($result, $username, $password);
                             // Set login cookie for 1 hour
                             $user->password = $password;
                             // Need this for Metalib
                         } else {
                             $user = new PEAR_Error('authentication_error_invalid');
                         }
                     } else {
                         $user = new PEAR_Error('authentication_error_technical');
                     }
                 } else {
                     $user = new PEAR_Error('authentication_error_technical');
                 }
                 $mysip->disconnect();
             } else {
                 $user = new PEAR_Error('authentication_error_technical');
             }
         } else {
             $user = new PEAR_Error('authentication_error_blank');
         }
     } else {
         $user = new PEAR_Error('authentication_error_blank');
     }
     return $user;
 }
Beispiel #4
0
 /**
  * Mark fees as paid.
  *
  * This is called after a successful online payment.
  *
  * @param array $patron The patron array from patronLogin
  * @param int   $amount Amount to be registered as paid.
  *
  * @return mixed true if successfull, or PEAR_Error if registering failed.
  * @access public
  */
 public function markFeesAsPaid($patron, $amount)
 {
     $params = isset($this->config['OnlinePayment']['registrationParams']) ? $this->config['OnlinePayment']['registrationParams'] : array();
     $required = array('host', 'port', 'userId', 'password', 'locationCode');
     foreach ($required as $req) {
         if (!isset($params[$req])) {
             error_log("Missing SIP2 parameter {$req}");
             return new PEAR_Error('online_payment_registration_failed');
         }
     }
     $currency = $this->config['OnlinePayment']['currency'];
     $patronId = $patron['cat_username'];
     $errFun = function ($patronId, $error) {
         error_log("SIP2 payment error: {$error}");
         error_log("   patron: {$patronId}");
         return new PEAR_Error('online_payment_registration_failed');
     };
     $sip = new sip2();
     $sip->error_detection = false;
     $sip->msgTerminator = "\r";
     $sip->hostname = $params['host'];
     $sip->port = $params['port'];
     $sip->AO = '';
     // SIP expects payable amount to be a string
     // with ',' as a decimal point
     $amount = (string) ($amount / 100.0);
     $amount = str_replace('.', ',', $amount);
     if ($sip->connect()) {
         $sip->scLocation = $params['locationCode'];
         $sip->UIDalgorithm = 0;
         $sip->PWDalgorithm = 0;
         $login_msg = $sip->msgLogin($params['userId'], $params['password']);
         $login_response = $sip->get_message($login_msg);
         if (strncmp('94', $login_response, 2) == 0) {
             $login_result = $sip->parseLoginResponse($login_response);
             if ($login_result['fixed']['Ok'] == '1') {
                 $sip->patron = $patronId;
                 $feepaid_msg = $sip->msgFeePaid(1, 0, $amount, $currency);
                 $feepaid_response = $sip->get_message($feepaid_msg);
                 if (strncmp('38', $feepaid_response, 2) == 0) {
                     $feepaid_result = $sip->parseFeePaidResponse($feepaid_response);
                     if ($feepaid_result['fixed']['PaymentAccepted'] == 'Y') {
                         $sip->disconnect();
                         return true;
                     } else {
                         $sip->disconnect();
                         return $errFun($patronId, 'payment rejected');
                     }
                 } else {
                     $sip->disconnect();
                     return $errFun($patronId, 'payment failed');
                 }
             } else {
                 $sip->disconnect();
                 return $errFun($patronId, 'login failed');
             }
         } else {
             $sip->disconnect();
             return $errFun($patronId, 'login failed');
         }
     } else {
         return $errFun($patronId, 'connection error');
     }
     return true;
 }
Beispiel #5
0
 public function getMyProfile($patron, $forceReload = false)
 {
     global $timer;
     global $configArray;
     if (is_object($patron)) {
         $patron = get_object_vars($patron);
     }
     if (array_key_exists($patron['username'], $this->patronProfiles) && !$forceReload) {
         $timer->logTime('Retrieved Cached Profile for Patron');
         return $this->patronProfiles[$patron['username']];
     }
     $mysip = new sip2();
     $mysip->hostname = $configArray['SIP2']['host'];
     $mysip->port = $configArray['SIP2']['port'];
     if ($mysip->connect()) {
         //send selfcheck status message
         $in = $mysip->msgSCStatus();
         $msg_result = $mysip->get_message($in);
         // Make sure the response is 98 as expected
         if (preg_match("/^98/", $msg_result)) {
             $result = $mysip->parseACSStatusResponse($msg_result);
             //  Use result to populate SIP2 setings
             $mysip->AO = $result['variable']['AO'][0];
             /* set AO to value returned */
             $mysip->AN = $result['variable']['AN'][0];
             /* set AN to value returned */
             $mysip->patron = $patron['username'];
             $mysip->patronpwd = $patron['cat_password'];
             $in = $mysip->msgPatronInformation('fine');
             $msg_result = $mysip->get_message($in);
             // Make sure the response is 24 as expected
             if (preg_match("/^64/", $msg_result)) {
                 $result = $mysip->parsePatronInfoResponse($msg_result);
                 $address = $result['variable']['BD'][0];
                 $addressParts = explode(',', $address);
                 $expirationDate = $result['variable']['PE'][0];
                 $formattedExpiration = substr($expirationDate, 4, 2) . '/' . substr($expirationDate, 6, 2) . '/' . substr($expirationDate, 0, 4);
                 //$fines = $this->parseSip2Fines($result['variable']['AV']);
                 $location = new Location();
                 $location->code = $result['variable']['AQ'][0];
                 $location->find();
                 if ($location->N > 0) {
                     $location->fetch();
                     $homeLocationId = $location->locationId;
                 }
                 global $user;
                 $profile = array('lastname' => $result['variable']['DJ'][0], 'firstname' => isset($result['variable']['DH'][0]) ? $result['variable']['DH'][0] : '', 'displayName' => $patron['displayName'], 'fullname' => $result['variable']['AE'][0], 'address1' => trim($addressParts[0]), 'city' => trim($addressParts[1]), 'state' => trim($addressParts[2]), 'zip' => isset($addressParts[3]) ? trim($addressParts[3]) : '', 'phone' => isset($result['variable']['BF'][0]) ? $result['variable']['BF'][0] : '', 'email' => isset($result['variable']['BE'][0]) ? $result['variable']['BE'][0] : '', 'homeLocationId' => isset($homeLocationId) ? $homeLocationId : -1, 'homeLocationName' => $this->translateLocation($result['variable']['AQ'][0]), 'expires' => $formattedExpiration, 'fines' => isset($result['variable']['BV']) ? sprintf('$%01.2f', $result['variable']['BV'][0]) : 0, 'finesval' => isset($result['variable']['BV']) ? $result['variable']['BV'][0] : '', 'numHolds' => $result['fixed']['HoldCount'] + $result['fixed']['UnavailableCount'], 'numHoldsAvailable' => $result['fixed']['HoldCount'], 'numHoldsRequested' => $result['fixed']['UnavailableCount'], 'numCheckedOut' => $result['fixed']['ChargedCount'], 'bypassAutoLogout' => $user ? $user->bypassAutoLogout : false);
                 //Get eContent info as well
                 require_once ROOT_DIR . '/Drivers/EContentDriver.php';
                 $eContentDriver = new EContentDriver();
                 $eContentAccountSummary = $eContentDriver->getAccountSummary();
                 $profile = array_merge($profile, $eContentAccountSummary);
                 //Get a count of the materials requests for the user
                 $materialsRequest = new MaterialsRequest();
                 $materialsRequest->createdBy = $user->id;
                 $statusQuery = new MaterialsRequestStatus();
                 $statusQuery->isOpen = 1;
                 $materialsRequest->joinAdd($statusQuery);
                 $materialsRequest->find();
                 $profile['numMaterialsRequests'] = $materialsRequest->N;
             } else {
                 $profile = new PEAR_Error('patron_info_error_technical');
             }
         } else {
             $profile = new PEAR_Error('patron_info_error_technical');
         }
         $mysip->disconnect();
     } else {
         $profile = new PEAR_Error('patron_info_error_technical');
     }
     $this->patronProfiles[$patron['username']] = $profile;
     $timer->logTime('Retrieved Profile for Patron from SIP 2');
     return $profile;
 }
 public function authenticate()
 {
     global $configArray;
     global $timer;
     if (isset($_POST['username']) && isset($_POST['password'])) {
         $username = $_POST['username'];
         $password = $_POST['password'];
         //Set this up to use library prefix
         $barcodePrefix = $configArray['Catalog']['barcodePrefix'];
         if (strlen($barcodePrefix) > 0) {
             if (strlen($username) == 9) {
                 $username = substr($barcodePrefix, 0, 5) . $username;
             } elseif (strlen($username) == 8) {
                 $username = substr($barcodePrefix, 0, 6) . $username;
             } elseif (strlen($username) == 7) {
                 $username = $barcodePrefix . $username;
             }
         }
         //Check to see if we have already processed this user
         if (array_key_exists($username, self::$processedUsers)) {
             return self::$processedUsers[$username];
         }
         if ($username != '' && $password != '') {
             // Attempt SIP2 Authentication
             $mysip = new sip2();
             $mysip->hostname = $configArray['SIP2']['host'];
             $mysip->port = $configArray['SIP2']['port'];
             if ($mysip->connect()) {
                 //send selfcheck status message
                 $in = $mysip->msgSCStatus();
                 $msg_result = $mysip->get_message($in);
                 // Make sure the response is 98 as expected
                 if (preg_match("/^98/", $msg_result)) {
                     $result = $mysip->parseACSStatusResponse($msg_result);
                     //  Use result to populate SIP2 setings
                     $mysip->AO = $result['variable']['AO'][0];
                     /* set AO to value returned */
                     if (isset($result['variable']['AN'])) {
                         $mysip->AN = $result['variable']['AN'][0];
                         /* set AN to value returned */
                     }
                     $mysip->patron = $username;
                     $mysip->patronpwd = $password;
                     $in = $mysip->msgPatronStatusRequest();
                     $msg_result = $mysip->get_message($in);
                     // Make sure the response is 24 as expected
                     if (preg_match("/^24/", $msg_result)) {
                         $result = $mysip->parsePatronStatusResponse($msg_result);
                         if ($result['variable']['BL'][0] == 'Y' and $result['variable']['CQ'][0] == 'Y') {
                             //Get patron info as well
                             $in = $mysip->msgPatronInformation('none');
                             $msg_result = $mysip->get_message($in);
                             // Make sure the response is 24 as expected
                             if (preg_match("/^64/", $msg_result)) {
                                 $patronInfoResponse = $mysip->parsePatronInfoResponse($msg_result);
                                 //print_r($patronInfoResponse);
                             }
                             // Success!!!
                             $user = $this->processSIP2User($result, $username, $password, $patronInfoResponse);
                             // Set login cookie for 1 hour
                             $user->password = $password;
                             // Need this for Metalib
                         } else {
                             $user = new PEAR_Error('authentication_error_invalid');
                         }
                     } else {
                         $user = new PEAR_Error('authentication_error_technical');
                     }
                 } else {
                     $user = new PEAR_Error('authentication_error_technical');
                 }
                 $mysip->disconnect();
             } else {
                 $user = new PEAR_Error('authentication_error_technical');
                 global $logger;
                 $logger->log("Unable to connect to SIP server", PEAR_LOG_ERR);
             }
         } else {
             $user = new PEAR_Error('authentication_error_blank');
         }
         $timer->logTime("Authenticated user in SIP2Authentication");
         self::$processedUsers[$username] = $user;
     } else {
         $user = new PEAR_Error('authentication_error_blank');
     }
     return $user;
 }