Example #1
0
function addKeylinks($kid, $uid)
{
    $data = array("uid" => $uid, "kid" => $kid);
    $linkid = db_new("users_keys_links", $data);
    if ($linkid) {
        return ErrorCode::CODE("1011");
    } else {
        return ErrorCode::CODE("1012");
    }
}
Example #2
0
function GetUserLinks($uid)
{
    $sql = "select k.`key` from users_keys_links as l\n            left join `keys` as k\n            on l.kid = k.id\n            WHERE l.uid=:uid and l.is_delete=0";
    $list = db_query($sql, array(":uid" => $uid));
    if ($list) {
        return ErrorCode::CODE("1009", array("list" => $list));
    } else {
        return ErrorCode::CODE("1010");
    }
}
Example #3
0
function GetUserinfoJson($token)
{
    if (empty($token)) {
        die(ErrorCode::CODE("1007"));
    }
    $userinfo = json_decode(Crypt3Des::decrypt(urldecode($token), $GLOBALS['keys']), true);
    if (empty($userinfo)) {
        die(ErrorCode::CODE("1008"));
    }
    return $userinfo;
}
Example #4
0
        die('{"encrypt":"' . $md5Key . '"}');
    }
});
if_post("/GetKeyList.json", function () {
    is_api();
    $json = file_get_contents('php://input');
    $jsonarray = json_decode($json, true);
    $userinfo = GetUserinfoJson($jsonarray['token']);
    die(GetUserLinks($userinfo['id']));
});
if_post("/addKey.json", function () {
    is_api();
    $json = file_get_contents('php://input');
    $jsonarray = json_decode($json, true);
    $userinfo = GetUserinfoJson($jsonarray['token']);
    $keyid = findkey($jsonarray['key']);
    if ($keyid) {
        if (findkeyslinkidcount($keyid['id'], $userinfo['id'])) {
            die(ErrorCode::CODE("1012"));
        } else {
            die(addKeylinks($keyid['id'], $userinfo['id']));
        }
    } else {
        $kid = addKeys(array("key" => $jsonarray['key']));
        if ($kid) {
            die(addKeylinks($kid, $userinfo['id']));
        } else {
            die(ErrorCode::CODE("1012"));
        }
    }
});
Example #5
0
 /**
  * Parses the url, and dispatches to the appropriate controller.
  * @param bool $skipControllerInitialization
  */
 public function dispatch($skipControllerInitialization = false)
 {
     Profile::start('Dispatcher', 'Dispatching');
     $contentTypes = array();
     try {
         $controllerName = isset($_GET['controller']) ? trim($_GET['controller']) : $this->defaultControllerName;
         $controllerName = $this->controllerFromUrlSanitizer->sanitize($controllerName);
         $invalidControllerName = false;
         try {
             $controller = $this->controllerFactory->get($controllerName);
         } catch (ControllerFactoryException $e) {
             // Not failing just yet, so the model gets initialized.
             $invalidControllerName = true;
             $controller = $this->controllerFactory->get($this->defaultControllerName);
         }
         $model = new Model();
         $controller->setModel($model);
         $controller->initModel();
         $contentTypes = $this->getAcceptContentTypes($_SERVER['HTTP_ACCEPT']);
         try {
             if ($invalidControllerName) {
                 ErrorCode::notFound();
             }
             try {
                 $errorDuringRender = null;
                 $errorCode = null;
                 // Try to dispatch to the actual action.
                 $actionParameters = explode('/', isset($_GET['action']) ? $_GET['action'] : 'index');
                 $action = $actionParameters[0];
                 array_shift($actionParameters);
                 if ($action[0] === '_') {
                     throw new ErrorCode(ErrorCode::NOT_FOUND, 'Tried to access action with underscore.');
                 }
                 $action = $this->actionFromUrlSanitizer->sanitize($action);
                 try {
                     // Check if the action is valid
                     $reflectionClass = new ReflectionClass($controller);
                     $actionMethod = $reflectionClass->getMethod($action);
                     if ($action !== 'index' && (method_exists('Controller', $action) || !$actionMethod->isPublic() || $actionMethod->class !== get_class($controller))) {
                         throw new DispatcherException();
                     }
                 } catch (Exception $e) {
                     throw new ErrorCode(ErrorCode::NOT_FOUND, 'Tried to access invalid action.');
                 }
                 $controller->setAction($action);
                 $parameters = array();
                 $stringParameters = array();
                 $i = 0;
                 foreach ($actionMethod->getParameters() as $parameter) {
                     $actionParameter = isset($actionParameters[$i]) ? $actionParameters[$i] : null;
                     if ($actionParameter === null) {
                         if (!$parameter->isDefaultValueAvailable()) {
                             throw new ErrorCode(ErrorCode::BAD_REQUEST, 'Not all parameters supplied.');
                         }
                         // Well: there is no more additional query, and apparently the rest of the parameters are optional, so continue.
                         continue;
                     }
                     if (($parameterTypeClass = $parameter->getClass()) != false) {
                         if (!$parameterTypeClass->isSubclassOf('RW_Type')) {
                             throw new ErrorCode(ErrorCode::BAD_REQUEST, 'Invalid parameter type.');
                         }
                         $parameterTypeClassName = $parameterTypeClass->getName();
                         $parameters[] = new $parameterTypeClassName($actionParameter);
                     } else {
                         $parameters[] = $actionParameter;
                     }
                     $stringParameters[] = $actionParameter;
                     $i++;
                 }
                 $controller->setActionParameters($stringParameters);
                 if (!$skipControllerInitialization) {
                     $controller->initialize();
                 }
                 // This actually calls the apropriate action.
                 call_user_func_array(array($controller, $action), $parameters);
                 $controller->extendModel();
                 try {
                     $this->renderers->render($controller->getViewName(), $model, $this->notificationCenter, $this->theme->getTemplatesPath(), $contentTypes, $controller);
                 } catch (Exception $e) {
                     throw new ErrorCode(ErrorCode::INTERNAL_SERVER_ERROR, 'Error during render: ' . $e->getMessage());
                 }
             } catch (ErrorMessageException $e) {
                 $errorDuringRender = true;
                 $this->notificationCenter->addError($e->getMessage());
             } catch (ErrorCode $e) {
                 throw $e;
             } catch (Exception $e) {
                 $additionalInfo = array();
                 $additionalInfo['controllerName'] = $controllerName;
                 if (isset($action)) {
                     $additionalInfo['action'] = $action;
                 }
                 $additionalInfo['exceptionThrown'] = get_class($e);
                 $additionalInfo['error'] = $e->getMessage();
                 Log::warning($e->getMessage(), 'Dispatcher', $additionalInfo);
                 throw new ErrorCode(ErrorCode::INTERNAL_SERVER_ERROR);
             }
         } catch (ErrorCode $e) {
             // All other exceptions have already been caught.
             $errorDuringRender = true;
             $errorCode = $e->getCode();
             $e->writeHttpHeader();
             if ($e->getMessage()) {
                 Log::debug($e->getMessage(), 'Dispatcher');
             }
         }
         if ($errorDuringRender) {
             $this->renderers->renderError($errorCode, $model, $this->notificationCenter, $this->theme->getTemplatesPath(), $contentTypes);
         }
     } catch (Exception $e) {
         try {
             Log::fatal('There has been a fatal error dispatching.', 'Dispatcher', array('error' => $e->getMessage()));
             $this->renderers->renderFatalError($this->notificationCenter, $this->theme->getTemplatesPath(), $contentTypes);
         } catch (Exception $e) {
             die('<h1 class="error">Fatal error...</h1>');
         }
     }
     Profile::stop();
 }
