updated on Thu Jan 26 12:02:26 UTC 2012
[aur-mirror.git] / iptlogger / install.php
blob4694fc30a8b802e04174ae0cbcc97df37be3a3b3
1 <?php
2 /**********************************************************
3 *This file is meant for setting up database and user *
4 *that is needed for Iptables Analyzer. *
5 * *
6 *2005 Sven Kauber <celeon@gmail.com> *
7 *This file is distributed under GPL License *
8 * *
9 * Todo: *
10 * -disable the need for exec - include data instead *
11 **********************************************************/
13 $SETUP = array('host','port','ipadmin','ipadminpass','ipuser','ipauserpass','rootuser','rootpass','dbname','urlbase','logfile');
14 ob_start();
16 function isAllSet()
17 //checks if some field was empty
18 //gets an array of values as parameter
20 global $SETUP;
21 $res = true;
22 for($i = 0; $i < count($SETUP); $i++)
24 if(trim($_POST[$SETUP[$i]]) == '')
26 $res = false;
27 break;
30 return $res;
33 $OK = '
34 <pre>
35 All went OK!
37 /(|
38 ( :
39 __\ \ _____
40 (____) `|
41 (____)| |
42 (____).__|
43 (___)__.|_____
45 </pre>';
47 $NOTOK = '
48 <pre>
49 ____
50 /\ \
51 / \___\
52 _\ / __/_
53 /\ \/_/\ \
54 / \___\ \___\
55 _\ / / / __/_
56 /\ \/___/\/_/\ \
57 / \___\ / \___\
58 _\ / __/_ _\ / __/_
59 /\ \/_/\ \/\ \/_/\ \
60 / \___\ \___\ \___\ \___\
61 \ / / / / / / /itz/
62 \/___/\/___/\/___/\/___/
63 </pre>';
65 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
66 <html>
67 <head>
68 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
69 <title>.: IPtables Analyzer Installation :.</title>
70 <style type="text/css">
71 body
73 font-family:Verdana, Arial, Helvetica, sans-serif;
74 font-size: 9px;
75 color: #000000;
76 background: #ECF0F8;
78 .field
80 font-family:Verdana, Arial, Helvetica, sans-serif;
81 background:#F3F7FF;
82 color: #000000;
83 font-size:9px;
84 color:#000000;
85 border-right:#CC3333 1px solid;
86 border-top:#CC3333 1px solid;
87 border-left:#CC3333 1px solid;
88 border-bottom:#CC3333 1px solid;
89 margin-left: 10px;
91 .fieldf
93 font-family:Verdana, Arial, Helvetica, sans-serif;
94 color: #000000;
95 font-size:9px;
96 color:#000000;
97 margin-left: 10px;
100 .rleg
102 font-family: Verdana, Arial, Helvetica, sans-serif;
103 font-size: 9px;
104 color:#8B0000;
105 font-weight: bold;
106 background: #800000;
107 color: #ECF0F8;
109 .content
111 width: 780px;
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;
120 font-size:14px;
121 color:#800000;
122 background: none;
123 font-weight:bold;
124 text-align: left;
128 font-family: Verdana, Arial, Helvetica, sans-serif;
129 font-size: 12px;
130 color: #8B0000;
131 background: none;
132 font-weight: bold;
133 text-align: left;
135 .fieldd
137 text-align: left;
138 font-size: 9px;
139 width: 160px;
141 .input
143 text-align: left;
144 font-family:Verdana, Arial, Helvetica, sans-serif;
145 background:#F3F7FF;
146 color: #000000;
147 font-size: 9px;
148 color:#000000;
149 border-right:#8B0000 1px solid;
150 border-top:#8B0000 1px solid;
151 border-left:#8B0000 1px solid;
152 border-bottom:#8B0000 1px solid;
154 </style>
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();
164 </script>
166 </head>
167 <body onLoad="rightFocus();">
168 <?php
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">
175 <tbody>
176 <tr>
177 <td rowspan="3" valign="top">
178 <table>
179 <tbody>
180 <tr>
181 <td><h1>IPtables Analyzer Installation</h1></td>
182 </tr>
183 <tr>
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>
185 </tr>
186 </tbody>
187 </table>
188 </td>
189 </tr>
190 <tr>
191 <td>
192 <fieldset>
193 <legend class="rleg">Database information</legend>
194 <table border="0" cellpadding="0" cellspacing="0">
195 <tbody>
196 <tr>
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>
199 </tr>
200 <tr>
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>
203 </tr>
204 <tr>
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>
207 </tr>
208 <tr>
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>
211 </tr>
212 <tr>
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>
215 </tr>
216 </tbody>
217 </table>
218 </fieldset>
219 <br />
220 <fieldset>
221 <legend class="rleg">User information</legend>
222 <table border="0" cellpadding="0" cellspacing="0">
223 <tbody>
224 <tr>
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>
227 </tr>
228 <tr>
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>
232 </tr>
233 <tr>
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>
236 </tr>
237 <tr>
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>
241 </tr>
242 </tbody>
243 </table>
244 </fieldset>
245 <br />
246 <fieldset>
247 <legend class="rleg">General information</legend>
248 <table border="0" cellpadding="0" cellspacing="0">
249 <tbody>
250 <tr>
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>
254 </tr>
255 <tr>
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>
258 </tr>
259 </tbody>
260 </table>
261 </fieldset>
262 </td>
263 </tr>
264 <tr>
265 <td rowspan="3"><input class="input" type="submit" name="submit" value="Install!"></td>
266 </tr>
267 </tbody>
268 </table>
269 </form>;
270 <?php
272 else
273 //form was submitted
275 if(!isAllSet())
276 //all the fields were not set
278 echo($NOTOK.'<br />You had some empty text fields!<br /><a href="./install.php">back</a>');
280 else
282 //getting the values
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);
325 //usr/bin/feed_db.pl
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>!');
341 <?php
344 </body>
345 </html>
346 <?php
347 ob_end_flush();