2 /**********************************************************
3 *This file is meant for setting up database and user *
4 *that is needed for Iptables Analyzer. *
6 *2005 Sven Kauber <celeon@gmail.com> *
7 *This file is distributed under GPL License *
10 * -disable the need for exec - include data instead *
11 **********************************************************/
13 $SETUP = array('host','port','ipadmin','ipadminpass','ipuser','ipauserpass','rootuser','rootpass','dbname','urlbase','logfile');
17 //checks if some field was empty
18 //gets an array of values as parameter
22 for($i = 0; $i < count($SETUP); $i++
)
24 if(trim($_POST[$SETUP[$i]]) == '')
60 / \___\ \___\ \___\ \___\
62 \/___/\/___/\/___/\/___/
65 <!DOCTYPE HTML
PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
68 <META HTTP
-EQUIV
="Content-Type" CONTENT
="text/html; charset=ISO-8859-1">
69 <title
>.: IPtables Analyzer Installation
:.</title
>
70 <style type
="text/css">
73 font
-family
:Verdana
, Arial
, Helvetica
, sans
-serif
;
80 font
-family
:Verdana
, Arial
, Helvetica
, sans
-serif
;
85 border
-right
:#CC3333 1px solid;
86 border
-top
:#CC3333 1px solid;
87 border
-left
:#CC3333 1px solid;
88 border
-bottom
:#CC3333 1px solid;
93 font
-family
:Verdana
, Arial
, Helvetica
, sans
-serif
;
102 font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
;
112 border
-top
:#8B0000 1px solid;
113 border
-right
:#8B0000 1px solid;
114 border
-left
:#8B0000 1px solid;
115 border
-bottom
:#8B0000 1px solid;
119 font
-family
:Verdana
, Arial
, Helvetica
, sans
-serif
;
128 font
-family
: Verdana
, Arial
, Helvetica
, sans
-serif
;
144 font
-family
:Verdana
, Arial
, Helvetica
, sans
-serif
;
149 border
-right
:#8B0000 1px solid;
150 border
-top
:#8B0000 1px solid;
151 border
-left
:#8B0000 1px solid;
152 border
-bottom
:#8B0000 1px solid;
155 <script type
="text/javascript">
156 function rightFocus()
157 //puts the cursor to the right place: on host field
159 if(document
.forms
[0] != null && document
.forms
[0].name
== "settings")
161 document
.settings
.rootpass
.focus();
167 <body onLoad
="rightFocus();">
169 if(!isset($_POST['submit']))
171 //if was not submitted, print out the form
173 <form action
= "<?php echo($_SERVER['PHP_SELF']); ?>" method
= "post" name
="settings">
174 <table
class="content" border
="0">
177 <td rowspan
="3" valign
="top">
181 <td
><h1
>IPtables Analyzer Installation
</h1
></td
>
184 <td
>Make sure exec
- function is not disabled on php
.ini
, since it will be needed
for the automatic insertion of database data
!</td
>
193 <legend
class="rleg">Database information
</legend
>
194 <table border
="0" cellpadding
="0" cellspacing
="0">
197 <td
class="fieldd">host
:</td
>
198 <td
><input size
="30" maxlength
="50" class="field" type
="text" value
="localhost" name
="<?php echo($SETUP[0]); ?>"></td
>
201 <td
class="fieldd">port
:</td
>
202 <td
><input size
="30" maxlength
="50" class="field" type
="text" value
= "3406" name
="<?php echo($SETUP[1]); ?>"></td
>
205 <td
class="fieldd">database to be created
:</td
>
206 <td
><input size
="30" maxlength
="50" class="field" type
="text" value
="iptables" name
="<?php echo($SETUP[8]); ?>"></td
>
209 <td
class="fieldd">mysql root user
:</td
>
210 <td
><input size
="30" maxlength
="50" class="field" type
="text" value
= "root" name
="<?php echo($SETUP[6]); ?>"></td
>
213 <td
class="fieldd">mysql root user
's password:</td>
214 <td><input size="30" maxlength="50" class="field" type="password" name="<?php echo($SETUP[7]); ?>"></td>
221 <legend class="rleg">User information</legend>
222 <table border="0" cellpadding="0" cellspacing="0">
225 <td class="fieldd">admin:</td>
226 <td><input size="30" maxlength="50" class="field" type="text" value="ipadmin" name="<?php echo($SETUP[2]); ?>"></td>
229 <td class="fieldd">admin\'s password:</td>
230 <td><input size="30" maxlength="50" class="field" type="password" value = "1234" name="<?php echo($SETUP[3]); ?>"></td>
231 <td class="fieldf">(1234)</td>
234 <td class="fieldd">user:</td>
235 <td><input size="30" maxlength="50" class="field" type="text" value="ipuser" name="<?php echo($SETUP[4]); ?>"></td>
238 <td class="fieldd">user\'s password:</td>
239 <td><input size="30" maxlength="50" class="field" type="password" value = "1234" name="<?php echo($SETUP[5]); ?>"></td>
240 <td class="fieldf">(1234)</td>
247 <legend class="rleg">General information</legend>
248 <table border="0" cellpadding="0" cellspacing="0">
251 <td class="fieldd">access folder on server:</td>
252 <td><input size="30" maxlength="50" class="field" type="text" value="/iptables/" name="<?php echo($SETUP[9]); ?>"></td>
253 <td class="fieldf">(result is http://yourhost/iptables/)</td>
256 <td class="fieldd">location of the log file:</td>
257 <td><input size="30" maxlength="50" class="field" type="text" value="/var/log/iptables.log" name="<?php echo($SETUP[10]); ?>" /></td>
265 <td rowspan="3"><input class="input" type="submit" name="submit" value="Install!"></td>
276 //all the fields were not set
278 echo($NOTOK.'<br
/>You had some
empty text fields
!<br
/><a href
="./install.php">back
</a
>');
283 $DBNAME = trim($_POST[$SETUP[8]]);
284 $USER = trim($_POST[$SETUP[6]]);
285 $PASS = trim($_POST[$SETUP[7]]);
286 $HOST = trim($_POST[$SETUP[0]]);
287 $PORT = trim($_POST[$SETUP[1]]);
288 $IPADMIN = trim($_POST[$SETUP[2]]);
289 $IPUSER = trim($_POST[$SETUP[4]]);
290 $IPADMINPASS = trim($_POST[$SETUP[3]]);
291 $IPUSERPASS = trim($_POST[$SETUP[5]]);
292 $LOGFILE = trim($_POST[$SETUP[10]]);
293 $URLBASE = trim($_POST[$SETUP[9]]);
295 $link = mysql_connect($HOST,$USER,$PASS) or die("Mysql error occured: ".mysql_error());
296 //if not connected, call the page self with error message
298 //creating database and users and granting rights
299 $queries = array('create database iptables
;',
300 "grant create,select,insert on iptables.* to '$IPADMIN'@'$HOST' identified by '$IPADMINPASS';",
301 "grant select on iptables.* to '$IPUSER'@'$HOST' identified by '$IPUSERPASS';",
302 "grant create temporary tables on iptables.* to '$IPUSER'@'$HOST' identified by '$IPUSERPASS';");
303 for($i = 0; $i < count($queries); $i++)
304 mysql_query($queries[$i],$link) or die('Error occured
: '.mysql_error());
306 exec("cat sql/db.sql | mysql $DBNAME -u$IPADMIN -p$IPADMINPASS");
308 //editing config.php and feed_db.php - thanks cactus and other guys of Arch forums :)
309 $conf = 'config
.php
';
310 $match= array('/^
([ ]*)\
$db_host.*$
/m
',
311 '/^
([ ]*)\
$db_user.*$
/m
',
312 '/^
([ ]*)\
$db_password.*$
/m
',
313 '/^
([ ]*)\
$db_name.*$
/m
',
314 '/^
([ ]*)\
$url_base.*$
/m
');
317 $replace= array('$
{1}$db_host="'.$HOST.'";',
318 '$
{1}$db_user="'.$IPUSER.'";',
319 '$
{1}$db_password="'.$IPUSERPASS.'";',
320 '$
{1}$db_name="'.$DBNAME.'";',
321 '$
{1}$url_base="'.$URLBASE.'";');
322 $file = preg_replace($match,$replace,file_get_contents($conf));
323 file_put_contents ($conf, $file);
326 $pl = '/usr
/bin
/feed_db
.pl
';
327 $match = array('/^
([ ]*)my
.\
$dsn.*$
/m
',
328 '/^
([ ]*)my
.\
$db_user_name.*$
/m
',
329 '/^
([ ]*)my
.\
$db_password.*$
/m
',
330 '/^
([ ]*)my
.\
$log_file.*$
/m
');
331 $replace = array('$
{1}my
$dsn="DBI:mysql:'.$DBNAME.':'.$HOST.'";',
332 '$
{1}my
$db_user_name="'.$IPADMIN.'";',
333 '$
{1}my
$db_password="'.$IPADMINPASS.'";',
334 '$
{1}my
$log_file="'.$LOGFILE.'";');
335 $file = preg_replace($match,$replace,file_get_contents($pl));
336 file_put_contents ($pl, $file);
337 echo($OK.'<br
/>Now start the
daemon (/etc
/rc
.d
/iptlogd start
)
338 and <br
/><a href
="./">watch the logs
</a
>!');