Exemplo n.º 1
0
    /**
     * @param $jobid
     */
    public function edit_tab($jobid)
    {
        if (!empty($_GET['deleteauth'])) {
            //disable token on dropbox
            try {
                $dropbox = new BackWPup_Destination_Dropbox_API(BackWPup_Option::get($jobid, 'dropboxroot'));
                if (BackWPup_Option::get($jobid, 'dropboxsecret')) {
                    $dropbox->setOAuthTokens(array('access_token' => BackWPup_Option::get($jobid, 'dropboxtoken'), 'oauth_token_secret' => BackWPup_Encryption::decrypt(BackWPup_Option::get($jobid, 'dropboxsecret'))));
                } else {
                    $dropbox->setOAuthTokens(BackWPup_Option::get($jobid, 'dropboxtoken'));
                }
                $dropbox->disable_access_token();
            } catch (Exception $e) {
                echo '<div id="message" class="error"><p>' . sprintf(__('Dropbox API: %s', 'backwpup'), $e->getMessage()) . '</p></div>';
            }
            BackWPup_Option::update($jobid, 'dropboxtoken', array());
            BackWPup_Option::update($jobid, 'dropboxroot', 'sandbox');
            BackWPup_Option::delete($jobid, 'dropboxsecret');
        }
        $dropbox = new BackWPup_Destination_Dropbox_API('dropbox');
        $dropbox_auth_url = $dropbox->oAuthAuthorize();
        $dropbox = new BackWPup_Destination_Dropbox_API('sandbox');
        $sandbox_auth_url = $dropbox->oAuthAuthorize();
        $dropboxtoken = BackWPup_Option::get($jobid, 'dropboxtoken');
        ?>

		<h3 class="title"><?php 
        esc_html_e('Login', 'backwpup');
        ?>
</h3>
		<p></p>
		<table class="form-table">
			<tr>
				<th scope="row"><?php 
        esc_html_e('Authentication', 'backwpup');
        ?>
</th>
				<td><?php 
        if (empty($dropboxtoken['access_token'])) {
            ?>
						<span style="color:red;"><?php 
            esc_html_e('Not authenticated!', 'backwpup');
            ?>
</span><br/>&nbsp;<br/>
						<a class="button secondary"
						   href="http://db.tt/8irM1vQ0"><?php 
            esc_html_e('Create Account', 'backwpup');
            ?>
</a>
					<?php 
        } else {
            ?>
						<span style="color:green;"><?php 
            esc_html_e('Authenticated!', 'backwpup');
            ?>
</span><br/>&nbsp;<br/>
						<a class="button secondary"
						   href="<?php 
            echo wp_nonce_url(network_admin_url('admin.php?page=backwpupeditjob&deleteauth=1&jobid=' . $jobid . '&tab=dest-dropbox'), 'edit-job');
            ?>
"
						   title="<?php 
            esc_html_e('Delete Dropbox Authentication', 'backwpup');
            ?>
"><?php 
            esc_html_e('Delete Dropbox Authentication', 'backwpup');
            ?>
</a>
					<?php 
        }
        ?>
				</td>
			</tr>

			<?php 
        if (empty($dropboxtoken['access_token'])) {
            ?>
				<tr>
					<th scope="row"><label for="id_sandbox_code"><?php 
            esc_html_e('App Access to Dropbox', 'backwpup');
            ?>
</label></th>
					<td>
						<input id="id_sandbox_code" name="sandbox_code" type="text" value="" class="regular-text code" />&nbsp;
						<a class="button secondary" href="<?php 
            echo esc_attr($sandbox_auth_url);
            ?>
" target="_blank"><?php 
            esc_html_e('Get Dropbox App auth code', 'backwpup');
            ?>
</a>
						<p class="description"><?php 
            esc_html_e('A dedicated folder named BackWPup will be created inside of the Apps folder in your Dropbox. BackWPup will get read and write access to that folder only. You can specify a subfolder as your backup destination for this job in the destination field below.', 'backwpup');
            ?>
</p>
					</td>
				</tr>
				<tr>
					<th></th>
					<td><?php 
            esc_html_e('— OR —', 'backwpup');
            ?>
</td>
				</tr>
				<tr>
					<th scope="row"><label for="id_dropbbox_code"><?php 
            esc_html_e('Full Access to Dropbox', 'backwpup');
            ?>
</label></th>
					<td>
						<input id="id_dropbbox_code" name="dropbbox_code" type="text" value="" class="regular-text code" />&nbsp;
						<a class="button secondary" href="<?php 
            echo esc_attr($dropbox_auth_url);
            ?>
" target="_blank"><?php 
            esc_html_e('Get full Dropbox auth code ', 'backwpup');
            ?>
</a>
						<p class="description"><?php 
            esc_html_e('BackWPup will have full read and write access to your entire Dropbox. You can specify your backup destination wherever you want, just be aware that ANY files or folders inside of your Dropbox can be overridden or deleted by BackWPup.', 'backwpup');
            ?>
</p>
					</td>
				</tr>
			<?php 
        }
        ?>
		</table>


		<h3 class="title"><?php 
        esc_html_e('Backup settings', 'backwpup');
        ?>
</h3>
		<p></p>
		<table class="form-table">
			<tr>
				<th scope="row"><label for="iddropboxdir"><?php 
        esc_html_e('Destination Folder', 'backwpup');
        ?>
</label></th>
				<td>
					<input id="iddropboxdir" name="dropboxdir" type="text" value="<?php 
        echo esc_attr(BackWPup_Option::get($jobid, 'dropboxdir'));
        ?>
" class="regular-text" />
					<p class="description">
						<?php 
        esc_attr_e('Specify a subfolder where your backup archives will be stored. If you use the App option from above, this folder will be created inside of Apps/BackWPup. Otherwise it will be created at the root of your Dropbox. Already exisiting folders with the same name will not be overriden.', 'backwpup');
        ?>
					</p>
				</td>
			</tr>
			<tr>
				<th scope="row"><?php 
        esc_html_e('File Deletion', 'backwpup');
        ?>
</th>
				<td>
					<?php 
        if (BackWPup_Option::get($jobid, 'backuptype') === 'archive') {
            ?>
						<label for="iddropboxmaxbackups">
							<input id="iddropboxmaxbackups" name="dropboxmaxbackups" type="number" min="0" step="1" value="<?php 
            echo esc_attr(BackWPup_Option::get($jobid, 'dropboxmaxbackups'));
            ?>
" class="small-text" />
							&nbsp;<?php 
            esc_html_e('Number of files to keep in folder.', 'backwpup');
            ?>
						</label>
					<?php 
        } else {
            ?>
						<label for="iddropboxsyncnodelete">
							<input class="checkbox" value="1" type="checkbox" <?php 
            checked(BackWPup_Option::get($jobid, 'dropboxsyncnodelete'), true);
            ?>
 name="dropboxsyncnodelete" id="iddropboxsyncnodelete" />
							&nbsp;<?php 
            esc_html_e('Do not delete files while syncing to destination!', 'backwpup');
            ?>
						</label>
					<?php 
        }
        ?>
				</td>
			</tr>
		</table>

		<?php 
    }
 /**
  * Authentication over ajax
  */
 public function edit_ajax()
 {
     $_GET['jobid'] = (int) $_GET['jobid'];
     // dropbox auth
     if ($_GET['type'] == 'dropbox') {
         try {
             $dropbox = new BackWPup_Destination_Dropbox_API('dropbox');
             // let the user authorize (user will be redirected)
             $response = $dropbox->oAuthAuthorize(network_admin_url('admin.php') . '?page=backwpupeditjob&jobid=' . $_GET['jobid'] . '&tab=dest-dropbox&_wpnonce=' . wp_create_nonce('edit-job'));
             // save oauth_token_secret
             $auth_data = array('oauth_token' => $response['oauth_token'], 'oauth_token_secret' => $response['oauth_token_secret'], 'type' => 'dropbox');
             set_site_transient('backwpup_dropbox_auth_' . $_GET['jobid'], $auth_data, 3600);
             wp_redirect($response['authurl']);
         } catch (Exception $e) {
             BackWPup_Admin::message(sprintf(__('Dropbox API: %s', 'backwpup'), $e->getMessage()), true);
             wp_redirect(network_admin_url('admin.php') . '?page=backwpupeditjob&jobid=' . $_GET['jobid'] . '&tab=dest-dropbox&_wpnonce=' . wp_create_nonce('edit-job'));
         }
     } elseif ($_GET['type'] == 'sandbox') {
         try {
             $dropbox = new BackWPup_Destination_Dropbox_API('sandbox');
             // let the user authorize (user will be redirected)
             $response = $dropbox->oAuthAuthorize(network_admin_url('admin.php') . '?page=backwpupeditjob&jobid=' . $_GET['jobid'] . '&tab=dest-dropbox&_wpnonce=' . wp_create_nonce('edit-job'));
             // save oauth_token_secret
             $auth_data = array('oauth_token' => $response['oauth_token'], 'oauth_token_secret' => $response['oauth_token_secret'], 'type' => 'sandbox');
             set_site_transient('backwpup_dropbox_auth_' . $_GET['jobid'], $auth_data, 3600);
             wp_redirect($response['authurl']);
         } catch (Exception $e) {
             BackWPup_Admin::message(sprintf(__('Dropbox API: %s', 'backwpup'), $e->getMessage()), true);
             wp_redirect(network_admin_url('admin.php') . '?page=backwpupeditjob&jobid=' . $_GET['jobid'] . '&tab=dest-dropbox&_wpnonce=' . wp_create_nonce('edit-job'));
         }
     }
 }
