Location: PHPKode > projects > Cancerbero - The watchdog of the ports > cancerbero-0.6/site/first_install.php
<?php

$save = "";
if (isset($_POST["save"])) $save = $_POST["save"];


if ( $save == "save_database" ) {

	$name_db = trim($_POST['name_db']);
	$user_db = trim($_POST['user_db']);
	$pass_db = trim($_POST['pass_db']);
	$retype_pass_db = trim($_POST['retype_pass_db']);
	$host_db = trim($_POST['host_db']);
	$source_host = trim($_POST['source_host']);
	$admin = trim($_POST['admin']);
	$pass_admin = trim($_POST['pass_admin']);

	if ($retype_pass_db != $pass_db) {
		echo "<h1>User Passwords are diferent, try again</h1>";
	} elseif ( $pass_db == ""){
		echo "<h1>User Passwords are empty, try again</h1>";
	} else {
		$status_connect = mysql_connect($host_db, $admin, $pass_admin);
	
		$status = mysql_query ("GRANT USAGE ON * . * TO '$user_db'@'$source_host' IDENTIFIED BY '$pass_db'");
		if (!($status)) {
			//echo "User '$user_db'@'$host_db' already created<br>";
			mysql_query ("SET PASSWORD FOR '$user_db'@'$source_host' = PASSWORD('$pass_db')");
		}
	
		$status = mysql_query ("CREATE database $name_db");
		if (!($status)) {
			//echo "Database $name_db already created<br>";
			$result = mysql_query("SHOW TABLES FROM $name_db");
			if ( mysql_num_rows ($result) > 0) {
				//echo "try upgrade";
				$try_upgrade = "yes";
			}
		}
	
		mysql_query ("GRANT SELECT , INSERT , UPDATE , DELETE , CREATE , DROP , INDEX , ALTER , CREATE TEMPORARY TABLES ON $name_db . * TO $user_db@$source_host");
	
		mysql_close ($status_connect);
	
		$status_connect = mysql_connect($host_db, $user_db, $pass_db);
		$status_select = mysql_select_db($name_db);
	
		if ($status_connect && $status_select) {
	
			if ($file = fopen( "/etc/cancerbero/cancerbero.cfg",  "w+")) {
				fwrite($file,"#(AUTOGENERATED by cancerbero-gui) Be careful if you modify it.\n");
				fwrite($file,"#\n");
				fwrite($file,"# Configuration file of cancerbero. Edit to fit your needs.\n");
				fwrite($file,"#\n");
				fwrite($file,"\n");
				fwrite($file,"\$name_db = \"$name_db\";\n");
				fwrite($file,"\$user_db = \"$user_db\";\n");
				fwrite($file,"\$pass_db = \"$pass_db\";\n");
				fwrite($file,"\$host_db = \"$host_db\";\n");
				fwrite($file,"\n");
				fwrite($file,"\$nmap_bin=\"/usr/bin/nmap\";\n");
				fclose($file); // hemos terminado, cerramos el apuntador
			}
	
			if ($try_upgrade == "yes") {
				include_once ("upgrade.php");
				exit;
			} else {
				include_once ("include/cancerbero.php");
			}
	
		} else {
			echo "<h1>WARNING: Can't connect to the database with that values...try again the configuration.</h1>";
		}
	}
}
include ("index.php");

?>
Return current item: Cancerbero - The watchdog of the ports