if (!defined('WW_SESS')) { exit; } // updates go here $updates = array(); /* 2011-11-22 added fields to enable Google-friendly redirects */ $updates[] = array('action' => 'add', 'table' => 'articles', 'column' => 'redirect_code', 'type' => 'SMALLINT(3) NULL AFTER seo_keywords'); $updates[] = array('action' => 'add', 'table' => 'articles', 'column' => 'redirect_url', 'type' => 'VARCHAR(255) NULL AFTER redirect_code'); /* end of 2011-11-22 updates */ // run updates if (isset($_POST['run_updates'])) { $update_status = 'running updates...'; foreach ($updates as $to_update) { switch ($to_update['action']) { case 'add': $update_status .= add_column($to_update['table'], $to_update['column'], $to_update['type']); break; case 'drop': // commented out for safety - probably won't need this anyway // $update_status .= drop_column($to_update['table'],$to_update['column']); break; case 'change': $update_status .= change_column($to_update['table'], $to_update['column'], $to_update['type']); break; } } $update_status .= 'finished updates...'; } /** * check_table *
function csvToDB($url, $t_name) { $debug = array(); $table = file_get_contents($url); $tr = preg_split("/\r\n/", $table); $names = preg_split("/,/", $tr[0]); $cols = replaceWeirdChar($tr[0]); $insert = "insert into {$t_name} ({$cols})"; foreach ($names as $name) { $name = replaceWeirdChar($name); add_column($t_name, $name, "text"); } for ($count = 1; $count < count($tr); $count++) { $td = preg_split("/,/", $tr[$count]); $content = ''; for ($contador = 0; $contador < count($names); $contador++) { $content .= '"' . $td[$contador] . '",'; } $debug[] = "{$insert} values ({$content})<br/>" . count($names) . "<br/>"; } return $debug; }
add_column("mac_track_devices", "host_id", "ALTER TABLE `mac_track_devices` ADD COLUMN `host_id` int(10) unsigned NOT NULL default '0' AFTER `device_id`"); execute_sql("Speed up queries", "ALTER TABLE `mac_track_ports` ADD INDEX `scan_date` USING BTREE(`scan_date`)"); execute_sql("Add length to Device Types Match Fields", "ALTER TABLE `mac_track_device_types` MODIFY COLUMN `sysDescr_match` VARCHAR(100) NOT NULL default '', MODIFY COLUMN `sysObjectID_match` VARCHAR(100) NOT NULL default ''"); execute_sql("Correct a Scanning Function Bug", "DELETE FROM mac_track_scanning_functions WHERE scanning_function='Not Applicable - Hub/Switch'"); /* start Aggregated Changes */ create_table("mac_track_aggregated_ports", "CREATE TABLE mac_track_aggregated_ports (\n\t`row_id` int(10) unsigned NOT NULL auto_increment,\n\t`site_id` int(10) unsigned NOT NULL default '0',\n\t`device_id` int(10) unsigned NOT NULL default '0',\n\t`hostname` varchar(40) NOT NULL default '',\n\t`device_name` varchar(100) NOT NULL default '',\n\t`vlan_id` varchar(5) NOT NULL default 'N/A',\n\t`vlan_name` varchar(50) NOT NULL default '',\n\t`mac_address` varchar(20) NOT NULL default '',\n\t`vendor_mac` varchar(8) default NULL,\n\t`ip_address` varchar(20) NOT NULL default '',\n\t`dns_hostname` varchar(200) default '',\n\t`port_number` varchar(10) NOT NULL default '',\n\t`port_name` varchar(50) NOT NULL default '',\n\t`date_last` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n\t`first_scan_date` datetime NOT NULL default '0000-00-00 00:00:00',\n\t`count_rec` int(10) unsigned NOT NULL default '0',\n\t`active_last` tinyint(1) unsigned NOT NULL default '0',\n\t`authorized` tinyint(3) unsigned NOT NULL default '0',\n\tPRIMARY KEY (`row_id`),\n\tUNIQUE KEY `port_number` USING BTREE (`port_number`,`mac_address`,`ip_address`,`device_id`,`site_id`,`vlan_id`,`authorized`),\n\tKEY `site_id` (`site_id`),\n\tKEY `description` (`device_name`),\n\tKEY `mac` (`mac_address`),\n\tKEY `hostname` (`hostname`),\n\tKEY `vlan_name` (`vlan_name`),\n\tKEY `vlan_id` (`vlan_id`),\n\tKEY `device_id` (`device_id`),\n\tKEY `ip_address` (`ip_address`),\n\tKEY `port_name` (`port_name`),\n\tKEY `dns_hostname` (`dns_hostname`),\n\tKEY `vendor_mac` (`vendor_mac`),\n\tKEY `authorized` (`authorized`),\n\tKEY `site_id_device_id` (`site_id`,`device_id`))\n\tENGINE=MyISAM COMMENT='Database for aggregated date for Tracking Device MAC''s';"); # new for 2.1.2 # SNMP V3 add_column("mac_track_devices", "snmp_options", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_options` int(10) unsigned NOT NULL default '0' AFTER `user_password`"); add_column("mac_track_devices", "snmp_username", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_username` varchar(50) default NULL AFTER `snmp_status`"); add_column("mac_track_devices", "snmp_password", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_password` varchar(50) default NULL AFTER `snmp_username`"); add_column("mac_track_devices", "snmp_auth_protocol", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_auth_protocol` char(5) default '' AFTER `snmp_password`"); add_column("mac_track_devices", "snmp_priv_passphrase", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_priv_passphrase` varchar(200) default '' AFTER `snmp_auth_protocol`"); add_column("mac_track_devices", "snmp_priv_protocol", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_priv_protocol` char(6) default '' AFTER `snmp_priv_passphrase`"); add_column("mac_track_devices", "snmp_context", "ALTER TABLE `mac_track_devices` ADD COLUMN `snmp_context` varchar(64) default '' AFTER `snmp_priv_protocol`"); add_column("mac_track_devices", "max_oids", "ALTER TABLE `mac_track_devices` ADD COLUMN `max_oids` int(12) unsigned default '10' AFTER `snmp_context`"); create_table("mac_track_snmp", "CREATE TABLE `mac_track_snmp` (\n\t\t\t`id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t`name` varchar(100) NOT NULL default '',\n\t\t\tPRIMARY KEY (`id`))\n\t\t\tENGINE=MyISAM COMMENT='Group of SNMP Option Sets';"); create_table("mac_track_snmp_items", "CREATE TABLE `mac_track_snmp_items` (\n\t\t\t`id` int(10) unsigned NOT NULL auto_increment,\n\t\t\t`snmp_id` int(10) unsigned NOT NULL default '0',\n\t\t\t`sequence` int(10) unsigned NOT NULL default '0',\n\t\t\t`snmp_version` varchar(100) NOT NULL default '',\n\t\t\t`snmp_readstring` varchar(100) NOT NULL,\n\t\t\t`snmp_port` int(10) NOT NULL default '161',\n\t\t\t`snmp_timeout` int(10) unsigned NOT NULL default '500',\n\t\t\t`snmp_retries` tinyint(11) unsigned NOT NULL default '3',\n\t\t\t`max_oids` int(12) unsigned default '10',\n\t\t\t`snmp_username` varchar(50) default NULL,\n\t\t\t`snmp_password` varchar(50) default NULL,\n\t\t\t`snmp_auth_protocol` char(5) default '',\n\t\t\t`snmp_priv_passphrase` varchar(200) default '',\n\t\t\t`snmp_priv_protocol` char(6) default '',\n\t\t\t`snmp_context` varchar(64) default '',\n\t\t\tPRIMARY KEY (`id`,`snmp_id`))\n\t\t\tENGINE=MyISAM COMMENT='Set of SNMP Options';"); echo "\nDatabase Upgrade Complete\n"; function execute_sql($message, $syntax) { $result = db_execute($syntax); if ($result) { echo "SUCCESS: Execute SQL, {$message}, Ok\n"; } else { echo "ERROR: Execute SQL, {$message}, Failed!\n"; } } function create_table($table, $syntax) { $tables = db_fetch_assoc("SHOW TABLES LIKE '{$table}'");
<?php require_once 'util/main.php'; require_once 'util/db_function.php'; add_column();