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

# Script to change a cancerbero's database version 3 to version 4

include_once("dbconnect.php");

$database_ver = 4;

$upgrade_version = mysql_query("UPDATE `configuration` SET `database_ver` = ( -1 ) * `database_ver` WHERE 1") or die (mysql_error());

$query = mysql_query("ALTER TABLE `configuration` CHANGE `database_ver` `database_ver` INT( 3 ) NOT NULL DEFAULT '1'") or die (mysql_error());

$query = mysql_query ("ALTER DATABASE `$name_db` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());	


$query = mysql_query ("CREATE TABLE IF NOT EXISTS `alerts` (
  		       `alert_id` int(21) NOT NULL auto_increment,
  		       `last_scan_id` int(10) NOT NULL default '0',
  		       `old_scan_id` int(10) NOT NULL default '0',
  		       `alert_name` varchar (100) NOT NULL,
  		       `alert_checked` ENUM( 'unchecked', 'checked' ) NOT NULL,
  		       `message` varchar(254) default NULL,

  		       PRIMARY KEY  (`alert_id`)
		       ) ENGINE=MyISAM DEFAULT CHARSET=utf8") or die (mysql_error());

$query = mysql_query ("CREATE TABLE IF NOT EXISTS `alert_type` (
 		       `alert_name` varchar(100) NOT NULL, 
		       `status` ENUM( 'on', 'off' ) NOT NULL,
		       `alert_level` ENUM( 'Soft', 'Medium', 'Critical', 'Doom' ) NOT NULL,
		       `description` varchar(254) default NULL,
		       `plugin_name` varchar(100) NOT NULL,

 		       PRIMARY KEY  (`alert_name`)
		       ) ENGINE=MyISAM DEFAULT CHARSET=utf8") or die (mysql_error());

$query = mysql_query ("CREATE TABLE IF NOT EXISTS `plugins` (
 		      `plugin_name` varchar(100) NOT NULL, 
 		      `status` ENUM( 'on', 'off' ) NOT NULL,
		      `description` varchar(255) default NULL,
		      `version` varchar(10) default NULL,

 		      PRIMARY KEY  (`plugin_name`)
		      ) ENGINE=MyISAM DEFAULT CHARSET=utf8") or die (mysql_error());

$query = mysql_query ("CREATE TABLE IF NOT EXISTS `owners` (
  		      `owner_id` int(21) NOT NULL auto_increment,
 		      `name` varchar(100) NOT NULL,
 		      `email` varchar(100) NOT NULL,
 		      `telephone` varchar(15) DEFAULT NULL,
 		      `section` varchar(20) DEFAULT NULL,

 		      PRIMARY KEY  (`owner_id`)
		      ) ENGINE=MyISAM DEFAULT CHARSET=utf8") or die (mysql_error());

$query = mysql_query ("CREATE TABLE IF NOT EXISTS `send_alerts` (
 		      `owner_id` int(21) NOT NULL auto_increment,
		      `alert_name` varchar(100) default NULL,
  		      `object` ENUM( 'Host', 'Range','Sensor', 'God', 'Other' ) NOT NULL,
  		      `object_index` int(21) NOT NULL,

  		      PRIMARY KEY  (`owner_id`, `alert_name`, `object`, `object_index`)
	 	      ) ENGINE=MyISAM DEFAULT CHARSET=utf8") or die (mysql_error());	

$query = mysql_query ("CREATE TABLE IF NOT EXISTS `ownership` (
 		      `object` ENUM( 'Host', 'Range','Sensor', 'God' ) NOT NULL,
		      `object_index` int(21) NOT NULL,
		      `owner_id` int(21) NOT NULL,

		      PRIMARY KEY  (`object`, `object_index`, `owner_id`)
		      ) ENGINE=MyISAM DEFAULT CHARSET=utf8") or die (mysql_error());	

$query = mysql_query ("ALTER TABLE `configuration` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `hosts` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `hosts` CHANGE `ip` `ip` VARCHAR( 16 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `hosts` CHANGE `hostname` `hostname` VARCHAR( 64 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `hosts` CHANGE `comment` `comment` VARCHAR( 255 ) default NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `logs` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `logs` CHANGE `name_proc` `name_proc` VARCHAR( 32 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `logs` CHANGE `facility` `facility` VARCHAR( 32 ) NULL DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `logs` CHANGE `priority` `priority` VARCHAR( 32 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `logs` CHANGE `message` `message` VARCHAR( 255 ) NOT NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `nmap_cfg` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `nmap_cfg` CHANGE `nmap_type_cfg` `nmap_type_cfg` ENUM( 'Sweep', 'Scan' ) NOT NULL DEFAULT 'Sweep'") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `nmap_cfg` CHANGE `nmap_option_name` `nmap_option_name` VARCHAR( 32 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `nmap_cfg` CHANGE `nmap_cmd_cfg` `nmap_cmd_cfg` VARCHAR( 255 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("UPDATE `nmap_cfg` SET `nmap_cmd_cfg` = '-A -T4 -PA445,22 -PS445,22 --host_timeout 900000 -p -' WHERE `nmap_type_cfg` = 'Scan' AND `nmap_option_name` = 'Polite'") or die (mysql_error());
$query = mysql_query ("UPDATE `nmap_cfg` SET `nmap_cmd_cfg` = '-A -r -T5 -PA445,22 -PS445,22 -PE --host_timeout 900000 -p -' WHERE `nmap_type_cfg` = 'Scan' AND `nmap_option_name` = 'Normal'") or die (mysql_error());
$query = mysql_query ("UPDATE `nmap_cfg` SET `nmap_cmd_cfg` = '-A -r -PA445,22 -PS445,22 -PE -p - --max_rtt_timeout 100 --min_rtt_timeout 10 --host_timeout 900000 --initial_rtt_timeout 50 --max_scan_delay 5' WHERE `nmap_type_cfg` = 'Scan' AND `nmap_option_name` = 'Aggressive'") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `ports` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `protocol` `protocol` VARCHAR( 10 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `service` `service` VARCHAR( 20 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `fingerprint` `fingerprint` VARCHAR( 255 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `product` `product` VARCHAR( 255 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `extra_info` `extra_info` VARCHAR( 255 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `port_version` `port_version` VARCHAR( 255 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ports` CHANGE `service_confidence` `service_confidence` VARCHAR( 255 ) DEFAULT NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `program_values` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `program_values` CHANGE `status_sweep` `status_sweep` VARCHAR( 25 ) DEFAULT NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `ranges` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ranges` CHANGE `range` `range` VARCHAR( 18 ) NOT NULL;") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ranges` ADD `range_name` varchar(100) default NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `ranges` ADD `comment` varchar(255) default NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `scans` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `scans` CHANGE `os_guessed` `os_guessed` VARCHAR( 100 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `scans` CHANGE `os_gen` `os_gen` VARCHAR( 100 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `scans` CHANGE `host_fingerprint` `host_fingerprint` VARCHAR( 254 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `scans` ADD `number_of_alerts` INT( 3 ) DEFAULT '0' NOT NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `sensors` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `sensors` CHANGE `sensor_name` `sensor_name` VARCHAR( 20 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `sensors` CHANGE `cancerbero_sensor_ver` `cancerbero_sensor_ver` VARCHAR( 8 ) NOT NULL DEFAULT '0';
") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `sensors` ADD `comment` varchar(255) default NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `users` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `users` CHANGE `email` `email` VARCHAR( 100 ) NOT NULL") or die (mysql_error());

$query = mysql_query ("ALTER TABLE `white_list` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `white_list` CHANGE `white_list` `white_list` VARCHAR( 18 ) NOT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `white_list` CHANGE `comment` `comment` VARCHAR( 255 ) DEFAULT NULL") or die (mysql_error());
$query = mysql_query ("ALTER TABLE `white_list` ADD `white_list_name` varchar(100) default NULL AFTER `white_list`") or die (mysql_error());

$upgrade_version = mysql_query("UPDATE configuration SET database_ver= $database_ver") or die (mysql_error());
?>
Return current item: Cancerbero - The watchdog of the ports