Esempio n. 1
0
function handle_dropbox_auth($dropbox)
{
    // first try to load existing access token
    $access_token = load_token("access");
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($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()) {
        // 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();
        store_token($request_token, $request_token['t']);
        die("Authentication required. <a href='{$auth_url}'>Click here.</a>");
    }
}
Esempio n. 2
0
 /**
  * 注销
  * @method logout
  * @return 重定向
  */
 public function logout()
 {
     $token = cookie('token');
     if ($token) {
         delete_token($token);
     }
     cookie(null);
     session(null);
     session('[destroy]');
     redirect(C('BASE_URL'));
 }
Esempio n. 3
0
function handle_dropbox_auth($dropbox)
{
    // first try to load existing access token
    $access_token = load_token("access");
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($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()) {
        $dropb_autho = "yes";
        update_option('dropb_autho', $dropb_autho);
        echo '<h3>Dropbox Account Details</h3>';
        $account_info = $dropbox->GetAccountInfo();
        $used = round(($account_info->quota_info->quota - ($account_info->quota_info->normal + $account_info->quota_info->shared)) / 1073741824, 1);
        $quota = round($account_info->quota_info->quota / 1073741824, 1);
        echo $account_info->display_name . ', ' . 'you have' . ' ' . $used . 'GB' . 'of' . ' ' . $quota . 'GB (' . round($used / $quota * 100, 0) . '%) ' . 'free';
        echo '</br><p>Unlink Account for local backups</p></br>';
        echo '<td><a href="' . site_url() . '/wp-admin/tools.php?page=wp-database-backup&action=unlink" class="btn btn-primary">Unlink Account<a/>';
    } else {
        $dropb_autho = "no";
        update_option('dropb_autho', $dropb_autho);
        // redirect user to dropbox oauth page
        $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?page=wp-database-backup&auth_callback=1";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        ?>
    <style>
    #adminmenuwrap {
        padding-bottom: 838px;
    }
</style>
    <h3>Dropbox</h3>
    <p>Define an Dropbox destination connection.</p>
    <p>In order to use Dropbox destination you will need to authorized it with your Dropbox account</p>
    <p>Please click the authorize button below and follow the instructions inside the pop up window</p>
    <p>For local backup leave the setting as it is</p>
          <p>
    <form action="" method="get">
        <a href="<?php 
        echo $auth_url;
        ?>
"><input type="button" name="authorize" id="authorize" value="Authorize"
               class="btn btn-primary" /></a><br/>
         </form>
    </p>
    <?php 
        die;
        //die("Authentication required".$auth_url);
    }
}
Esempio n. 4
0
// 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()) {
    // 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();
    store_token($request_token, $request_token['t']);
    die("Authentication required. <a href='{$auth_url}'>Click here.</a>");
}
echo "<pre>";
echo "<b>Account:</b>\r\n";
print_r($dropbox->GetAccountInfo());
$files = $dropbox->GetFiles("", false);
if (empty($files)) {
Esempio n. 5
0
function merge_tokens_ii($id_array)
{
    //ii stands for "id insensitive"
    if (sizeof($id_array) < 2) {
        throw new UnexpectedValueException();
    }
    check_permission(PERM_ADDER);
    $id_array = array_map('intval', $id_array);
    foreach ($id_array as $tid) {
        if (is_token_covered_by_ne_markup($tid)) {
            throw new Exception("Cannot change tokens under NE markup");
        }
    }
    $joined = join(',', $id_array);
    //check if they are all in the same sentence
    $res = sql_query("SELECT distinct sent_id FROM tokens WHERE tf_id IN({$joined})");
    if (sql_num_rows($res) > 1) {
        throw new Exception();
    }
    $r = sql_fetch_array($res);
    $sent_id = $r['sent_id'];
    //check if they all stand in a row
    $r = sql_fetch_array(sql_query("SELECT MIN(pos) AS minpos, MAX(pos) AS maxpos FROM tokens WHERE tf_id IN({$joined})"));
    $res = sql_query("SELECT tf_id FROM tokens WHERE sent_id={$sent_id} AND pos > " . $r['minpos'] . " AND pos < " . $r['maxpos'] . " AND tf_id NOT IN ({$joined}) LIMIT 1");
    if (sql_num_rows($res) > 0) {
        throw new Exception();
    }
    //assemble new token, delete others from form2tf and tokens, update tf_id in their revisions
    $res = sql_query("SELECT tf_id, tf_text FROM tokens WHERE tf_id IN ({$joined}) ORDER BY pos");
    $r = sql_fetch_array($res);
    $new_id = $r['tf_id'];
    $new_text = $r['tf_text'];
    sql_begin();
    while ($r = sql_fetch_array($res)) {
        $new_text .= $r['tf_text'];
        sql_query("UPDATE tf_revisions SET tf_id={$new_id} WHERE tf_id=" . $r['tf_id']);
        delete_token($r['tf_id'], false);
    }
    //update tf_text, add new revision
    $revset_id = create_revset("Tokens {$joined} merged to <{$new_text}>");
    $token_for_form2tf = str_replace('ё', 'е', mb_strtolower($new_text));
    sql_pe("UPDATE tokens SET tf_text = ? WHERE tf_id=? LIMIT 1", array($new_text, $new_id));
    sql_pe("INSERT INTO form2tf VALUES(?, ?)", array($token_for_form2tf, $new_id));
    $parse = new MorphParseSet(false, $new_text);
    create_tf_revision($revset_id, $new_id, $parse->to_xml());
    //drop sentence status
    sql_query("UPDATE sentences SET check_status='0' WHERE sent_id={$sent_id} LIMIT 1");
    sql_query("DELETE FROM sentence_check WHERE sent_id={$sent_id}");
    sql_commit();
}
Esempio n. 6
0
 /**
  * 注销
  */
 public function logout()
 {
     delete_token(cookie('token'));
     session(null);
     cookie(null);
     $this->redirect('Printer/Index/index');
 }
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;
    }
}
function handle_dropbox_auth($dropbox, $option)
{
    // first try to load existing access token
    $access_token = load_token($option['access_token']);
    if (!empty($access_token)) {
        $dropbox->SetAccessToken($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, $option['access_token']);
        delete_token($_GET['oauth_token']);
    }
    // checks if access token is required
    if (!$dropbox->IsAuthorized()) {
        ?>
		<img src="logo.png" class="dropbox">
		<?php 
        // redirect user to dropbox auth page
        $return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1&check=10&config=30";
        $auth_url = $dropbox->BuildAuthorizeUrl($return_url);
        $request_token = $dropbox->GetRequestToken();
        store_token($request_token, $request_token['t']);
        die("Authentication required. <a onclick=window.open('{$auth_url}','popUpWindow','height=400,width=600,left=10,top=10,,scrollbars=yes,menubar=no') return false;>Click here.</a>");
    }
}