forked from dtouzeau/artica
/
nmap.index.php
315 lines (231 loc) · 7.13 KB
/
nmap.index.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
308
309
310
311
312
313
314
315
<?php
include_once('ressources/class.templates.inc');
include_once('ressources/class.ldap.inc');
include_once('ressources/class.nmap.inc');
include_once('ressources/class.artica.inc');
include_once('ressources/class.ini.inc');
$user=new usersMenus();
if($user->AsSystemAdministrator==false){header('location:users.index.php');exit();}
if(isset($_GET["NmapScanEnabled"])){main_settings_edit();exit;}
if(isset($_GET["nmap_delete_ip"])){main_delete_network();exit;}
if(isset($_GET["main"])){main_switch();exit;}
if(isset($_GET["AddNmapNetwork"])){main_add_nework();exit;}
if(isset($_GET["ScanNow"])){main_scan();exit;}
main_page();
function main_page(){
$page=CurrentPageName();
if($_GET["hostname"]==null){
$user=new usersMenus();
$_GET["hostname"]=$user->hostname;}
$html=
"
<script language=\"JavaScript\">
var timerID = null;
var timerID1 = null;
var tant=0;
var reste=0;
function demarre(){
tant = tant+1;
reste=5-tant;
if (tant < 5 ) {
timerID = setTimeout(\"demarre()\",2000);
} else {
tant = 0;
ChargeLogs();
demarre(); //la boucle demarre !
}
}
function ChargeLogs(){
if(document.getElementById('nmap_events')){
LoadAjax('nmap_events','$page?main=nmap-evdetails');
}
LoadAjax('status','$page?main=status');
}
</script>
<table style='width:100%'>
<tr>
<td width=1% valign='top'><img src='img/bg_nmap.png'></td>
<td valign='top'>
<div id='status'></div></td>
</tr>
<tr>
<td colspan=2 valign='top'>
<div id='main_config'></div>
</td>
</tr>
</table>
<script>demarre();ChargeLogs();LoadAjax('main_config','$page?main=default');</script>
";
$cfg["JS"][]="js/nmap.js";
$tpl=new template_users('{APP_NMAP}',$html,0,0,0,0,$cfg);
echo $tpl->web_page;
}
function main_switch(){
switch ($_GET["main"]) {
case "nmap-list":echo main_network_list();exit;break;
case "nmap-add":echo main_form_add();exit;break;
case "nmap-log":echo main_events();exit;break;
case "status":echo main_status();exit;break;
case "nmap-evdetails":echo main_events_fill();break;
default:main_settings();break;
}
}
function main_form_add(){
$tmp=md5(date('YmdHis'));
$html=" <H5>{add_network} </H5>
<p class=caption>{add_network_text}</p>
<input type='hidden' name='tmp' id='tmp' value='$tmp'>
" . RoundedLightGrey("
<table style='width:100%'>
<tr>
<td valign='top' nowrap align='right'><strong>{ip}:</strong></td>
<td valign='top' nowrap align='left'>" . Field_text('nmap_ip','','width:120px')."</td>
</tr>
<tr>
<td valign='top' nowrap align='right'><strong>{mask}:</strong></td>
<td valign='top' nowrap align='left'>" . Field_text('nmap_mask','','width:120px')."</td>
</tr>
<tr>
<td colspan=2 align='right'><input type='button' OnClick=\"javascript:AddNmapNetwork();\" value='{add} »'></td>
</tr>
</table>");
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function main_settings(){
$nmap=new nmap();
$artica=new artica_general();
$html="
<table style='width:100%'>
<tr>
<td valign='top'>
<H5>{APP_NMAP} {settings}</H5>
<p class=caption>{about}</p>
" . RoundedLightGrey("
<table style='width:100%'>
<tr>
<td valign='top' nowrap align='right'><strong>{NmapScanEnabled}:</strong></td>
<td valign='top' nowrap align='left'>" . Field_numeric_checkbox_img('NmapScanEnabled',$artica->NmapScanEnabled,'{enable_disable}')."</td>
</tr>
<tr>
<td valign='top' nowrap align='right'><strong>{NmapRotateMinutes}:</strong></td>
<td valign='top' nowrap align='left'>" . Field_text('NmapRotateMinutes',$nmap->NmapRotateMinutes,'width:90px')."</td>
</tr>
<tr>
<td colspan=2 align='right'><input type='button' OnClick=\"javascript:SaveNmapSettings();\" value='{edit} »'></td>
</tr>
</table>")."
<br><div id='nmap_list'>".main_network_list()."</div>
</td>
<td valign='top'>
" . RoundedLightGrey(Paragraphe("acl-add-64.png",'{add_network}','{add_network_text}',"javascript:nmap_add_network()"))."<br>
" . RoundedLightGrey(Paragraphe("folder-logs-64.png",'{nmap_logs}','{nmap_logs_text}',"javascript:nmap_logs()"))."<br>
" . RoundedLightGrey(Paragraphe("global-settings.png",'{perform_scan}','{perform_scan_text}',"javascript:nmap_scan()"))."<br>
</td>
</tr>
</table>
";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function main_settings_edit(){
$nmap=new nmap();
$nmap->NmapRotateMinutes=$_GET["NmapRotateMinutes"];
$nmap->SaveConf();
$artica=new artica_general();
$artica->NmapScanEnabled=$_GET["NmapScanEnabled"];
$artica->Save();
}
function main_network_list(){
$nmap=new nmap();
$html="
<table style='with:350px'>";
while (list ($num, $ligne) = each ($nmap->NmapNetworkIP) ){
$tmp=md5(date('YmdHis').$ligne);
$html=$html . "
<tr " . CellRollOver().">
<td width=1% valign='top'><img src='img/fw_bold.gif'></td>
<td><strong>$ligne</td>
<td width=1% valign='top'>" . imgtootltip('x.gif','{delete}',"nmap_delete_ip('$num','$tmp')")."</td>
</tr>
";
}
$html=$html . "</table>";
$tpl=new templates();
return $tpl->_ENGINE_parse_body("<H3>{networks_list}</h3>".RoundedLightGrey($html));
}
function main_delete_network(){
$nmap=new nmap();
$net=$nmap->NmapNetworkIP[$_GET["nmap_delete_ip"]];
$tpl=new templates();
if($nmap->delIpToscan($_GET["nmap_delete_ip"])){
echo $tpl->_ENGINE_parse_body("$net\n{success}");
}else{
echo $tpl->_ENGINE_parse_body("$net\n{failed}\n$nmap->ldap_error");
}
}
function main_add_nework(){
$nmap=new nmap();
$sip=new SecondIP($_GET["AddNmapNetwork"],$_GET["mask"]);
$tpl=new templates();
if($nmap->addIpToscan($sip->CDR)){
echo $tpl->_ENGINE_parse_body("$sip->CDR\n{success}");
}else{
echo $tpl->_ENGINE_parse_body("$sip->CDR\n{failed}\n$nmap->ldap_error");
}
}
function main_status(){
$sock=new sockets();
$datas=$sock->getfile('nmapmem');
if(strlen($datas)>2){
$img="warning24.png";
$status="{stopped}";
}else{
$img="ok32.png";
$status="running";
}
$status="<table style='width:100%'>
<tr>
<td valign='top'>
<img src='img/$img'>
</td>
<td valign='top'>
<table style='width:100%'>
<tr>
<td align='right' nowrap><strong>{APP_NMAP}:</strong></td>
<td><strong>$status</strong></td>
</tr>
<tr>
<td align='right'><strong>{pid}:</strong></td>
<td><strong>$datas</strong></td>
</tr>
</table>
</td>
</tr>
</table>";
$status=RoundedLightGreen($status);
$tpl=new templates();
return $tpl->_ENGINE_parse_body($status);
}
function main_events(){
$html="<H3>{nmap_logs}</H3><div id='nmap_events'>".main_events_fill()."</div>";
$tpl=new templates();
echo $tpl->_ENGINE_parse_body($html);
}
function main_events_fill(){
$datas=@explode("\n",file_get_contents(@dirname(__FILE__).'/ressources/logs/nmap.log'));
if(is_array($datas)){
$datas=array_reverse($datas);
while (list ($num, $ligne) = each ($datas) ){
if(trim($ligne)<>null){
$ev[]=$ligne;
}
}
}
return "<textarea style='border:0px;font-size:10px;width:100%' rows=50>".@implode("\n",$ev)."</textarea>";
}
function main_scan(){
$sock=new sockets();
$sock->getfile('NmapScanNow');
}
?>