function setDropbox() { error_reporting(E_ALL); $this->enable_implicit_flush(); // -- end of unneeded stuff // if there are many files in your Dropbox it can take some time, so disable the max. execution time set_time_limit(0); $dbx = new DropboxClient(array('app_key' => "fv1z1w4yn5039ys", 'app_secret' => "jyzrgispic9cabg", 'app_full_access' => true), 'en'); $access_token = $this->load_token("access"); if (!empty($access_token)) { $dbx->SetAccessToken($access_token); // echo "loaded access token:"; // print_r($access_token); } elseif (!empty($_GET['auth_callback'])) { // then load our previosly created request token $request_token = $this->load_token($_GET['oauth_token']); if (empty($request_token)) { die('Request token not found!'); } // get & store access token, the request token is not needed anymore $access_token = $dbx->GetAccessToken($request_token); $this->store_token($access_token, "access"); $this->delete_token($_GET['oauth_token']); } // checks if access token is required if (!$dbx->IsAuthorized()) { // redirect user to dbx auth page $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1"; $auth_url = $dbx->BuildAuthorizeUrl($return_url); $request_token = $dbx->GetRequestToken(); $this->store_token($request_token, $request_token['t']); die("Authentication required. <a href='{$auth_url}'>Click here.</a>"); } return $dbx; }
/** * @param mixed $dbxObj */ public function setDbxObj($token) { error_reporting(E_ALL); $this->enable_implicit_flush(); // -- end of unneeded stuff // if there are many files in your Dropbox it can take some time, so disable the max. execution time set_time_limit(0); $dbx = new \DropboxClient(array('app_key' => $this->APP_KEY, 'app_secret' => $this->APP_SECRET, 'app_full_access' => $this->APP_FULL_ACCESS), 'en'); // $q = \App\Token::where('user_id',1)->get()[0]->access_token; // $access_token = \GuzzleHttp\json_decode($q,true); if (!empty($token)) { $dbx->SetAccessToken((array) \GuzzleHttp\json_decode($token->access_token)); // echo "loaded access token:"; // print_r($access_token); } elseif (!empty($_GET['auth_callback'])) { // then load our previosly created request token $request_token = $this->load_token("request_temp"); if (empty($request_token)) { die('Request token not found!'); } // get & store access token, the request token is not needed anymore $access_token = $dbx->GetAccessToken($request_token); $this->setToken($access_token); // $this->store_token($access_token, "access"); $this->delete_token("request_temp"); } // checks if access token is required if (!$dbx->IsAuthorized()) { // redirect user to dbx auth page // $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1"; $auth_url = $dbx->BuildAuthorizeUrl($this->return_url); $request_token = $dbx->GetRequestToken(); $this->store_token($request_token, "request_temp"); // die(redirect($auth_url)); header("Location: {$auth_url}"); exit; } return $dbx; }
* @license See license.txt * */ // these 2 lines are just to enable error reporting and disable output buffering (don't include this in you application!) error_reporting(E_ALL); enable_implicit_flush(); // -- end of unneeded stuff // if there are many files in your Dropbox it can take some time, so disable the max. execution time set_time_limit(0); require_once "DropboxClient.php"; // you have to create an app at https://www.dropbox.com/developers/apps and enter details below: $dropbox = new DropboxClient(array('app_key' => "h9wy5qfiytli7b3", 'app_secret' => "21xqna3r57yqmmk", 'app_full_access' => false), 'en'); // first try to load existing access token $access_token = load_token("access"); if (!empty($access_token)) { $dropbox->SetAccessToken($access_token); echo "loaded access token:"; print_r($access_token); } elseif (!empty($_GET['auth_callback'])) { // then load our previosly created request token $request_token = load_token($_GET['oauth_token']); if (empty($request_token)) { die('Request token not found!'); } // get & store access token, the request token is not needed anymore $access_token = $dropbox->GetAccessToken($request_token); store_token($access_token, "access"); delete_token($_GET['oauth_token']); } // checks if access token is required if (!$dropbox->IsAuthorized()) {
function authorize_dropbox() { global $_CONFIG; include_once "classes/DropboxClient.php"; $access_token = load_token("access"); if ($_CONFIG["cron_dropbox_active"]) { $dropbox = new DropboxClient(array('app_key' => $_CONFIG['cron_dropbox_Key'], 'app_secret' => $_CONFIG['cron_dropbox_Secret'], 'app_full_access' => false), 'en'); if (!empty($access_token)) { $dropbox->SetAccessToken($access_token); } if ($dropbox->IsAuthorized()) { echo "<center><h2>Dropbox Connection Authorized!</h2></center>"; return; } } else { return; } if ($_CONFIG["cron_dropbox_active"] and !empty($_GET['auth_callback'])) { // then load our previosly created request token $request_token = load_token($_GET['oauth_token']); if (empty($request_token)) { die('Request token not found!'); } // get & store access token, the request token is not needed anymore $access_token = $dropbox->GetAccessToken($request_token); store_token($access_token, "access"); delete_token($_GET['oauth_token']); echo "<center><h2>Dropbox Connection Authorized!</h2></center>"; return; } if (empty($access_token) and $_CONFIG["cron_dropbox_active"]) { //$dropbox->SetAccessToken($access_token); //print_r($access_token); $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . "&auth_callback=1"; $auth_url = $dropbox->BuildAuthorizeUrl($return_url); $request_token = $dropbox->GetRequestToken(); store_token($request_token, $request_token['t']); ?> <script> window.location="<?php echo $auth_url; ?> " </script> <?php exit; } }
public function indexAction() { // delete coupon expire // $coupon = Utility::deleteExpireCoupon(); $appKey = 'rqvezrg3abysf3x'; $appSecret = 'uoye0pmyap6fuoy'; $service_locator_str = 'doctrine.connection.orm_default'; $sm = $this->getServiceLocator(); $service = $sm->get($service_locator_str); $params = $service->getParams(); $host = $params['host']; $user = $params['user']; $pass = $params['password']; $name = $params['dbname']; $tables = "*"; $return = ''; $link = mysql_connect($host, $user, $pass); if ($link) { mysql_select_db($name, $link); //get all of the tables if ($tables == '*') { $tables = array(); $result = mysql_query('SHOW TABLES'); while ($row = mysql_fetch_row($result)) { $tables[] = $row[0]; } } else { $tables = is_array($tables) ? $tables : explode(',', $tables); } //cycle through foreach ($tables as $table) { $result = mysql_query('SELECT * FROM ' . $table); $num_fields = mysql_num_fields($result); $return .= 'DROP TABLE ' . $table . ';'; $row2 = mysql_fetch_row(mysql_query('SHOW CREATE TABLE ' . $table)); $return .= "\n\n" . $row2[1] . ";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while ($row = mysql_fetch_row($result)) { $return .= 'INSERT INTO ' . $table . ' VALUES('; for ($j = 0; $j < $num_fields; $j++) { $row[$j] = addslashes($row[$j]); $row[$j] = ereg_replace("\n", "\\n", $row[$j]); if (isset($row[$j])) { $return .= '"' . $row[$j] . '"'; } else { $return .= '""'; } if ($j < $num_fields - 1) { $return .= ','; } } $return .= ");\n"; } } $return .= "\n\n\n"; } $files = glob('public\\backup\\*'); // get all file names foreach ($files as $file) { // iterate files if (is_file($file)) { unlink($file); } // delete file } $directoryBk = 'public/backup/'; $backupName = 'backup-' . time() . '-' . date("d", time()) . '-' . date('m', time()) . '-' . date('Y', time()) . '.sql'; //save file $handle = fopen($directoryBk . $backupName, "w+"); // write file fwrite($handle, $return); // close file fclose($handle); DropboxUtility::enable_implicit_flush(); $dropbox = new \DropboxClient(array('app_key' => $appKey, 'app_secret' => $appSecret, 'app_full_access' => false), 'en'); $accessToken = "AD4_9TIkfjoAAAAAAAA0jFsQImeJnIyvWDrjBa_ND7vP5YjuZFNMbS7jMdvwhCem"; $accessToken = DropboxUtility::load_token('access'); if (!empty($accessToken)) { $dropbox->SetAccessToken($accessToken); } elseif (!empty($_GET['auth_callback'])) { $requestToken = DropboxUtility::load_token($_GET['oauth_token']); if (empty($requestToken)) { die('Request token not found!'); } // get & store access token, the request token is not needed anymore $accessToken = $dropbox->GetAccessToken($requestToken); DropboxUtility::store_token($accessToken, "access"); DropboxUtility::delete_token($_GET['oauth_token']); } if (!$dropbox->IsAuthorized()) { // redirect user to dropbox auth page $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1"; $auth_url = $dropbox->BuildAuthorizeUrl($return_url); $request_token = $dropbox->GetRequestToken(); DropboxUtility::store_token($request_token, $request_token['t']); die("Authentication required. <a href='{$auth_url}'>Click here.</a>"); } else { $fileUpload = $dropbox->UploadFile($directoryBk . $backupName); print_r($fileUpload); } // send mail $sendMail = MailUtility::sendMailAttachment($directoryBk . $backupName, $backupName, 'Kaffa DB', '*****@*****.**', true); die('Backup success!'); } else { die(mysql_error()); } }