Beispiel #1
1
 /**
  * Class process method wnich is used to execute this component.
  */
 public function process()
 {
     //DROPBOX
     //Request Unlink Dropbox Acount
     if ($this->request()->get('unlink')) {
         Phpfox::getService('backuprestore.dropboxfront')->unlink_account();
         $this->isAccess = null;
         $page = $_SERVER['HTTP_REFERER'];
         $sec = "0";
         header("Refresh: {$sec}; url={$page}");
     }
     $canCall = false;
     if (!$this->request()->get('db_authorize')) {
         $this->dropbox = PhpFox::getService('backuprestore.dropboxfront');
         $canCall = true;
     }
     $dbauthorize = array();
     if ($canCall) {
         $dbauthorize['Url'] = $this->dropbox->get_authorize_url();
         if ($this->dropbox->is_authorized()) {
             //User Dropbox info
             $dbaccount_info = $this->dropbox->get_account_info();
             $dbaccount_details = array('account_owner' => $dbaccount_info->display_name, 'used_space' => round(($dbaccount_info->quota_info->quota - ($dbaccount_info->quota_info->normal + $dbaccount_info->quota_info->shared)) / 1073741824, 1), 'quota' => round($dbaccount_info->quota_info->quota / 1073741824, 1));
             $dbaccount_details['used_percent'] = round($dbaccount_details['used_space'] / $dbaccount_details['quota'] * 100, 0);
             $this->authorized['dropbox'] = 1;
         } else {
             if ($this->request()->get('continue')) {
                 if (!$this->dropbox->is_authorized()) {
                     $dbauthorize['error_not_authorized'] = 'yes';
                 }
                 $dbauthorize['submitbutton'] = 'Authorize';
             }
         }
     }
     //Request Authorize Dropbox Account
     if ($this->request()->get('db_authorize')) {
         $dbauthorize['submitbutton'] = 'Continue';
     }
     $this->template()->assign(array('dbauthorize' => $dbauthorize, 'DBADetails' => !empty($dbaccount_details) ? $dbaccount_details : null, 'authorized' => $this->authorized));
 }
Beispiel #2
1
 private function _import()
 {
     Phpfox::getLib('phpfox.process')->import(Phpfox::getLib('xml.parser')->parse(PHPFOX_DIR_XML . 'version' . PHPFOX_XML_SUFFIX));
     PhpFox::getService('core.country.process')->importForInstall(Phpfox::getLib('xml.parser')->parse(PHPFOX_DIR_XML . 'country' . PHPFOX_XML_SUFFIX));
     // $this->_pass();
     /*
     $this->_oTpl->assign(array(
     	'sMessage' => 'Imports complete...',
     	'sNext' => $this->_step('language')
     ));
     */
     return ['message' => 'Importing language package', 'next' => 'language'];
 }
 public function __construct()
 {
     require_once 'module/backuprestore/Dropbox/API.php';
     require_once 'module/backuprestore/Dropbox/OAuth/Consumer/ConsumerAbstract.class.php';
     require_once 'module/backuprestore/Dropbox/OAuth/Consumer/Curl.class.php';
     $this->btdbsett = PhpFox::getService('backuprestore.backuprestore');
     if (!extension_loaded('curl')) {
         Phpfox_Error::set(Phpfox::getPhrase('testsearch.curl_not_loaded_message'));
     }
     $this->oauth = new Backuprestore_Dropbox_OAuth_Consumer_Curl($this->app_key, $this->app_secret);
     if ($dbarray = $this->btdbsett->getBTDBSettingByName('dropbox_tokens')) {
         $this->tokens = unserialize(array_shift($dbarray));
     }
     //Convert array to stdClass for the new API
     if ($this->tokens && is_array($this->tokens['access'])) {
         $accessToken = new stdClass();
         $accessToken->oauth_token = $this->tokens['access']["token"];
         $accessToken->oauth_token_secret = $this->tokens['access']["token_secret"];
         $this->tokens['access'] = $accessToken;
         $this->tokens['state'] = 'access';
     }
     try {
         $this->init();
         //If we are in the access state and are still not authorized then unlink and re init
         if ($this->tokens['state'] == 'access' && !$this->is_authorized()) {
             throw new Exception();
         }
     } catch (Exception $e) {
         $this->unlink_account();
         $this->init();
     }
 }
