static function admin_dropbox_settings($admin) { $config = Config::current(); if (!Visitor::current()->group->can("change_settings")) { show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings.")); } if (empty($_POST)) { return $admin->display("dropbox_settings"); } if (!isset($_POST['hash']) or $_POST['hash'] != $config->secure_hashkey) { show_403(__("Access Denied"), __("Invalid security key.")); } if (isset($_POST['authorize'])) { $data = json_decode(file_get_contents("http://chyrp.net/api/1/dropboxsync.php?keys"), true); $app_key = $data["key"]; $app_secret = $data["secret"]; $callback = url("/admin/?action=dropbox_oauth"); try { $storage = new \Dropbox\OAuth\Storage\Session(); // if (!$storage->get("access_token")) $storage->delete(); $OAuth = new \Dropbox\OAuth\Consumer\Curl($app_key, $app_secret, $storage, $callback); # Build authorize URL and redirect to Dropbox redirect($OAuth->getAuthoriseURL()); } catch (\Dropbox\Exception $e) { error(__("Dropbox Sync Error!", "dropbox"), $e->getMessage()); } } }
echo 'Access token deleted. Continuing setup.' . PHP_EOL; } } } while (empty($consumerKey)) { echo 'Please enter your consumer key: '; $consumerKey = trim(fgets(STDIN)); } while (empty($consumerSecret)) { echo 'Please enter your consumer secret: '; $consumerSecret = trim(fgets(STDIN)); } try { // Set up the OAuth consumer $storage = new \Dropbox\OAuth\Storage\Session(); $OAuth = new \Dropbox\OAuth\Consumer\Curl($consumerKey, $consumerSecret, $storage); // Generate the authorisation URL and prompt user echo "Generating Authorisation URL...\r\n\r\n"; echo "===== Begin Authorisation URL =====\r\n"; echo $OAuth->getAuthoriseUrl() . PHP_EOL; echo "===== End Authorisation URL =====\r\n\r\n"; echo "Visit the URL above and allow the SDK to connect to your account\r\n"; echo "Press any key once you have completed this step..."; fgets(STDIN); // Acquire the access token echo "Acquiring access token...\r\n"; $OAuth->getAccessToken(); $token = serialize(array('token' => $storage->get('access_token'), 'consumerKey' => $consumerKey, 'consumerSecret' => $consumerSecret)); // Write the access token to disk if (@file_put_contents('oauth.token', $token) === false) { throw new \Dropbox\Exception('Unable to write token to file');