forked from poppyred/1.6.x
/
nginx.peer.php
executable file
·217 lines (160 loc) · 7.23 KB
/
nginx.peer.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php
header("Pragma: no-cache");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-cache, must-revalidate");
if(isset($_GET["verbose"])){$GLOBALS["VERBOSE"]=true;ini_set('display_errors', 1);ini_set('error_reporting', E_ALL);ini_set('error_prepend_string',null);ini_set('error_append_string',null);}
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
include_once('ressources/class.groups.inc');
include_once('ressources/class.artica.inc');
include_once('ressources/class.ini.inc');
include_once('ressources/class.squid.inc');
include_once('ressources/class.system.network.inc');
include_once('ressources/class.squid.reverse.inc');
if(isset($_GET["general-settings"])){general_settings();exit;}
if(isset($_POST["general-settings"])){general_settings_save();exit;}
if(isset($_GET["js"])){js();exit;}
if(isset($_GET["tabs"])){tabs();exit;}
function js(){
header("content-type: application/x-javascript");
$ID=intval($_GET["ID"]);
$tpl=new templates();
$page=CurrentPageName();
$title=$tpl->javascript_parse_text("{new_server}");
if($ID>0){
$q=new mysql_squid_builder();
$ligne=mysql_fetch_array($q->QUERY_SQL("SELECT servername FROM reverse_sources WHERE ID='$ID'"));
$title=$ligne["servername"];
}
echo "YahooWin2(890,'$page?tabs=yes&ID=$ID','$title');";
}
function tabs(){
$ID=intval($_GET["ID"]);
$page=CurrentPageName();
$tpl=new templates();
$q=new mysql();
$title=$tpl->javascript_parse_text("{new_server}");
$sock=new sockets();
$EnableNginx=intval($sock->GET_INFO("EnableNginx"));
if($EnableNginx==0){
echo FATAL_ERROR_SHOW_128("
{enable_reverse_proxy_service}
<center style='margin:30px'>". button("{enable_reverse_proxy_service}","Loadjs('$page?EnableNginx=yes')",42)."</center>");
return;
}
if($ID>0){
$q=new mysql_squid_builder();
$ligne=mysql_fetch_array($q->QUERY_SQL("SELECT ipaddr FROM reverse_sources WHERE ID='$ID'"));
$title=$ligne["ipaddr"];
}
$array["general-settings"]=$title;
if($ID>0){
$array["web-servers"]='{web_servers}';
}
$fontsize=18;
while (list ($num, $ligne) = each ($array) ){
if($num=="web-servers"){
$tab[]= $tpl->_ENGINE_parse_body("<li><a href=\"nginx.peer.www.php?ID=$ID\" style='font-size:{$fontsize}px'><span>$ligne</span></a></li>\n");
continue;
}
if($num=="events"){
$tab[]= $tpl->_ENGINE_parse_body("<li><a href=\"nginx.events.php?ID=$ID\" style='font-size:{$fontsize}px'><span>$ligne</span></a></li>\n");
continue;
}
if($num=="destinations"){
$tab[]= $tpl->_ENGINE_parse_body("<li><a href=\"nginx.destinations.php?ID=$ID\" style='font-size:{$fontsize}px'><span>$ligne</span></a></li>\n");
continue;
}
$tab[]="<li style='font-size:{$fontsize}px'><a href=\"$page?$num=yes&ID=$ID\"><span >$ligne</span></a></li>\n";
}
$t=time();
//
echo build_artica_tabs($tab, "main_source_$ID")."<script>";
}
function general_settings(){
$ID=intval($_GET["ID"]);
$tpl=new templates();
$page=CurrentPageName();
$fields_size=22;
$rv=new squid_reverse();
$q=new mysql_squid_builder();
$sock=new sockets();
$t=time();
$sslcertificates=$rv->ssl_certificates_list();
$sslcertificates[null]="{none}";
$results=$q->QUERY_SQL("SELECT ID,keys_zone FROM nginx_caches ORDER BY keys_zone LIMIT 0,250");
$nginx_caches[0]="{none}";
while($ligne2=mysql_fetch_array($results,MYSQL_ASSOC)){
$nginx_caches[$ligne2["ID"]]=$ligne2["keys_zone"];
}
$ligne=mysql_fetch_array($q->QUERY_SQL("SELECT * FROM reverse_sources WHERE ID='$ID'"));
if(!$q->ok){echo FATAL_ERROR_SHOW_128($q->mysql_error);return;}
$html[]="<div style='width:98%' class=form>";
$html[]="<table style='width:100%'>";
$html[]="<tr><td colspan=2 style='font-size:28px;padding-bottom:20px'>{main_parameters} {$ligne["ipaddr"]}:{$ligne["port"]}</td></tr>";
$html[]=Field_text_table("servername-$t","{name}",$ligne["servername"],$fields_size,null,450);
$html[]=Field_ipv4_table("ipaddr-$t","{ipaddr}",$ligne["ipaddr"],$fields_size,null,110);
$html[]=Field_text_table("port-$t","{inbound_port}",$ligne["port"],$fields_size,null,110);
$html[]=Field_checkbox_table("ssl-$t", "{UseSSL}",$ligne["ssl"],$fields_size);
$html[]=Field_text_table("forceddomain-$t","{forceddomain}",$ligne["forceddomain"],$fields_size,null,450);
$html[]=Field_text_table("remote_path-$t","{root_directory}",$ligne["remote_path"],$fields_size,null,450);
$html[]=Field_list_table("cacheid-$t","{cache_directory}",$ligne["cacheid"],$fields_size,$nginx_caches,null,450);
$html[]=Field_list_table("certificate-$t","{certificate}",$ligne["certificate"],$fields_size,$sslcertificates,null,450);
$html[]=Field_button_table_autonome("{apply}","Submit$t",30);
$html[]="</table>";
$html[]="</div>
<script>
var xSubmit$t= function (obj) {
var results=obj.responseText;
if(results.length>3){alert(results);}
$('#NGINX_MAIN_TABLE').flexReload();
$('#NGINX_DESTINATION_MAIN_TABLE').flexReload();
var ID=$ID
if(ID==0){ YahooWin2Hide();}
}
function Submit$t(){
var ssl=0
var XHR = new XHRConnection();
XHR.appendData('general-settings','$ID');
if(document.getElementById('ssl-$t').checked){ss=1;}
XHR.appendData('servername',document.getElementById('servername-$t').value);
XHR.appendData('ipaddr',document.getElementById('ipaddr-$t').value);
XHR.appendData('ssl',ssl);
XHR.appendData('port',document.getElementById('port-$t').value);
XHR.appendData('forceddomain',document.getElementById('forceddomain-$t').value);
var pp=encodeURIComponent(document.getElementById('remote_path-$t').value);
XHR.appendData('remote_path',document.getElementById('remote_path-$t').value);
XHR.appendData('cacheid',document.getElementById('cacheid-$t').value);
XHR.appendData('certificate',document.getElementById('certificate-$t').value);
XHR.sendAndLoad('$page', 'POST',xSubmit$t);
}
</script>
";
echo $tpl->_ENGINE_parse_body(@implode("\n", $html));
}
function general_settings_save(){
$_POST["remote_path"]=url_decode_special_tool($_POST["remote_path"]);
$q=new mysql_squid_builder();
if(!$q->FIELD_EXISTS("reverse_sources", "cacheid")){$q->QUERY_SQL("ALTER TABLE `reverse_sources` ADD `cacheid` INT(10) NOT NULL DEFAULT '0'");}
if(!$q->FIELD_EXISTS("reverse_sources", "certificate")){$q->QUERY_SQL("ALTER TABLE `reverse_sources` ADD `certificate` CHAR(128) NULL");}
$ID=intval($_POST["general-settings"]);
if($ID>0){
$q->QUERY_SQL("UPDATE `reverse_sources` SET
`servername`='{$_POST["servername"]}',
`ipaddr`='{$_POST["ipaddr"]}',
`remote_path`='{$_POST["remote_path"]}',
`forceddomain`='{$_POST["forceddomain"]}',
`port`='{$_POST["port"]}',
`cacheid`='{$_POST["cacheid"]}',
`ssl`='{$_POST["ssl"]}',
`certificate`='{$_POST["certificate"]}'
WHERE ID='{$_POST["general-settings"]}'");
if(!$q->ok){echo $q->mysql_error;}
}else{
$q->QUERY_SQL("INSERT IGNORE INTO `reverse_sources` (`ssl`,`servername`,`ipaddr`,`remote_path`,`forceddomain`,`port`,`cacheid`,`certificate`)
VALUES('{$_POST["ssl"]}','{$_POST["servername"]}','{$_POST["ipaddr"]}','{$_POST["remote_path"]}','{$_POST["forceddomain"]}','{$_POST["port"]}','{$_POST["cacheid"]}','{$_POST["certificate"]}')");
if(!$q->ok){echo $q->mysql_error;}
}
}