Exemplo n.º 3
0
    /**
     * @param $jobid
     */
    public function edit_tab($jobid)
    {
        if (!empty($_GET['deleteauth']) && $_GET['deleteauth'] == 1) {
            //disable token on dropbox
            try {
                $dropbox = new BackWPup_Destination_Dropbox_API(BackWPup_Option::get($jobid, 'dropboxroot'));
                if (BackWPup_Option::get($jobid, 'dropboxsecret')) {
                    $dropbox->setOAuthTokens(array('access_token' => BackWPup_Option::get($jobid, 'dropboxtoken'), 'oauth_token_secret' => BackWPup_Encryption::decrypt(BackWPup_Option::get($jobid, 'dropboxsecret'))));
                } else {
                    $dropbox->setOAuthTokens(BackWPup_Option::get($jobid, 'dropboxtoken'));
                }
                $dropbox->disable_access_token();
            } catch (Exception $e) {
                echo '<div id="message" class="error"><p>' . sprintf(__('Dropbox API: %s', 'backwpup'), $e->getMessage()) . '</p></div>';
            }
            BackWPup_Option::update($jobid, 'dropboxtoken', array());
            BackWPup_Option::update($jobid, 'dropboxroot', 'sandbox');
            BackWPup_Option::delete($jobid, 'dropboxsecret');
        }
        $dropbox = new BackWPup_Destination_Dropbox_API('dropbox');
        $dropbox_auth_url = $dropbox->oAuthAuthorize();
        $dropbox = new BackWPup_Destination_Dropbox_API('sandbox');
        $sandbox_auth_url = $dropbox->oAuthAuthorize();
        $dropboxtoken = BackWPup_Option::get($jobid, 'dropboxtoken');
        ?>

    <h3 class="title"><?php 
        _e('Login', 'backwpup');
        ?>
</h3>
    <p></p>
    <table class="form-table">
        <tr>
            <th scope="row"><?php 
        _e('Authentication', 'backwpup');
        ?>
</th>
            <td><?php 
        if (empty($dropboxtoken['access_token'])) {
            ?>
               		<span style="color:red;"><?php 
            _e('Not authenticated!', 'backwpup');
            ?>
</span><br />&nbsp;<br />
					<a class="button secondary" href="http://db.tt/8irM1vQ0"><?php 
            _e('Create Account', 'backwpup');
            ?>
</a>
				<?php 
        } else {
            ?>
                	<span style="color:green;"><?php 
            _e('Authenticated!', 'backwpup');
            ?>
</span><br />&nbsp;<br />
					<a class="button secondary" href="<?php 
            echo network_admin_url('admin.php') . '?page=backwpupeditjob&deleteauth=1&jobid=' . $jobid . '&tab=dest-dropbox&_wpnonce=' . wp_create_nonce('edit-job');
            ?>
" title="<?php 
            _e('Delete Dropbox Authentication', 'backwpup');
            ?>
"><?php 
            _e('Delete Dropbox Authentication', 'backwpup');
            ?>
</a>
				<?php 
        }
        ?>
            </td>
        </tr>

		<?php 
        if (empty($dropboxtoken['access_token'])) {
            ?>
		<tr>
			<th scope="row"><label for="id_sandbox_code"><?php 
            _e('Dropbox App auth code', 'backwpup');
            ?>
</label></th>
			<td>
				<input id="id_sandbox_code" name="sandbox_code" type="text" value="" class="regular-text code help-tip" title="<?php 
            _e('A dedicated folder named after your app is created within the Apps folder of a user\'s Dropbox. Your app gets read and write access to this folder only and users can provide content to your app by moving files into this folder.', 'backwpup');
            ?>
" />&nbsp;
				<a class="button secondary" href="<?php 
            echo $sandbox_auth_url;
            ?>
" target="_blank"><?php 
            _e('Get Dropbox App auth code', 'backwpup');
            ?>
</a>
			</td>
		</tr>
		<tr>
			<th></th>
			<td><?php 
            _e('— OR —', 'backwpup');
            ?>
</td>
		</tr>
		<tr>
			<th scope="row"><label for="id_dropbbox_code"><?php 
            _e('Full Dropbox auth code', 'backwpup');
            ?>
</label></th>
			<td>
				<input id="id_dropbbox_code" name="dropbbox_code" type="text" value="" class="regular-text code help-tip"  title="<?php 
            _e('You get full access to all the files and folders in a user\'s Dropbox.', 'backwpup');
            ?>
" />&nbsp;
				<a class="button secondary" href="<?php 
            echo $dropbox_auth_url;
            ?>
" target="_blank"><?php 
            _e('Get full Dropbox auth code ', 'backwpup');
            ?>
</a>
			</td>
		</tr>
		<?php 
        }
        ?>
    </table>


    <h3 class="title"><?php 
        _e('Backup settings', 'backwpup');
        ?>
</h3>
    <p></p>
    <table class="form-table">
        <tr>
            <th scope="row"><label for="iddropboxdir"><?php 
        _e('Folder in Dropbox', 'backwpup');
        ?>
</label></th>
            <td>
                <input id="iddropboxdir" name="dropboxdir" type="text" value="<?php 
        echo esc_attr(BackWPup_Option::get($jobid, 'dropboxdir'));
        ?>
" class="regular-text" />
            </td>
        </tr>
        <tr>
            <th scope="row"><?php 
        _e('File Deletion', 'backwpup');
        ?>
</th>
            <td>
				<?php 
        if (BackWPup_Option::get($jobid, 'backuptype') == 'archive') {
            ?>
                    <label for="iddropboxmaxbackups"><input id="iddropboxmaxbackups" name="dropboxmaxbackups" title="<?php 
            esc_attr_e('Oldest files will be deleted first. 0 = no deletion', 'backwpup');
            ?>
" type="text" size="3" value="<?php 
            echo esc_attr(BackWPup_Option::get($jobid, 'dropboxmaxbackups'));
            ?>
" class="small-text help-tip" />&nbsp;
					<?php 
            _e('Number of files to keep in folder.', 'backwpup');
            ?>
</label>
					<?php 
        } else {
            ?>
                    <label for="iddropboxsyncnodelete" ><input class="checkbox" value="1"
                           type="checkbox" <?php 
            checked(BackWPup_Option::get($jobid, 'dropboxsyncnodelete'), TRUE);
            ?>
                           name="dropboxsyncnodelete" id="iddropboxsyncnodelete" /> <?php 
            _e('Do not delete files while syncing to destination!', 'backwpup');
            ?>
</label>
					<?php 
        }
        ?>
            </td>
        </tr>
    </table>

	<?php 
    }