Beispiel #4
0
 /**
  * Class process method wnich is used to execute this component.
  */
 public function process()
 {
     //DROPBOX
     $canCall = false;
     if (!$this->request()->get('db_authorize')) {
         $this->dropbox = PhpFox::getService('backuprestore.dropboxfront');
         $canCall = true;
     }
     $dbauthorize = array();
     if ($canCall) {
         $dbauthorize['Url'] = $this->dropbox->get_authorize_url();
         if ($this->dropbox->is_authorized()) {
             //User Dropbox info
             $dbaccount_info = $this->dropbox->get_account_info();
             $dbaccount_details = array('account_owner' => $dbaccount_info->display_name, 'used_space' => round(($dbaccount_info->quota_info->quota - ($dbaccount_info->quota_info->normal + $dbaccount_info->quota_info->shared)) / 1073741824, 1), 'quota' => round($dbaccount_info->quota_info->quota / 1073741824, 1));
             $dbaccount_details['used_percent'] = round($dbaccount_details['used_space'] / $dbaccount_details['quota'] * 100, 0);
             $this->authorized['dropbox'] = 1;
         } else {
             if ($this->request()->get('continue')) {
                 if (!$this->dropbox->is_authorized()) {
                     $dbauthorize['error_not_authorized'] = 'yes';
                 }
                 $dbauthorize['submitbutton'] = 'Authorize';
             }
         }
     }
     //Request Authorize Dropbox Account
     if ($this->request()->get('db_authorize')) {
         $dbauthorize['submitbutton'] = 'Continue';
     }
     //Google DRIVE
     $gdrive = PhpFox::getService('backuprestore.googledrivefront');
     $tokens = $gdrive->getAccessTokens();
     //Check Google drive User Authorization
     if ($gdrive->is_authorized()) {
         //User Google Drive info
         try {
             if (isset($tokens)) {
                 $drive = $gdrive->buildService($tokens);
                 $gdrive_info = $gdrive->getAcountInfo($drive);
                 $this->authorized['gdrive'] = 1;
             }
         } catch (Exception $e) {
             throw $e;
         }
     }
     // Google Drive Authorize
     if ($this->request()->get('gd_authorize')) {
         if (!$gdrive->initClientKeys()) {
             $this->url()->forward($this->url()->makeUrl('admincp.backuprestore.gdrivesett'), 'In order to use Google Drive Service fill below requirements');
         }
         try {
             $gdrive->gdrive_auth_request();
         } catch (Exception $e) {
             Phpfox::addMessage($e->getMessage());
         }
     }
     $this->template()->assign(array('dbauthorize' => $dbauthorize, 'gdrive_info' => !empty($gdrive_info) ? $gdrive_info : null, 'DBADetails' => !empty($dbaccount_details) ? $dbaccount_details : null, 'authorized' => $this->authorized));
 }