Example #6
0
 /**
  * Constructs a new error with the given error code and error message.
  * @private
  * 
  * @param code
  *	The error code associated with this error. This should be a
  *	valid integer.
  * @param message
  *	The error message associated with this error. This is an alphanumeric string. This should not
  *	be null.
  */
 function Error($code, $message)
 {
     $this->m_code = ErrorCode::parse($code);
     $this->m_message = $message;
 }
Example #7
0
 /**
  * Handles a start tag.
  * @private
  */
 function elementStartHandler($parser, $name, $attrs)
 {
     $name = trim($name);
     array_push($this->m_tagStack, $name);
     if (empty($attrs)) {
         return;
     }
     if ($this->m_tagStack === array("RESPONSE")) {
         $this->m_serverName = $attrs["TYPE"];
         $this->m_serverVersion = $attrs["VERSION"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "ADDITIONALVERIFICATION", "ADDRESS")) {
         $this->m_addressResponseData = $attrs["RAW"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "ADDITIONALVERIFICATION", "CSC")) {
         $this->m_cscResponseData = $attrs["RAW"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "ADDITIONALVERIFICATION", "ZIP")) {
         $this->m_zipCodeResponseData = $attrs["RAW"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "RESULT")) {
         if (!empty($attrs["DUPLICATE"])) {
             $this->m_duplicate = (bool) $attrs["DUPLICATE"];
         }
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "ICC")) {
         $this->m_iccType = $attrs["TYPE"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "ICC", "ICCTAG")) {
         $this->m_iccTags[] = new ICCTag($attrs["TAGID"], null);
         if (!empty($attrs["TYPE"])) {
             $this->m_iccTags[count($this->m_iccTags) - 1]->setType(ICCTagValueType::parse($attrs["TYPE"]));
         }
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "EXPIRYDATE")) {
         $this->m_expiryDateFormat = $attrs["FORMAT"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "CARDDETAILS", "STARTDATE")) {
         $this->m_startDateFormat = $attrs["FORMAT"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "ICCPUBLICKEYS")) {
         $this->m_iccPublicKeyType = $attrs["TYPE"];
         $this->m_iccPublicKeyContent = $attrs["CONTENT"];
         $this->m_iccPublicKeyClearExisting = (bool) $attrs["CLEAREXISTING"];
         $this->m_iccPublicKeyReplaceExisting = (bool) $attrs["REPLACEEXISTING"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "ICCPUBLICKEYS", "CERTIFICATIONAUTHORITY")) {
         $this->m_iccCertificationAuthorities[] = new CertificationAuthority($attrs["DESCRIPTION"], $attrs["RID"]);
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "ICCPUBLICKEYS", "CERTIFICATIONAUTHORITY", "PUBLICKEY")) {
         $this->m_iccCertificationAuthorities[count($this->m_iccCertificationAuthorities) - 1]->addPublicKey(new PublicKey($attrs["INDEX"], $attrs["HASH"], $attrs["HASHALGORITHM"]));
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "ICCPUBLICKEYS", "CERTIFICATIONAUTHORITY", "PUBLICKEY", "VALIDFROM")) {
         $publicKeys = $this->m_iccCertificationAuthorities[count($this->m_iccCertificationAuthorities) - 1]->getPublicKeys();
         $publicKeys[count($publicKeys) - 1]->setValidFromDateFormat($attrs["FORMAT"]);
         $this->m_iccCertificationAuthorities[count($this->m_iccCertificationAuthorities) - 1]->setPublicKeys($publicKeys);
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "ICCPUBLICKEYS", "CERTIFICATIONAUTHORITY", "PUBLICKEY", "VALIDTO")) {
         $publicKeys = $this->m_iccCertificationAuthorities[count($this->m_iccCertificationAuthorities) - 1]->getPublicKeys();
         $publicKeys[count($publicKeys) - 1]->setValidToDateFormat($attrs["FORMAT"]);
         $this->m_iccCertificationAuthorities[count($this->m_iccCertificationAuthorities) - 1]->setPublicKeys($publicKeys);
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "RESULT", "ERRORS", "ERROR")) {
         $this->m_lastErrorCode = ErrorCode::parse($attrs["CODE"]);
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "TRANSACTIONDETAILS", "GEOIP")) {
         if (!empty($attrs["IsBlackListed"])) {
             $this->m_originatingIPAddressIsBlackListed = (bool) $attrs["IsBlackListed"];
         }
         if (!empty($attrs["IsKnownProxy"])) {
             $this->m_originatingIPAddressIsKnownProxy = (bool) $attrs["IsKnownProxy"];
         }
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "TRANSACTIONDETAILS", "GEOIP", "CONTINENT")) {
         $this->m_originatingIPAddressContinentAlpha2 = $attrs["ALPHA2"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "TRANSACTIONDETAILS", "GEOIP", "COUNTRY")) {
         $this->m_originatingIPAddressCountryAlpha2 = $attrs["ALPHA2"];
         $this->m_originatingIPAddressCountryCode = $attrs["CODE"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "TRANSACTIONDETAILS", "GEOIP", "REGION")) {
         $this->m_originatingIPAddressRegionCode = $attrs["CODE"];
         return;
     }
     if ($this->m_tagStack === array("RESPONSE", "TRANSACTIONDETAILS", "LOCALDATETIME")) {
         $this->m_localDateTimeFormat = $attrs["FORMAT"];
         return;
     }
     /*
     		echo "<pre>";
     		echo print_r($this->m_tagStack, true);
     		echo print_r($attrs, true);
     		echo "</pre>";
     */
     //		trigger_error("CardEaseXMLResponse: Unexpected response attrs: ".print_r($attrs, true), E_USER_WARNING);
     //		trigger_error("CardEaseXMLResponse: Unexpected response attrs: ".print_r($this->m_tagStack, true), E_USER_ERROR);
 }