Diff
6 years ago
dashboard
7 years ago
rest-api
6 years ago
.htaccess
7 years ago
Diff.php
6 years ago
GeoLite2-Country.mmdb
6 years ago
IPTraf.php
6 years ago
IPTrafList.php
7 years ago
WFLSPHP52Compatability.php
6 years ago
compat.php
8 years ago
conntest.php
7 years ago
cronview.php
8 years ago
dbview.php
8 years ago
diffResult.php
8 years ago
email_genericAlert.php
7 years ago
email_newIssues.php
6 years ago
email_unlockRequest.php
8 years ago
email_unsubscribeRequest.php
7 years ago
flags.php
7 years ago
live_activity.php
8 years ago
menu_dashboard.php
7 years ago
menu_dashboard_options.php
7 years ago
menu_firewall.php
6 years ago
menu_firewall_blocking.php
7 years ago
menu_firewall_blocking_options.php
8 years ago
menu_firewall_waf.php
7 years ago
menu_firewall_waf_options.php
7 years ago
menu_options.php
6 years ago
menu_scanner.php
6 years ago
menu_scanner_credentials.php
8 years ago
menu_scanner_options.php
6 years ago
menu_support.php
7 years ago
menu_tools.php
7 years ago
menu_tools_diagnostic.php
6 years ago
menu_tools_importExport.php
7 years ago
menu_tools_livetraffic.php
6 years ago
menu_tools_twoFactor.php
7 years ago
menu_tools_whois.php
8 years ago
menu_wordfence_central.php
7 years ago
noc1.key
7 years ago
sysinfo.php
8 years ago
unknownFiles.php
8 years ago
viewFullActivityLog.php
8 years ago
wf503.php
7 years ago
wfAPI.php
6 years ago
wfActivityReport.php
6 years ago
wfAdminNoticeQueue.php
8 years ago
wfAlerts.php
6 years ago
wfArray.php
7 years ago
wfBrowscap.php
6 years ago
wfBrowscapCache.php
7 years ago
wfBulkCountries.php
7 years ago
wfCache.php
6 years ago
wfCentralAPI.php
6 years ago
wfConfig.php
6 years ago
wfCrawl.php
6 years ago
wfCredentialsController.php
7 years ago
wfCrypt.php
6 years ago
wfDB.php
7 years ago
wfDashboard.php
7 years ago
wfDateLocalization.php
8 years ago
wfDiagnostic.php
6 years ago
wfDict.php
8 years ago
wfDirectoryIterator.php
7 years ago
wfHelperBin.php
11 years ago
wfHelperString.php
11 years ago
wfIPWhitelist.php
7 years ago
wfImportExportController.php
7 years ago
wfIssues.php
6 years ago
wfJWT.php
7 years ago
wfLockedOut.php
7 years ago
wfLog.php
6 years ago
wfMD5BloomFilter.php
8 years ago
wfModuleController.php
7 years ago
wfNotification.php
8 years ago
wfOnboardingController.php
7 years ago
wfPersistenceController.php
8 years ago
wfRESTAPI.php
7 years ago
wfScan.php
6 years ago
wfScanEngine.php
6 years ago
wfSchema.php
6 years ago
wfStyle.php
7 years ago
wfSupportController.php
6 years ago
wfUnlockMsg.php
6 years ago
wfUpdateCheck.php
6 years ago
wfUtils.php
6 years ago
wfVersionCheckController.php
8 years ago
wfView.php
10 years ago
wfViewResult.php
8 years ago
wordfenceClass.php
6 years ago
wordfenceConstants.php
6 years ago
wordfenceHash.php
6 years ago
wordfenceScanner.php
6 years ago
wordfenceURLHoover.php
6 years ago
wfImportExportController.php
118 lines
| 1 | <?php |
| 2 | |
| 3 | class wfImportExportController { |
| 4 | /** |
| 5 | * Returns the singleton wfImportExportController. |
| 6 | * |
| 7 | * @return wfImportExportController |
| 8 | */ |
| 9 | public static function shared() { |
| 10 | static $_shared = null; |
| 11 | if ($_shared === null) { |
| 12 | $_shared = new wfImportExportController(); |
| 13 | } |
| 14 | return $_shared; |
| 15 | } |
| 16 | |
| 17 | public function export() { |
| 18 | $export = array(); |
| 19 | |
| 20 | //Basic Options |
| 21 | $keys = wfConfig::getExportableOptionsKeys(); |
| 22 | foreach ($keys as $key) { |
| 23 | $export[$key] = wfConfig::get($key, ''); |
| 24 | } |
| 25 | |
| 26 | //Serialized Options |
| 27 | $export['scanSched'] = wfConfig::get_ser('scanSched', array()); |
| 28 | |
| 29 | //Table-based Options |
| 30 | $export['blocks'] = wfBlock::exportBlocks(); |
| 31 | |
| 32 | //Make the API call |
| 33 | try { |
| 34 | $api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); |
| 35 | $res = $api->call('export_options', array(), array('export' => json_encode($export))); |
| 36 | if ($res['ok'] && $res['token']) { |
| 37 | return array( |
| 38 | 'ok' => 1, |
| 39 | 'token' => $res['token'], |
| 40 | ); |
| 41 | } |
| 42 | else if ($res['err']) { |
| 43 | return array('err' => __("An error occurred: ", 'wordfence') . $res['err']); |
| 44 | } |
| 45 | else { |
| 46 | throw new Exception(__("Invalid response: ", 'wordfence') . var_export($res, true)); |
| 47 | } |
| 48 | } |
| 49 | catch (Exception $e) { |
| 50 | return array('err' => __("An error occurred: ", 'wordfence') . $e->getMessage()); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | public function import($token) { |
| 55 | try { |
| 56 | $api = new wfAPI(wfConfig::get('apiKey'), wfUtils::getWPVersion()); |
| 57 | $res = $api->call('import_options', array(), array('token' => $token)); |
| 58 | if ($res['ok'] && $res['export']) { |
| 59 | $totalSet = 0; |
| 60 | $import = @json_decode($res['export'], true); |
| 61 | if (!is_array($import)) { |
| 62 | return array('err' => __("An error occurred: Invalid options format received.", 'wordfence')); |
| 63 | } |
| 64 | |
| 65 | //Basic Options |
| 66 | $keys = wfConfig::getExportableOptionsKeys(); |
| 67 | $toSet = array(); |
| 68 | foreach ($keys as $key) { |
| 69 | if (isset($import[$key])) { |
| 70 | $toSet[$key] = $import[$key]; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | if (count($toSet)) { |
| 75 | $validation = wfConfig::validate($toSet); |
| 76 | $skipped = array(); |
| 77 | if ($validation !== true) { |
| 78 | foreach ($validation as $error) { |
| 79 | $skipped[$error['option']] = $error['error']; |
| 80 | unset($toSet[$error['option']]); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | $totalSet += count($toSet); |
| 85 | wfConfig::save(wfConfig::clean($toSet)); |
| 86 | } |
| 87 | |
| 88 | //Serialized Options |
| 89 | if (isset($import['scanSched']) && is_array($import['scanSched'])) { |
| 90 | wfConfig::set_ser('scanSched', $import['scanSched']); |
| 91 | wfScanner::shared()->scheduleScans(); |
| 92 | $totalSet++; |
| 93 | } |
| 94 | |
| 95 | //Table-based Options |
| 96 | if (isset($import['blocks']) && is_array($import['blocks'])) { |
| 97 | wfBlock::importBlocks($import['blocks']); |
| 98 | $totalSet += count($import['blocks']); |
| 99 | } |
| 100 | |
| 101 | return array( |
| 102 | 'ok' => 1, |
| 103 | 'totalSet' => $totalSet, |
| 104 | ); |
| 105 | } |
| 106 | else if ($res['err']) { |
| 107 | return array('err' => "An error occurred: " . $res['err']); |
| 108 | } |
| 109 | else { |
| 110 | throw new Exception("Invalid response: " . var_export($res, true)); |
| 111 | } |
| 112 | } |
| 113 | catch (Exception $e) { |
| 114 | return array('err' => "An error occurred: " . $e->getMessage()); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 |