Esempio n. 1
0
         die;
     } catch (Exception $e) {
         die($e->getMessage());
     }
     break;
 case 'downloadsugarsync':
     //Download Dropbox Backup
     check_admin_referer('download-backup');
     if (!class_exists('SugarSync')) {
         require_once realpath(dirname(__FILE__) . '/../libs/sugarsync.php');
     }
     $jobs = get_option('backwpup_jobs');
     $jobid = $_GET['jobid'];
     try {
         $sugarsync = new SugarSync($jobs[$jobid]['sugarrefreshtoken']);
         $response = $sugarsync->get(urldecode($_GET['file']));
         header("Pragma: public");
         header("Expires: 0");
         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
         header("Content-Type: " . (string) $response->mediaType);
         header("Content-Type: application/force-download");
         header("Content-Type: application/octet-stream");
         header("Content-Type: application/download");
         header("Content-Disposition: attachment; filename=" . (string) $response->displayName . ";");
         header("Content-Transfer-Encoding: binary");
         header("Content-Length: " . (int) $response->size);
         echo $sugarsync->download(urldecode($_GET['file']));
         die;
     } catch (Exception $e) {
         die($e->getMessage());
     }
Esempio n. 2
0
function backwpup_get_sugarsync_root($args = '')
{
    if (is_array($args)) {
        extract($args);
        $ajax = false;
    } else {
        check_ajax_referer('backwpupeditjob_ajax_nonce');
        if (!current_user_can(BACKWPUP_USER_CAPABILITY)) {
            die('-1');
        }
        $sugaruser = $_POST['sugaruser'];
        $sugarpass = $_POST['sugarpass'];
        $sugarrootselected = $_POST['sugarrootselected'];
        $ajax = true;
    }
    if (!class_exists('SugarSync')) {
        require_once dirname(__FILE__) . '/../libs/sugarsync.php';
    }
    if (empty($sugaruser)) {
        echo '<span id="sugarroot" style="color:red;">' . __('Missing Username!', 'backwpup') . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    if (empty($sugarpass)) {
        echo '<span id="sugarroot" style="color:red;">' . __('Missing Password!', 'backwpup') . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    try {
        $sugarsync = new SugarSync($sugaruser, $sugarpass);
        $user = $sugarsync->user();
        $syncfolders = $sugarsync->get($user->syncfolders);
    } catch (Exception $e) {
        echo '<span id="sugarroot" style="color:red;">' . $e->getMessage() . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    if (!is_object($syncfolders)) {
        echo '<span id="sugarroot" style="color:red;">' . __('No Syncfolders found!', 'backwpup') . '</span>';
        if ($ajax) {
            die;
        } else {
            return;
        }
    }
    echo '<select name="sugarroot" id="sugarroot">';
    foreach ($syncfolders->collection as $roots) {
        echo "<option " . selected(strtolower($sugarrootselected), strtolower($roots->ref), false) . " value=\"" . $roots->ref . "\">" . $roots->displayName . "</option>";
    }
    echo '</select>';
    if ($ajax) {
        die;
    } else {
        return;
    }
}