This repository has been archived by the owner on Mar 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
base_maintenance.php
270 lines (225 loc) · 9.36 KB
/
base_maintenance.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
<?php
/*******************************************************************************
** Basic Analysis and Security Engine (BASE)
** Copyright (C) 2004 BASE Project Team
** Copyright (C) 2000 Carnegie Mellon University
**
** (see the file 'base_main.php' for license details)
**
** Project Leads: Kevin Johnson <[email protected]>
** Sean Muller <[email protected]>
** Built upon work by Roman Danyliw <[email protected]>, <[email protected]>
**
** Purpose: status and event/dns/whois cache maintenance
********************************************************************************
** Authors:
********************************************************************************
** Kevin Johnson <[email protected]
**
********************************************************************************
*/
include("base_conf.php");
include("$BASE_path/includes/base_constants.inc.php");
include("$BASE_path/includes/base_include.inc.php");
include_once("$BASE_path/base_db_common.php");
include_once("$BASE_path/base_common.php");
include_once("$BASE_path/base_stat_common.php");
include_once("$BASE_path/setup/setup_db.inc.php");
$et = new EventTiming($debug_time_mode);
$cs = new CriteriaState("base_maintenance.php");
$cs->ReadState();
// Check role out and redirect if needed -- Kevin
$roleneeded = 10000;
$BUser = new BaseUser();
if ($Use_Auth_System == 1)
{
if ($_POST['standalone'] == "yes")
{
$usrrole = $BUser->AuthenticateNoCookie(filterSql($_POST['user']), filterSql($_POST['pwd']));
if ($usrrole == "Failed")
base_header('HTTP/1.0 401');
if ($usrrole > $roleneeded)
base_header('HTTP/1.0 403');
}
elseif (($BUser->hasRole($roleneeded) == 0))
base_header("Location: ". $BASE_urlpath . "/index.php");
}
$page_title = _MAINTTITLE;
PrintBASESubHeader($page_title, $page_title, $cs->GetBackLink(), $refresh_all_pages);
$submit = ImportHTTPVar("submit", VAR_ALPHA | VAR_SPACE);
?>
<br>
<FORM METHOD="POST" ACTION="base_maintenance.php">
<?php
/* Connect to the Alert database */
$db = NewBASEDBConnection($DBlib_path, $DBtype);
$db->baseDBConnect($db_connect_method,
$alert_dbname, $alert_host, $alert_port, $alert_user, $alert_password);
if ( $debug_mode > 0 )
echo "submit = '$submit'<P>";
if ( ini_get("safe_mode") != true )
set_time_limit($max_script_runtime);
$repair_output = NULL;
if ( $submit == "Update Alert Cache" )
{
UpdateAlertCache($db);
}
else if ( $submit == "Rebuild Alert Cache" )
{
DropAlertCache($db);
UpdateAlertCache($db);
}
else if ( $submit == "Update IP Cache" )
{
UpdateDNSCache($db);
}
else if ( $submit == "Rebuild IP Cache" )
{
DropDNSCache($db);
UpdateDNSCache($db);
}
else if ( $submit == "Update Whois Cache" )
{
UpdateWhoisCache($db);
}
else if ( $submit == "Rebuild Whois Cache" )
{
DropWhoisCache($db);
UpdateWhoisCache($db);
}
else if ( $submit == "Repair Tables")
{
//$repair_output = RepairDBTables($db);
CreateBASEAG($db);
}
else if ( $submit == "Clear Data Tables")
{
ClearDataTables($db);
}
echo '<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#669999">
<TR><TD>
<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#FFFFFF">
<TR><TD class="sectiontitle">'._MNTPHP.'</TD></TR>
<TR><TD>
<B>'._MNTCLIENT.'</B> '.XSSPrintSafe($_SERVER['HTTP_USER_AGENT']).'<BR>
<B>'._MNTSERVER.'</B> '.XSSPrintSafe($_SERVER['SERVER_SOFTWARE']).'<BR>
<B>'._MNTSERVERHW.'</B> '.php_uname().'<BR>
<B>'._MNTPHPVER.'</B> '.phpversion().'<BR>
<B>PHP API:</B> '.php_sapi_name().'<BR>';
$tmp_error_reporting_str = "";
if ( (ini_get("error_reporting") & E_ERROR) > 0 )
$tmp_error_reporting_str .= " [E_ERROR] ";
if ( (ini_get("error_reporting") & E_WARNING) > 0 )
$tmp_error_reporting_str .= " [E_WARNING] ";
if ( (ini_get("error_reporting") & E_PARSE) > 0 )
$tmp_error_reporting_str .= " [E_PARSE] ";
if ( (ini_get("error_reporting") & E_NOTICE) > 0 )
$tmp_error_reporting_str .= " [E_NOTICE] ";
if ( (ini_get("error_reporting") & E_CORE_WARNING) > 0 )
$tmp_error_reporting_str .= " [E_CORE_WARNING] ";
if ( (ini_get("error_reporting") & E_CORE_ERROR) > 0 )
$tmp_error_reporting_str .= " [E_CORE_ERROR] ";
if ( (ini_get("error_reporting") & E_COMPILE_ERROR) > 0 )
$tmp_error_reporting_str .= " [E_COMPILE_ERROR] ";
if ( (ini_get("error_reporting") & E_COMPILE_WARNING) > 0 )
$tmp_error_reporting_str .= " [E_COMPILE_WARNING] ";
echo ' <B>'._MNTPHPLOGLVL.' </B> ('.ini_get("error_reporting").') '.$tmp_error_reporting_str.'<BR>
<B>'._MNTPHPMODS.' </B> ';
$module_lst = get_loaded_extensions();
for ( $i = 0; $i < count($module_lst); $i++)
echo " [ ".$module_lst[$i]." ]";
echo ' </TD></TR>
</TABLE>
</TD></TR>
</TABLE><P>';
echo '<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#669999">
<TR><TD>
<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#FFFFFF">
<TR><TD class="sectiontitle">'._DATABASE.'</TD></TR>
<TR><TD>';
GLOBAL $ADODB_vers;
echo "<B>"._MNTDBTYPE."</B> $DBtype <BR>
<B>"._MNTDBALV."</B> $ADODB_vers <BR>
<B>"._MNTDBALERTNAME."</B> $alert_dbname <BR>
<B>"._MNTDBARCHNAME."</B> $archive_dbname <BR>
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Repair Tables\">
<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Clear Data Tables\">";
echo $repair_output;
echo '
</TD></TR>
</TABLE>
</TD></TR>
</TABLE><P>';
echo '<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#669999">
<TR><TD>
<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#FFFFFF">
<TR><TD class="sectiontitle">'._MNTAIC.'</TD></TR>
<TR><TD>';
$event_cnt_lst = $db->baseExecute("SELECT COUNT(*) FROM event");
$event_cnt_row = $event_cnt_lst->baseFetchRow();
$event_cnt = $event_cnt_row[0];
$event_cnt_lst->baseFreeRows();
$cache_event_cnt_lst = $db->baseExecute("SELECT COUNT(*) FROM acid_event");
$cache_event_cnt_row = $cache_event_cnt_lst->baseFetchRow();
$cache_event_cnt = $cache_event_cnt_row[0];
$cache_event_cnt_lst->baseFreeRows();
echo '<B>'._MNTAICTE.'</B> '.$event_cnt.'  
<B>'._MNTAICCE.'</B> '.$cache_event_cnt.'
<INPUT TYPE="submit" NAME="submit" VALUE="Update Alert Cache">
<INPUT TYPE="submit" NAME="submit" VALUE="Rebuild Alert Cache">';
echo ' </TD></TR>
</TABLE>
</TD></TR>
</TABLE><P>';
echo '<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#669999">
<TR><TD>
<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=2 BORDER=0 BGCOLOR="#FFFFFF">
<TR><TD class="sectiontitle">'._MNTIPAC.'</TD></TR>
<TR><TD>';
$uncached_sip_cnt = UniqueSrcIPCnt($db);
$uncached_dip_cnt = UniqueDstIPCnt($db);
$ip_result = $db->baseExecute("SELECT COUNT(DISTINCT ip_src) FROM acid_event ".
"INNER JOIN acid_ip_cache ON ipc_ip = ip_src ".
"WHERE ipc_fqdn is not NULL");
$row = $ip_result->baseFetchRow();
$ip_result->baseFreeRows();
$cached_sip_cnt = $row[0];
$ip_result = $db->baseExecute("SELECT COUNT(DISTINCT ip_dst) FROM acid_event ".
"INNER JOIN acid_ip_cache ON ipc_ip = ip_dst ".
"WHERE ipc_fqdn is not NULL");
$row = $ip_result->baseFetchRow();
$ip_result->baseFreeRows();
$cached_dip_cnt = $row[0];
$ip_result = $db->baseExecute("SELECT COUNT(DISTINCT ip_src) FROM acid_event ".
"INNER JOIN acid_ip_cache ON ipc_ip = ip_src ".
"WHERE ipc_whois is not NULL");
$row = $ip_result->baseFetchRow();
$ip_result->baseFreeRows();
$cached_swhois_cnt = $row[0];
$ip_result = $db->baseExecute("SELECT COUNT(DISTINCT ip_dst) FROM acid_event ".
"INNER JOIN acid_ip_cache ON ipc_ip = ip_dst ".
"WHERE ipc_whois is not NULL");
$row = $ip_result->baseFetchRow();
$ip_result->baseFreeRows();
$cached_dwhois_cnt = $row[0];
echo '<B>'._MNTIPACUSIP.'</B> '.$uncached_sip_cnt.'   '.
'<B>'._MNTIPACDNSC.'</B> '.$cached_sip_cnt.' '.
'<B>'._MNTIPACWC.'</B> '.$cached_swhois_cnt.'<BR>'.
'<B>'._MNTIPACUDIP.'</B> '.$uncached_dip_cnt.'   '.
'<B>'._MNTIPACDNSC.'</B> '.$cached_dip_cnt.' '.
'<B>'._MNTIPACWC.'</B> '.$cached_dwhois_cnt.'<BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Update IP Cache">
<INPUT TYPE="submit" NAME="submit" VALUE="Update Whois Cache"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Rebuild IP Cache">
<INPUT TYPE="submit" NAME="submit" VALUE="Rebuild Whois Cache"><BR>';
echo ' </TD></TR>
</TABLE>
</TD></TR>
</TABLE><P>';
echo "\n</FORM>\n";
PrintBASESubFooter();
$et->PrintTiming();
echo "</body>\r\n</html>";
?>