예제 #1
0
 public function _check_crc($message)
 {
     // @codingStandardsIgnoreEnd
     if (!$this->error_detection) {
         return true;
     }
     return parent::_check_crc($message);
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
파일: SIP2.php 프로젝트: tillk/vufind
 /**
  * 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;
 }
예제 #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;
 }
예제 #5
0
 public function checkInItem($barcode)
 {
     global $configArray;
     //Place the hold via SIP 2
     $mysip = new sip2();
     $mysip->hostname = $configArray['SIP2']['host'];
     $mysip->port = $configArray['SIP2']['online_port'];
     $hold_result['result'] = false;
     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 = $user->cat_username;
             $mysip->patronpwd = $user->cat_password;
             $in = $mysip->msgCheckin($barcode, $mysip->_datestamp());
             $msg_result = $mysip->get_message($in);
             if (preg_match("/^10/", $msg_result)) {
                 $result = $mysip->parseCheckinResponse($msg_result);
                 $checkout_result['result'] = $result['fixed']['Ok'] == 1;
                 $checkout_result['success'] = $checkout_result['result'];
                 $checkout_result['message'] = $result['variable']['AF'][0];
                 $checkout_result['sipinput'] = $in;
                 $checkout_result['sipresult'] = $result;
             }
         }
     }
     return $checkout_result;
 }
예제 #6
0
 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;
 }
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;
    }
}