$database_bibleactions = Database_BibleActions::getInstance(); $database_users = Database_Users::getInstance(); $database_books = Database_Books::getInstance(); $address = $database_config_general->getServerAddress(); $url = "{$address}/sync/bibles.php"; $users = $database_users->getUsers(); $user = $users[0]; $hash = $database_users->getmd5($user); // Calculate the total checksum of all chapters in all books in all local Bibles. // Send the credentials to the server, // to enable the server to calculate a similar checksum for all Bibles on the server // that the client username has access to via its credentials. // The client compares the two checksums. // If they match, it means everything is in sync. $bibles = $database_bibles->getBibles(); $client_checksum = Checksum_Logic::getBibles($bibles); $post = array("u" => bin2hex($user), "p" => $hash, "a" => "total"); $server_checksum = Sync_Logic::post($post, $url); if ($server_checksum === false) { $database_logs->log(Locale_Translate::_("Failure getting Bibles checksum"), Filter_Roles::TRANSLATOR_LEVEL); die; } if ($client_checksum == $server_checksum) { $database_logs->log(Locale_Translate::_("The Bibles are up to date"), Filter_Roles::TRANSLATOR_LEVEL); die; } // Send the user credentials to the server and request the Bibles. // The server responds with the Bibles this user has access to. // The client stores this list for later use. $post = array("u" => bin2hex($user), "p" => $hash, "a" => "bibles"); $server_bibles = Sync_Logic::post($post, $url);
// and returns this checksum to the client. $user_ok = $database_users->usernameExists($username); if (!$user_ok) { $database_logs->log("Non existing user {$username}", Filter_Roles::MANAGER_LEVEL); } $pass_ok = $password == $database_users->getmd5($username); if (!$pass_ok) { $database_logs->log("Incorrect password {$password} for user {$username}", Filter_Roles::MANAGER_LEVEL); } if (!$user_ok || !$pass_ok) { // Unauthorized. http_response_code(401); die; } $bibles = Access_Bible::bibles($username); $server_checksum = Checksum_Logic::getBibles($bibles); echo $server_checksum; } else { if ($action == "bibles") { // The server reads the credentials from the client's user, // and responds with a list of Bibles this user has access to. if ($password != $database_users->getmd5($username)) { // Unauthorized. http_response_code(401); die; } $bibles = Access_Bible::bibles($username); $bibles = implode("\n", $bibles); $checksum = Checksum_Logic::get($bibles); echo "{$checksum}\n{$bibles}"; } else {
public function testGetBibles2() { $checksum = Checksum_Logic::getBibles(array("phpunit3", "phpunit4")); $this->assertEquals("020eb29b524d7ba672d9d48bc72db455", $checksum); }