Beispiel #5
0
 public function process()
 {
     $this->googledrive = PhpFox::getService('backuprestore.googledrivefront');
     $this->btdbsett = PhpFox::getService('backuprestore.backuprestore');
     //Clients deny for Application Register
     if (isset($_GET['error'])) {
         $this->url()->forward($this->url()->makeUrl('backuprestore.continue'), Phpfox::getPhrase('backuprestore.gd_auth_deny'));
     }
     //Get Access Tokens usung authorization code returnedfrom Google API
     if (isset($_GET['code'])) {
         try {
             $this->tokens['access_token'] = $this->googledrive->exchangeCode($_GET['code']);
             if (!empty($this->tokens['access_token'])) {
                 $this->btdbsett->addBTDBSetting('googledrive_tokens', serialize(json_decode($this->tokens['access_token'], true)));
             }
             //Redirct to main page
             $this->url()->forward($this->url()->makeUrl('admincp.backuprestore.destination'), Phpfox::getPhrase('backuprestore.gd_register_complete'));
         } catch (Exception $e) {
             $e->getMessage();
         }
     }
     //Insert GDrive client keys
     if ($aVals = $this->request()->getArray('val')) {
         if (empty($aVals['gdrive_clientid'])) {
             return Phpfox_Error::set(Phpfox::getPhrase('backuprestore.please_insert_your_application_client_id'));
         }
         if (empty($aVals['gdrive_clientsecret'])) {
             return Phpfox_Error::set(Phpfox::getPhrase('backuprestore.please_insert_your_application_client_secret_key'));
         }
         if (Phpfox_Error::isPassed()) {
             if ($gdrive = Phpfox::getService('backuprestore.process')->addGDriveKeys($aVals)) {
                 $this->url()->send('admincp.backuprestore.gdrivesett', null, Phpfox::getPhrase('backuprestore.changes_successfully_saved'));
             }
         }
     }
     //Values from DB for edit
     $gdkeys = Phpfox::getService('backuprestore.backuprestore')->getBTDBSettingByName('gdclient_keys');
     if (!empty($gdkeys)) {
         $gdkeys = unserialize(array_shift($gdkeys));
         $this->template()->assign('aForms', $gdkeys);
     }
     $this->template()->assign(array('redirect_url' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 'support_page' => $this->url()->makeUrl('admincp.backuprestore.gdrivesupp')));
     $this->template()->setBreadcrumb(Phpfox::getPhrase('backuprestore.google_drive'), $this->url()->makeUrl('admincp.backuprestore.gdrivesett'))->setHeader(array('btdbstyles.css' => 'module_backuprestore', 'scripts.js' => 'module_backuprestore'));
 }
 public function __construct()
 {
     require_once 'module/backuprestore/Google/Google_Client.php';
     require_once 'module/backuprestore/Google/contrib/Google_DriveService.php';
     require_once 'module/backuprestore/Google/contrib/Google_Oauth2Service.php';
     $this->btdbsett = PhpFox::getService('backuprestore.backuprestore');
     if (!$this->initClientKeys()) {
         return;
         // Phpfox::addMessage('Error');
     }
     $this->client = new Google_Client();
     $this->client->setApplicationName(Phpfox::getPhrase('backuprestore.phpfox_backup_into_cloud'));
     $this->client->setScopes($this->SCOPES);
     try {
         $this->init();
         //If we are in the access state and are still not authorized then unlink and re init
         if (!$this->is_authorized()) {
             throw new Exception();
         }
     } catch (Exception $e) {
         //Phpfox::addMessage(Phpfox::getPhrase('backuprestore.google_drive_error_when_requesting_access_token')); //re authorize user
     }
 }
Beispiel #7
0
 /**
  * Class process method wnich is used to execute this component.
  */
 public function process()
 {
     // Google Drive Authorize
     if ($this->request()->get('gd_authorize')) {
         if (!PhpFox::getService('backuprestore.googledrivefront')->initClientKeys()) {
             $this->url()->forward($this->url()->makeUrl('admincp.backuprestore.gdrivesett'), 'In order to use Google Drive Service fill below requirements');
         }
         try {
             PhpFox::getService('backuprestore.googledrivefront')->gdrive_auth_request();
         } catch (Exception $e) {
             Phpfox::addMessage($e->getMessage());
         }
     }
     // Google Drive Unauthorize
     if ($this->request()->get('gd_unauthorize')) {
         try {
             Phpfox::getService('backuprestore.googledrivefront')->gdrive_auth_revoke();
         } catch (Exception $re) {
         }
     }
     $gdrive = PhpFox::getService('backuprestore.googledrivefront');
     $tokens = $gdrive->getAccessTokens();
     //Check Google drive User Authorization
     if ($gdrive->is_authorized()) {
         //User Google Drive info
         try {
             if (isset($tokens)) {
                 $drive = $gdrive->buildService($tokens);
                 $gdrive_info = $gdrive->getAcountInfo($drive);
                 $this->authorized['gdrive'] = 1;
             }
         } catch (Exception $e) {
             throw $e;
         }
     }
     $this->template()->assign(array('gdrive_info' => !empty($gdrive_info) ? $gdrive_info : null, 'authorized' => $this->authorized));
 }
Beispiel #8
0
 public function __construct()
 {
     $this->_sTable = Phpfox::getT('backuprestore');
     $this->btcsett = PhpFox::getService('backuprestore.backuprestore');
 }
