-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathqwp_helper.ctrl.php
128 lines (106 loc) · 4.01 KB
/
qwp_helper.ctrl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php
/**
* Copyright (C) 2009-2019 www.seopanel.in. All rights reserved.
* @author Geo Varghese
*
*/
class QWP_Helper extends QuickWebProxy {
/**
* function to show web proxy form
*/
function showWebProxyForm($info) {
$proxyCtrler = new ProxyController();
$proxyList = $proxyCtrler->__getAllProxys();
// if allowed web server to act as a proxy
if (defined('QWP_ALLOW_WEB_SERVER_ACT_AS_PROXY') && QWP_ALLOW_WEB_SERVER_ACT_AS_PROXY) {
$proxyList[] = array('id' => 0, 'proxy' => $this->pluginText['Web Server']);
}
$sourceId = isset($info['source_id']) ? intval($info['source_id']) : intval($proxyList[0]['id']);
$this->set('sourceId', $sourceId);
$this->set('proxyList', $proxyList);
$this->pluginRender('web_proxy_form');
}
// if host server is selected as proxy, then verify user have enough
function verifyHostServerAsProxyEnabled($source) {
if ($source == 0) {
if (defined('QWP_ALLOW_WEB_SERVER_ACT_AS_PROXY') && QWP_ALLOW_WEB_SERVER_ACT_AS_PROXY) {
return true;
} else {
showErrorMsg($_SESSION['text']['label']['Access denied']);
}
}
return true;
}
/**
* function to do web proxy
*/
function doWebProxy($info) {
if (empty($info['url'])) {
showErrorMsg($this->pluginText["Please enter a valid url"]);
}
if (!isset($info['source_id'])) {
showErrorMsg($this->pluginText["Server list is empty"]);
}
if ($this->checkUrlBlocked($info['url'])) {
showErrorMsg($this->pluginText["Url blocked in the web proxy"]);
}
// if host server is selected as proxy, then verify user have enough
$this->verifyHostServerAsProxyEnabled($info['source_id']);
// check for backslahes at last
$info['url'] = addHttpToUrl($info['url']);
$url = $this->pluginScriptUrl . "&base_url=1&action=processWebProxy&doc_type=export&url=" . urlencode($info['url']);
$url .= "&source_id=" . intval($info['source_id']);
echo "<script type='text/javascript'>openInNewTab('$url')</script>";
}
function checkUrlBlocked($url) {
$blockList = explode(',', QWP_PROXY_BLOCK_URLS);
if (!empty($blockList)) {
foreach ($blockList as $blockUrl) {
$blockUrl = trim($blockUrl);
if (!empty($blockUrl) && stristr($url, $blockUrl)) {
return true;
}
}
}
return false;
}
/**
* function to process web proxy action
*/
function processWebProxy($info) {
global $sourceId;
if (empty($info['url']) && empty($info['q'])) {
showErrorMsg($this->pluginText["Please enter a valid url"]);
}
if (!isset($info['source_id'])) {
showErrorMsg($this->pluginText["Server list is empty"]);
}
if ($this->checkUrlBlocked($info['url'])) {
showErrorMsg($this->pluginText["Url blocked in the web proxy"]);
}
// if host server is selected as proxy, then verify user have enough
$sourceId = intval($info['source_id']);
$this->verifyHostServerAsProxyEnabled($sourceId);
// if base url is crawled, then store the details in crawl log
if (!empty($info['base_url'])) {
$url = urldecode($info['url']);
$crawlLogCtrl = new CrawlLogController();
$crawlInfo['crawl_status'] = 1;
$crawlInfo['ref_id'] = $crawlInfo['crawl_link'] = $url;
$crawlInfo['proxy_id'] = $sourceId;
$crawlInfo['crawl_type'] = "webproxy";
$logId = $crawlLogCtrl->createCrawlLog($crawlInfo);
}
global $retInfo;
define("PROXY_PREFIX", $this->pluginScriptUrl . "&action=processWebProxy&doc_type=export&source_id=$sourceId");
include $this->pluginPath . '/libs/php-proxy-app/index.php';
// if base url is crawled, then store the details in crawl log
if (!empty($info['base_url'])) {
$crawlInfo['crawl_status'] = $retInfo['crawl_status'] ? 1 : 0;
$crawlInfo['ref_id'] = $crawlInfo['crawl_link'] = $retInfo['crawl_link'];
$crawlInfo['log_message'] = addslashes($retInfo['log_message'] ? $retInfo['log_message'] : $_SESSION['text']['label']['Success']);
$crawlLogCtrl->updateCrawlLog($logId, $crawlInfo);
}
}
}
?>