Пример #1
0
 public function __construct($action, $settings, $extra)
 {
     require_once '../model/Error.inc.php';
     if ($this->profile) {
         Zotero_DB::profileStart($this->profileShard);
     }
     $this->startTime = microtime(true);
     // Inflate gzipped data
     if (!empty($_SERVER['HTTP_CONTENT_ENCODING']) && $_SERVER['HTTP_CONTENT_ENCODING'] == 'gzip') {
         $gzdata = file_get_contents('php://input');
         // Firefox 12 and above include the standard gzip header,
         // which needs to be stripped
         if (substr($gzdata, 0, 3) == chr(31) . chr(139) . chr(8)) {
             // 1F 8B 08
             $gzdata = substr($gzdata, 10);
         }
         $data = gzinflate($gzdata);
         parse_str($data, $_POST);
         foreach ($_POST as $key => $val) {
             $_REQUEST[$key] = $val;
         }
     }
     $this->responseXML = Zotero_Sync::getResponseXML();
     //if (!Z_CONFIG::$SYNC_ENABLED && $_SERVER["REMOTE_ADDR"] != '') {
     if (!Z_CONFIG::$SYNC_ENABLED) {
         $this->error(503, 'SERVER_ERROR', Z_CONFIG::$MAINTENANCE_MESSAGE);
     }
     if (empty($_REQUEST['version'])) {
         if ($action == 'index') {
             echo "Nothing to see here.";
             exit;
         }
         $this->error(400, 'NO_API_VERSION', "API version not specified");
     }
     $upgradeMessage = "Due to improvements made to sync functionality, you must upgrade to Zotero 2.0 or later (via Firefox's Tools menu -> Add-ons -> Extensions -> Find Updates or from zotero.org) to sync your Zotero library.";
     if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
         require_once '../model/ToolkitVersionComparator.inc.php';
         if ($_SERVER['HTTP_X_ZOTERO_VERSION'] == "2.0b6") {
             die("Please upgrade to Zotero 2.0 via Tools -> Add-ons -> Extensions -> Find Updates or from zotero.org.");
         } else {
             if (preg_match("/2.0b[0-9].SVN/", $_SERVER['HTTP_X_ZOTERO_VERSION'])) {
                 // Can't use version for SVN builds
             } else {
                 if (ToolkitVersionComparator::compare($_SERVER['HTTP_X_ZOTERO_VERSION'], "2.0rc.r5716") < 0) {
                     $this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
                 }
             }
         }
     }
     if (!in_array($_REQUEST['version'], $this->validAPIVersions)) {
         if ($_REQUEST['version'] < 8) {
             $this->error(400, 'UPGRADE_REQUIRED', $upgradeMessage);
         }
         $this->error(400, 'INVALID_API_VERSION', "Invalid request API version '{$_REQUEST['version']}'");
     }
     $this->apiVersion = (int) $_REQUEST['version'];
     $this->responseXML['version'] = $this->apiVersion;
 }
Пример #2
0
 private function handleUpdatedError(Exception $e)
 {
     if ($this->responseXML) {
         unset($this->responseXML->updated);
     } else {
         $this->responseXML = Zotero_Sync::getResponseXML($this->apiVersion);
     }
     $msg = $e->getMessage();
     //if (strpos($msg, "Can't connect to MySQL server on") !== false) {
     //	$this->error(503, 'SERVER_ERROR', "Syncing is currently unavailable for some users due to a server issue. We're working to restore service as soon as possible. Our apologies for the inconvenience.");
     //}
     if (strpos($msg, "Lock wait timeout exceeded; try restarting transaction") !== false || strpos($msg, "Deadlock found when trying to get lock; try restarting transaction") !== false || strpos($msg, "Too many connections") !== false || strpos($msg, "Can't connect to MySQL server") !== false || strpos($msg, " is down") !== false || $e->getCode() == Z_ERROR_SHARD_UNAVAILABLE) {
         $waitTime = $this->getWaitTime($this->sessionID);
         Z_Core::logError("WARNING: {$msg} -- sending sync wait ({$waitTime})");
         $locked = $this->responseXML->addChild('locked');
         $locked['wait'] = $waitTime;
         $this->end();
     }
     if (Z_ENV_TESTING_SITE) {
         throw $e;
     } else {
         $id = substr(md5(uniqid(rand(), true)), 0, 10);
         $str = date("D M j G:i:s T Y") . "\n";
         $str .= "IP address: " . $_SERVER['REMOTE_ADDR'] . "\n";
         if (isset($_SERVER['HTTP_X_ZOTERO_VERSION'])) {
             $str .= "Version: " . $_SERVER['HTTP_X_ZOTERO_VERSION'] . "\n";
         }
         $str .= "Error: " . $e;
         $str .= $this->responseXML->saveXML();
         if (!file_put_contents(Z_CONFIG::$SYNC_ERROR_PATH . $id, $str)) {
             error_log("Unable to save error report to " . Z_CONFIG::$SYNC_ERROR_PATH . $id);
         }
         $this->error(500, 'INVALID_OUTPUT', "Invalid response from server (Report ID: {$id})");
     }
 }