forked from dtouzeau/artica-1.5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system-etc-hosts.php
executable file
·307 lines (233 loc) · 7.96 KB
/
system-etc-hosts.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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.users.menus.inc');
$user=new usersMenus();
if($user->AsSystemAdministrator==false){
$tpl=new templates();
echo "alert('". $tpl->javascript_parse_text("{ERROR_NO_PRIVS}")."');";
die();exit();
}
if(isset($_GET["popup"])){popup();exit;}
if(isset($_GET["add-form"])){popup_add();exit;}
if(isset($_GET["ip_addr"])){popup_save();exit;}
if(isset($_GET["refresh"])){echo getlist();exit;}
if(isset($_GET["del"])){popup_delete();exit;}
if(isset($_GET["add-etc-hosts-p"])){Paragraphe_add();exit;}
if(isset($_GET["DisableEtcHosts"])){DisableEtcHosts_save();exit;}
js();
function js(){
$page=CurrentPageName();
$tpl=new templates();
$title=$tpl->_ENGINE_parse_body("{etc_hosts}");
$title2=$tpl->_ENGINE_parse_body("{add_new_entry}");
$html="
function etc_host_show(){
YahooWin3(740,'$page?popup=yes','$title');
}
function etc_hosts_add_form(){
YahooWin4(475,'$page?add-form=yes','$title2');
}
var X_etc_hosts_add_form_save= function (obj) {
var results=obj.responseText;
if(results.length>0){alert(results);}
YahooWin4Hide();
refresh();
}
function etc_hosts_add_form_save(){
var XHR = new XHRConnection();
XHR.appendData('ip_addr',document.getElementById('ip_addr').value);
XHR.appendData('servername',document.getElementById('servername').value);
XHR.appendData('alias',document.getElementById('alias').value);
document.getElementById('hostsdiv').innerHTML='<center style=\"margin:20px;padding:20px\"><img src=\"img/wait_verybig.gif\"></center>';
XHR.sendAndLoad('$page', 'GET',X_etc_hosts_add_form_save);
}
function refresh(){
LoadAjax('idhosts','$page?refresh=yes');
}
function etc_hosts_del(ip,name){
var XHR = new XHRConnection();
XHR.appendData('del',ip);
XHR.appendData('name',name);
document.getElementById('idhosts').innerHTML='<center style=\"margin:20px;padding:20px\"><img src=\"img/wait_verybig.gif\"></center>';
XHR.sendAndLoad('$page', 'GET',X_etc_hosts_add_form_save);
}
etc_host_show();
";
echo $html;
}
function DisableEtcHosts_save(){
$sock=new sockets();
$sock->SET_INFO("DisableEtcHosts",$_GET["DisableEtcHosts"]);
}
function popup(){
$page=CurrentPageName();
$LIST=getlist();
$sock=new sockets();
$html="<div class=explain>{etc_hosts_explain}</div>
<div style='text-align:right'>
<table>
<tr>
<td class=legend>{DisableEtcHosts}:</td>
<td>". Field_checkbox("DisableEtcHosts",1,$sock->GET_INFO("DisableEtcHosts"),"DisableEtcHostsSave()")."</td>
</tr>
</table>
</div>
<table style='width:100%'>
<tr>
<td valign='top'><div style='width:100%;height:330px;overflow:auto' id='idhosts'>$LIST</div></td>
<td valign='top'><div id='add-etc-hosts-p'></div></td>
</tr>
</table>
<script>
function ParEtcHosts(){
LoadAjax('add-etc-hosts-p','$page?add-etc-hosts-p=yes');
}
function idhostsList(){
LoadAjax('idhosts','$page?refresh=yes');
}
var x_DisableEtcHostsSave=function (obj) {
tempvalue=obj.responseText;
if(tempvalue.length>0){alert(tempvalue);}
ParEtcHosts();
idhostsList();
}
function DisableEtcHostsSave(){
var XHR = new XHRConnection();
if(document.getElementById('DisableEtcHosts').checked){
XHR.appendData('DisableEtcHosts','1');}else{
XHR.appendData('DisableEtcHosts','0');}
document.getElementById('add-etc-hosts-p').innerHTML='<center><img src=\"img/wait_verybig.gif\"></center>';
XHR.sendAndLoad('$page', 'GET',x_DisableEtcHostsSave);
}
ParEtcHosts();
</script>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("$html");
}
function Paragraphe_add(){
$add=Paragraphe("host-file-64-add.png","{add_new_entry}","{add_new_entry_text}","javascript:etc_hosts_add_form()","{add_new_entry_text}");
$sock=new sockets();
if($sock->GET_INFO("DisableEtcHosts")==1){
$add=Paragraphe("host-file-64-add-grey.png","{add_new_entry}","{add_new_entry_text}","");
}
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($add);
}
function getlist(){
$sock=new sockets();
$res=base64_decode($sock->getFrameWork("cmd.php?etc-hosts-open=yes"));
writelogs($res,__FUNCTION__,__FILE__,__LINE__);
$datas=unserialize($res);
while (list ($num, $ligne) = each ($datas) ){
if(preg_match("#^([0-9\.\:]+)\s+(.+?)\s+(.+?)$#",$ligne,$re)){
$array[]=array("name"=>$re[2],"alias"=>$re[3],"ip"=>$re[1],"md"=>md5($ligne));
continue;
}
if(preg_match("#^([0-9\.\:]+)\s+(.+?)$#",$ligne,$re)){
$array[]=array("name"=>$re[2],"ip"=>$re[1],"md"=>md5($ligne));
continue;
}
}
$DisableEtcHosts=$sock->GET_INFO("DisableEtcHosts");
if(!is_array($array)){return null;}
$html=" <table cellspacing='0' cellpadding='0' border='0' class='tableView' style='width:99%'>
<thead class='thead'>
<th> </th>
<th>{ip_address}</th>
<th>{servername}</th>
<th>{alias}</th>
<th> </th>
</thead>
</tr>
<tbody class='tbody'>
";
while (list ($num, $ligne) = each ($array) ){
if($classtr=="oddRow"){$classtr=null;}else{$classtr="oddRow";}
$delete=imgtootltip("delete-24.png","{delete}","etc_hosts_del('{$ligne["ip"]}','{$ligne["name"]}')");
if($ligne["name"]==null){$ligne["name"]=" ";}
if($ligne["alias"]==null){$ligne["alias"]=" ";}
if($DisableEtcHosts==1){
$delete=imgtootltip("delete-24-grey.png","{delete}","blur()");
}
$html=$html."<tr class=$classtr>
<td width=1% nowrap><img src='img/base.gif'></td>
<td width=1% nowrap style='font-size:14px'>{$ligne["ip"]}</td>
<td width=60% nowrap style='font-size:12px'>{$ligne["name"]}</td>
<td width=1% nowrap style='font-size:14px'>{$ligne["alias"]}</td>
<td width=1% nowrap>$delete</td>
</tr>
";
}
$html=$html."</tbody>
</table>";
$tpl=new templates();
return $tpl->_ENGINE_parse_body("$html");
}
function popup_save(){
if($_GET["ip_addr"]==null){return false;}
if($_GET["servername"]==null){return false;}
if($_GET["alias"]==null){
$_GET["alias"]=$_GET["servername"];
}
$line="{$_GET["ip_addr"]}\t{$_GET["servername"]}\t{$_GET["alias"]}";
$sock=new sockets();
$line=base64_encode($line);
$sock->getFrameWork("cmd.php?etc-hosts-add=$line");
}
function popup_add(){
$html="
<div id='hostsdiv'>
<table style='width:100%'>
<tr>
<td valign='top'><img src='img/64-computer.png'></td>
<td valign='top'>
<table style='width:100%' class=form>
<tr>
<td class=legend style='font-size:14px'>{ip_address}:</td>
<td>". Field_text('ip_addr',null,"width:120px;font-size:14px","script:CheckHostip()")."</td>
</tR>
<tr>
<td class=legend style='font-size:14px'>{servername}:</td>
<td>". Field_text('servername',null,"width:220px;font-size:14px",null,"CheckHostAlias()")."</td>
</tR>
<tr>
<td class=legend style='font-size:14px'>{alias}:</td>
<td>". Field_text('alias',null,"width:120px;font-size:14px")."</td>
</tR>
</table><hr>
<div style='width:100%;text-align:right'>". button("{add}","etc_hosts_add_form_save()")."</div>
</div>
<script>
function CheckHostip(){
DisableFieldsFromId('hostsdiv');
document.getElementById('ip_addr').disabled=false;
var ip_addr=document.getElementById('ip_addr').value;
var re = new RegExp('^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+');
if(ip_addr.match(re)){
document.getElementById('servername').disabled=false;
}
}
function CheckHostAlias(){
var servername=document.getElementById('servername').value;
if(servername.length==0){return;}
document.getElementById('alias').disabled=false;
var alias=document.getElementById('alias').value;
if(alias.length>0){return;}
tr=servername.split('.');
if(tr.length>0){
document.getElementById('alias').value=tr[0];
}
}
CheckHostip();
</script>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body("$html");
}
function popup_delete(){
$sock=new sockets();
$sock->getFrameWork("cmd.php?etc-hosts-del-by-values=yes&ip={$_GET["del"]}&name={$_GET["name"]}");
}
?>