Beispiel #9
0
 public function process()
 {
     error_reporting(E_ALL);
     $dbname = Phpfox::getParam(array('db', 'name'));
     $user = Phpfox::getParam(array('db', 'user'));
     $pass = Phpfox::getParam(array('db', 'pass'));
     $host = Phpfox::getParam(array('db', 'host'));
     $process = Phpfox::getService('backuprestore.process');
     $backuprestore = Phpfox::getService('backuprestore.backuprestore');
     Phpfox::getLib('database')->freeResult();
     $aItems = Phpfox::getLib('database')->getTableStatus();
     $iSize = 0;
     $iOverhead = 0;
     foreach ($aItems as $iKey => $aItem) {
         $iSize += $aItem['Data_length'];
         $iOverhead += $aItem['Data_free'];
         $aItems[$iKey]['Name'] = $aItems[$iKey]['Name'];
     }
     if ($this->request()->get('save_settings')) {
         $aTables = $this->request()->getArray('tables');
         $sql_file_name = $process->generate_unique_key(15);
         if (!is_dir('file/tmpDatabaseRestore/')) {
             @mkdir('file/tmpDatabaseRestore/', 0777);
             @chmod('file/tmpDatabaseRestore/', 0777);
         }
         $sql_file_name = "file/tmpDatabaseRestore/" . $sql_file_name;
         if ($aTables) {
             $process->backup_tables($sql_file_name . '.sql', $host, $user, $pass, $dbname, $aTables, $sql_file_name);
         }
         $process->backup();
     }
     $gdriveAuthError = false;
     $dropboxAuthError = false;
     $emptyServices = false;
     $savedpath = $backuprestore->getBTDBSettingByName('selected_services');
     if ($savedpath['setting_value'] == '') {
         $emptyServices = true;
     } else {
         $backupsettings = unserialize($savedpath['setting_value']);
         $dropbox = PhpFox::getService('backuprestore.dropboxfront');
         //Google DRIVE
         $gdrive = PhpFox::getService('backuprestore.googledrivefront');
         $tokens = $gdrive->getAccessTokens();
         if (isset($backupsettings['gdrive']) && $backupsettings['gdrive']) {
             if (!$gdrive->is_authorized()) {
                 $gdriveAuthError = true;
             } else {
                 $gdriveAuthError = false;
             }
         }
         if (isset($backupsettings['dropbox']) && $backupsettings['dropbox']) {
             if (!$dropbox->is_authorized()) {
                 $dropboxAuthError = true;
             } else {
                 $dropboxAuthError = false;
             }
         }
     }
     $this->template()->assign(array('aItems' => $aItems, 'iSize' => $iSize, 'gdriveAuthError' => $gdriveAuthError, 'dropboxAuthError' => $dropboxAuthError, 'emptyServices' => $emptyServices, 'authErrorUrl' => $this->url()->makeUrl('admincp.backuprestore.destination'), 'iOverhead' => $iOverhead, 'iCnt' => count($aItems)));
     $this->template()->setBreadcrumb(Phpfox::getPhrase('backuprestore.take_backup_content'), $this->url()->makeUrl('admincp.backuprestore.backup'))->setHeader(array('btdbstyles.css' => 'module_backuprestore', 'jqueryFileTree.css' => 'module_backuprestore', 'manage_filetree.js' => 'module_backuprestore', 'jqueryFileTree.js' => 'module_backuprestore', 'scripts.js' => 'module_backuprestore'));
 }
 public function test()
 {
     //Retrive Google DRive saved tokens from DB
     if ($savedtokens = PhpFox::getService('backuprestore.backuprestore')->getBTDBSettingByName('googledrive_tokens')) {
         $savedtokens = json_encode(unserialize(array_shift($savedtokens)));
     }
     $savedtokens = json_decode($savedtokens, true);
     $params = array('refresh_token' => $savedtokens['refresh_token'], 'client_id' => $this->ClientId, 'client_secret' => $this->ClientSecret, 'grant_type' => 'refresh_token');
     $mReturn = Phpfox::getLib('request')->send('https://accounts.google.com/o/oauth2/token', $params);
     $result = json_decode($mReturn, true);
     $result['created'] = Phpfox::getTime();
     //var_dump($result);
     if (isset($result['access_token'])) {
         $this->client->setAccessToken($mReturn);
         try {
             if ($newtokens = $this->client->getAccessToken()) {
                 $tekens = json_decode($newtokens, true);
                 $tekens['created'] = Phpfox::getTime();
                 $newtokens = json_encode($tekens);
                 $userinfo = $this->getUserInfo($newtokens);
                 $emailAddress = $userinfo->getEmail();
                 $userId = $userinfo->getId();
                 echo $emailAddress . "<br>" . $userId;
                 $service = $this->buildService($newtokens);
                 $abc = $this->getAcountInfo($service);
             }
         } catch (Exception $abc) {
             $abc->getMessage();
         }
     }
 }
Beispiel #11
-1
 private function deleteDropboxFile($key, $folder)
 {
     if ($folder) {
         $folder = trim($folder, '/');
         $folder = trim($folder, '\\');
         $folder = "/" . $folder . "/";
     } else {
         $folder = '/';
     }
     $dropbox = PhpFox::getService('backuprestore.dropboxfront');
     if ($dropbox->deleteFile($folder . $key)) {
         return true;
     }
 }