Пример #1
0
 /**
  * @brief Function for writing output
  *
  * Srray will be encoded to json format and written,
  * other type of arguments will be simple written to browser,
  *
  * @param any $output
  */
 public static function write($output)
 {
     // write simple output
     if (gettype($output) != 'array') {
         self::writeOutput($output);
     } else {
         if (OutputData::getOutputFormat() == self::NewLineFormat) {
             self::writeNewLineFormat($output);
         } else {
             self::writeLengthFormat($output);
         }
     }
 }
Пример #2
0
 /**
  * @brief Function for writing output.
  *
  * Arrays will be encoded to JSON or other formats depending on the
  * Content-Type header sent by the client.
  *
  * @param any $output The output sent back to the client.
  * @param number $modifiedTime Modified time which will be sent back to the
  * client as a HTTP header. By default the current time is sent.
  */
 public static function write($output, $modifiedTime = null)
 {
     // If no modified time is set get a timestamp now, then send the header
     Utils::sendMozillaTimestampHeader($modifiedTime);
     // Write simple output
     if (gettype($output) != 'array') {
         self::writeOutput($output);
     } else {
         switch (OutputData::getOutputFormat()) {
             case self::NewlinesFormat:
                 self::writeNewlinesFormat($output);
                 break;
             case self::LengthFormat:
                 self::writeLengthFormat($output);
                 break;
             case self::JsonFormat:
                 self::writeJsonFormat($output);
                 break;
         }
     }
 }
Пример #3
0
 /**
  *  @brief Delete a Mozilla Sync user.
  *
  *  DELETE https://server/pathname/version/username
  *
  *  Deletes the user account.
  *  NOTE: Requires simple authentication with the username and password associated with the account.
  *
  *  Return value:
  *  0 on success
  *
  *  Possible errors:
  *    503: there was an error removing the user
  *    404: the user does not exist in the database
  *    401: authentication failed
  *
  *  @param string $syncHash Mozilla Sync user hash of the user to be deleted.
  */
 private function deleteUser($syncHash)
 {
     if (User::isAutoCreateUser()) {
         //auto create accounts only
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         Utils::writeLog("Failed to delete user " . $syncHash . ". Delete disabled");
     }
     if (User::syncUserExists($syncHash) === false) {
         Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
         Utils::writeLog("Failed to delete user " . $syncHash . ". User does not exist.");
     }
     if (User::authenticateUser($syncHash) === false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         Utils::writeLog("Authentication for deleting user " . $syncHash . " failed.");
     }
     $syncId = User::syncHashToSyncId($syncHash);
     if ($syncId === false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         Utils::writeLog("Failed to convert user " . $syncHash . " to Sync ID.");
     }
     if (Storage::deleteStorage($syncId) === false) {
         Utils::changeHttpStatus(Utils::STATUS_MAINTENANCE);
         Utils::writeLog("Failed to delete storage for user " . $syncId . ".");
     }
     if (User::deleteUser($syncId) === false) {
         Utils::changeHttpStatus(Utils::STATUS_MAINTENANCE);
         Utils::writeLog("Failed to delete user " . $syncId . ".");
     }
     OutputData::write('0');
 }
Пример #4
0
 /**
  * @brief Change Http response code and send additional Mozilla sync status code
  *
  * @param integer $httpStatusCode
  * @param integer $syncErrorCode
  */
 public static function sendError($httpStatusCode, $syncErrorCode)
 {
     self::changeHttpStatus($httpStatusCode);
     OutputData::write($syncErrorCode);
 }
Пример #5
0
 /**
  * @brief Deletes all records for the user
  *
  * HTTP request: DELETE https://server/pathname/version/username/storage
  *
  * Will return a precondition error unless an X-Confirm-Delete header is included.
  *
  * All delete requests return the timestamp of the action.
  *
  * @param integer $userId
  * @return bool true if success
  */
 private function deleteStorage($userId)
 {
     if (!isset($_SERVER['HTTP_X_CONFIRM_DELETE'])) {
         return false;
     }
     $result = Storage::deleteStorage($userId);
     if ($result == false) {
         return false;
     }
     OutputData::write(Utils::getMozillaTimestamp());
     return true;
 }
Пример #6
0
 /**
  *  @brief Change password
  *
  *  POST https://server/pathname/version/username/password
  *
  *  Changes the password associated with the account to the value specified in the POST body.
  *
  *  NOTE: Requires basic authentication with the username and (current) password associated with the account.
  *  The auth username must match the username in the path.
  *
  *  Alternately, a valid X-Weave-Password-Reset header can be used, if it contains a code previously obtained from the server.
  *
  *  Return values: “success” on success.
  *
  *  Possible errors:
  *    400: 7 (Missing password field)
  *    400: 10 (Invalid or missing password reset code)
  *    400: 9 (Requested password not strong enough)
  *    404: the user does not exists in the database
  *    503: there was an error updating the password
  *    401: authentication failed
  */
 private function changePassword($syncUserHash, $password)
 {
     OutputData::write('success');
     return true;
 }
Пример #7
0
 /**
  * @brief Deletes all records for the specified user.
  *
  * HTTP request: DELETE https://server/pathname/version/username/storage
  *
  * Will return a precondition error unless an X-Confirm-Delete header is included.
  *
  * All delete requests return the timestamp of the action.
  *
  * @param integer $syncId The Sync user whose records will be deleted.
  * @return bool True on success, false otherwise.
  */
 private function deleteStorage($syncId)
 {
     // Only continue if X-Confirm-Delete header is set
     if (!isset($_SERVER['HTTP_X_CONFIRM_DELETE'])) {
         Utils::writeLog("Did not send X_CONFIRM_DELETE header when trying to delete all records for user " . $syncId . ".");
         return false;
     }
     $result = Storage::deleteStorage($syncId);
     if ($result === false) {
         Utils::writeLog("Failed to delete all records for user " . $syncId . ".");
         return false;
     }
     OutputData::write(Utils::getMozillaTimestamp());
     return true;
 }