function mikrotik_check_upgrade() { global $config, $database_default; include_once $config['library_path'] . '/database.php'; include_once $config['library_path'] . '/functions.php'; // Let's only run this check if we are on a page that actually needs the data $files = array('plugins.php', 'mikrotik.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } $version = mikrotik_version(); $current = $version['version']; $old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='mikrotik'"); if ($current != $old) { if (api_plugin_is_enabled('mikrotik')) { api_plugin_enable_hooks('mikrotik'); } db_execute("ALTER TABLE plugin_mikrotik_trees ADD COLUMN prevPackets BIGINT UNSIGNED default NULL AFTER prevBytes"); db_execute("ALTER TABLE plugin_mikrotik_trees ADD COLUMN prevHCBytes BIGINT UNSIGNED default NULL AFTER prevPackets"); db_execute("ALTER TABLE plugin_mikrotik_trees ADD COLUMN curBytes BIGINT UNSIGNED default null AFTER HCBytes"); db_execute("ALTER TABLE plugin_mikrotik_trees ADD COLUMN curPackets BIGINT UNSIGNED default null AFTER curBytes"); db_execute("ALTER TABLE plugin_mikrotik_trees ADD COLUMN curHCBytes BIGINT UNSIGNED default null AFTER curPackets"); db_execute("ALTER TABLE plugin_mikrotik_system ADD COLUMN firmwareVersion varchar(20) NOT NULL default '' AFTER sysLocation"); db_execute("ALTER TABLE plugin_mikrotik_system ADD COLUMN licVersion varchar(20) NOT NULL default '' AFTER firmwareVersion"); db_execute("ALTER TABLE plugin_mikrotik_system ADD COLUMN softwareID varchar(20) NOT NULL default '' AFTER licVersion"); db_execute("ALTER TABLE plugin_mikrotik_system ADD COLUMN serialNumber varchar(20) NOT NULL default '' AFTER softwareID"); db_execute("UPDATE plugin_config SET version='{$current}' WHERE directory='mikrotik'"); db_execute('UPDATE plugin_config SET ' . "version='" . $version['version'] . "', " . "name='" . $version['longname'] . "', " . "author='" . $version['author'] . "', " . "webpage='" . $version['url'] . "' " . "WHERE directory='" . $version['name'] . "' "); } }
function mikrotik_check_upgrade() { global $config, $database_default; include_once $config["library_path"] . "/database.php"; include_once $config["library_path"] . "/functions.php"; // Let's only run this check if we are on a page that actually needs the data $files = array('plugins.php', 'mikrotik.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } $version = mikrotik_version(); $current = $version['version']; $old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='mikrotik'"); if ($current != $old) { if (api_plugin_is_enabled('mikrotik')) { api_plugin_enable_hooks('mikrotik'); } db_execute("UPDATE plugin_config SET version='{$current}' WHERE directory='mikrotik'"); db_execute("UPDATE plugin_config SET " . "version='" . $version["version"] . "', " . "name='" . $version["longname"] . "', " . "author='" . $version["author"] . "', " . "webpage='" . $version["url"] . "' " . "WHERE directory='" . $version["name"] . "' "); } }
function api_plugin_enable($plugin) { $ready = api_plugin_check_config($plugin); if ($ready) { api_plugin_enable_hooks($plugin); db_execute("UPDATE plugin_config SET status = 1 WHERE directory = '{$plugin}'"); } }
function mactrack_check_upgrade () { global $config; if (defined('CACTI_BASE_PATH')) { $config["base_path"] = CACTI_BASE_PATH; } include_once($config["base_path"] . "/plugins/mactrack/lib/mactrack_functions.php"); $files = array('index.php', 'plugins.php', 'mactrack_devices.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } $current = plugin_mactrack_version(); $current = $current['version']; $old = db_fetch_row("SELECT * FROM plugin_config WHERE directory='mactrack'"); if (!sizeof($old) || $current != $old["version"]) { /* if the plugin is installed and/or active */ if (!sizeof($old) || $old["status"] == 1 || $old["status"] == 4) { /* re-register the hooks */ plugin_mactrack_install(); if (api_plugin_is_enabled('mactrack')) { # may sound ridiculous, but enables new hooks api_plugin_enable_hooks('mactrack'); } /* perform a database upgrade */ mactrack_database_upgrade(); } if (read_config_option("mt_convert_readstrings", true) != "on") { convert_readstrings(); } /* rebuild the scanning functions */ mactrack_rebuild_scanning_funcs(); /* update the plugin information */ $info = plugin_mactrack_version(); $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='mactrack'"); db_execute("UPDATE plugin_config SET name='" . $info["longname"] . "', author='" . $info["author"] . "', webpage='" . $info["homepage"] . "', version='" . $info["version"] . "' WHERE id='$id'"); } }
function thold_upgrade_database() { global $config, $database_default; include_once $config['library_path'] . '/database.php'; thold_setup_database(); include_once $config['base_path'] . '/plugins/thold/setup.php'; include_once $config['base_path'] . '/plugins/thold/thold_functions.php'; $v = plugin_thold_version(); $oldv = read_config_option('plugin_thold_version'); if ($oldv < 0.1) { db_execute('INSERT INTO settings (name, value) VALUES ("plugin_thold_version", "' . $v['version'] . '")'); $oldv = $v['version']; } // Check for needed Cacti Indexes $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM graph_templates_item"), "Key_name", "Key_name"); if (!array_key_exists("task_item_id", $indexes)) { db_execute("ALTER TABLE graph_templates_item ADD INDEX task_item_id(task_item_id)"); } $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM data_local"), "Key_name", "Key_name"); if (!array_key_exists("data_template_id", $indexes)) { db_execute("ALTER TABLE data_local ADD INDEX data_template_id(data_template_id)"); } if (!array_key_exists("snmp_query_id", $indexes)) { db_execute("ALTER TABLE data_local ADD INDEX snmp_query_id(snmp_query_id)"); } $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM host_snmp_cache"), "Key_name", "Key_name"); if (!array_key_exists("snmp_query_id", $indexes)) { db_execute("ALTER TABLE host_snmp_cache ADD INDEX snmp_query_id(snmp_query_id)"); } $indexes = array_rekey(db_fetch_assoc("SHOW INDEX FROM data_template_rrd"), "Key_name", "Key_name"); if (!array_key_exists("data_source_name", $indexes)) { db_execute("ALTER TABLE data_template_rrd ADD INDEX data_source_name(data_source_name)"); } // Added in thold v0.4 if ($oldv < 0.4) { api_plugin_db_add_column('thold', 'thold_data', array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '', 'after' => 'id')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'thold_fail_trigger')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'time_hi')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_low')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_fail_trigger')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'thold_enabled')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'data_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'notify_extra')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => 0, 'after' => 'cdef')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'tcheck', 'type' => 'int(1)', 'NULL' => false, 'default' => 0)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'local_graph_id', 'type' => 'int(11)', 'NULL' => false, 'default' => 0, 'after' => 'data_id')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'graph_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => 0, 'after' => 'graph_id')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'data_template_id', 'type' => 'int(11)', 'NULL' => false, 'default' => 0, 'after' => 'graph_template')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'name', 'type' => 'varchar(100)', 'NULL' => false, 'default' => '', 'after' => 'id')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_hi', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'thold_fail_trigger')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_low', 'type' => 'varchar(100)', 'NULL' => true, 'after' => 'time_hi')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_low')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1, 'after' => 'time_fail_trigger')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'thold_enabled')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'data_type', 'type' => 'int (3)', 'NULL' => false, 'default' => 0, 'after' => 'syslog_priority')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'percent_ds', 'type' => 'varchar(64)', 'NULL' => false, 'default' => 0, 'after' => 'cdef')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'exempt', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'restored_alert', 'type' => 'char(3)', 'NULL' => false, 'default' => '')); // Update our hooks db_execute('UPDATE plugin_hooks SET file = "includes/settings.php" WHERE name = "thold" AND hook = "config_arrays"'); db_execute('UPDATE plugin_hooks SET file = "includes/settings.php" WHERE name = "thold" AND hook = "config_settings"'); db_execute('UPDATE plugin_hooks SET file = "includes/settings.php" WHERE name = "thold" AND hook = "draw_navigation_text"'); db_execute('UPDATE plugin_hooks SET function = "thold_poller_bottom", file = "includes/polling.php" WHERE name = "thold" AND hook = "poller_bottom"'); // Register the new hooks api_plugin_register_hook('thold', 'rrd_graph_graph_options', 'thold_rrd_graph_graph_options', 'setup.php'); api_plugin_register_hook('thold', 'graph_buttons', 'thold_graph_button', 'setup.php'); api_plugin_register_hook('thold', 'data_source_action_array', 'thold_data_source_action_array', 'setup.php'); api_plugin_register_hook('thold', 'data_source_action_prepare', 'thold_data_source_action_prepare', 'setup.php'); api_plugin_register_hook('thold', 'data_source_action_execute', 'thold_data_source_action_execute', 'setup.php'); api_plugin_register_hook('thold', 'graphs_action_array', 'thold_graphs_action_array', 'setup.php'); api_plugin_register_hook('thold', 'graphs_action_prepare', 'thold_graphs_action_prepare', 'setup.php'); api_plugin_register_hook('thold', 'graphs_action_execute', 'thold_graphs_action_execute', 'setup.php'); api_plugin_enable_hooks('thold'); // Fix our realms db_execute('UPDATE plugin_realms SET file = "thold.php" WHERE display = "Configure Thresholds"'); api_plugin_register_realm('thold', 'thold_templates.php', 'Configure Threshold Templates', 1); db_execute('ALTER TABLE thold_data ADD INDEX ( tcheck )', FALSE); db_execute('ALTER TABLE thold_data ADD INDEX ( local_graph_id )', FALSE); db_execute('ALTER TABLE thold_data ADD INDEX ( graph_template_id )', FALSE); db_execute('ALTER TABLE thold_data ADD INDEX ( data_template_id )', FALSE); // Rename some columns db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN rra_id local_data_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_id data_template_rrd_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN template thold_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_template data_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_template graph_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE plugin_thold_log CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); /* Set the default names on threshold and templates */ db_execute("UPDATE thold_data, data_template_data, data_template_rrd SET\n\t\t\t thold_data.name = CONCAT_WS('',data_template_data.name_cache, ' [', data_template_rrd.data_source_name, ']', '')\n\t\t\t WHERE data_template_data.local_data_id = thold_data.local_data_id AND data_template_rrd.id = thold_data.data_template_rrd_id AND thold_data.name = ''"); db_execute("UPDATE thold_template SET name = CONCAT_WS('', data_template_name, ' [', data_source_name, ']', '') WHERE name = ''"); /* Set the graph_ids for all thresholds */ db_execute('UPDATE thold_data, graph_templates_item, data_template_rrd SET thold_data.local_graph_id = graph_templates_item.local_graph_id, thold_data.graph_template_id = graph_templates_item.graph_template_id, thold_data.data_template_id = data_template_rrd.data_template_id WHERE data_template_rrd.local_data_id=thold_data.local_data_id AND data_template_rrd.id=graph_templates_item.task_item_id'); } // End 0.4 Upgrade if (version_compare($oldv, '0.4.3', '<')) { // Fix a few hooks db_execute('DELETE FROM plugin_hooks WHERE name = "thold" AND hook = "config_insert"'); db_execute('DELETE FROM plugin_hooks WHERE name = "thold" AND hook = "config_arrays"'); api_plugin_register_hook('thold', 'config_insert', 'thold_config_insert', 'includes/settings.php'); api_plugin_register_hook('thold', 'config_arrays', 'thold_config_arrays', 'includes/settings.php'); api_plugin_enable_hooks('thold'); $e = strtolower(db_fetch_cell("SELECT `value` FROM settings WHERE `name` = 'thold_from_email'")); if ($e == '*****@*****.**') { db_execute("UPDATE settings SET `value`='cacti@localhost' WHERE `name`='thold_from_email'"); } } if (version_compare($oldv, '0.4.4', '<')) { api_plugin_db_add_column('thold', 'thold_data', array('name' => 'lasttime', 'type' => 'TIMESTAMP', 'NULL' => false, 'after' => 'lastread')); db_execute('ALTER TABLE thold_data ADD COLUMN bl_thold_valid INT UNSIGNED NOT NULL DEFAULT 0', FALSE); db_execute('ALTER TABLE thold_data MODIFY name varchar(150) default NULL'); db_execute('ALTER TABLE thold_template MODIFY COLUMN bl_pct_down varchar(100)'); db_execute('ALTER TABLE thold_template MODIFY COLUMN bl_pct_up varchar(100)'); db_execute('ALTER TABLE thold_data MODIFY COLUMN bl_pct_down varchar(100)'); db_execute('ALTER TABLE thold_data MODIFY COLUMN bl_pct_up varchar(100)'); } if (version_compare($oldv, '0.4.5', '<')) { api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'notify_warning_extra', 'type' => 'text', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_fail_trigger', 'type' => 'int(10)', 'NULL' => true, 'unsigned' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_warning_fail_count', 'type' => 'int(11)', 'NULL' => false, 'default' => '0')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_hi', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_low', 'type' => 'varchar(100)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_fail_trigger', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'time_warning_fail_length', 'type' => 'int (12)', 'NULL' => false, 'default' => 1)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'notify_warning_extra', 'type' => 'text', 'NULL' => true)); db_execute('ALTER TABLE thold_data MODIFY COLUMN notify_extra text'); db_execute('ALTER TABLE thold_template MODIFY COLUMN notify_extra text'); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'name', 'type' => 'varchar(128)', 'NULL' => false); $data['columns'][] = array('name' => 'description', 'type' => 'varchar(512)', 'NULL' => false); $data['columns'][] = array('name' => 'emails', 'type' => 'varchar(512)', 'NULL' => false); $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Notification Lists'; api_plugin_db_table_create('thold', 'plugin_notification_lists', $data); api_plugin_db_add_column('thold', 'host', array('name' => 'thold_send_email', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'disabled')); api_plugin_db_add_column('thold', 'host', array('name' => 'thold_host_email', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => true, 'after' => 'thold_send_email')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'notify_warning', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'notify_alert', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'notify_warning', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'notify_alert', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '1', 'after' => 'notify_warning_extra')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'hash', 'type' => 'varchar(32)', 'NULL' => true, 'after' => 'id')); db_execute("ALTER TABLE thold_data REMOVE COLUMN bl_enabled", FALSE); db_execute("ALTER TABLE thold_template REMOVE COLUMN bl_enabled", FALSE); api_plugin_register_hook('thold', 'config_form', 'thold_config_form', 'includes/settings.php'); api_plugin_register_realm('thold', 'notify_lists.php', 'Plugin -> Manage Notification Lists', 1); /* set unique hash values for all thold templates */ $templates = db_fetch_assoc("SELECT id FROM thold_template"); if (sizeof($templates)) { foreach ($templates as $t) { $hash = get_hash_thold_template($t['id']); db_execute("UPDATE thold_template SET hash='{$hash}' WHERE id=" . $t['id']); } } } if (version_compare($oldv, '0.4.7', '<')) { $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(12)', 'NULL' => false, 'unsigned' => true, 'auto_increment' => true); $data['columns'][] = array('name' => 'host_id', 'type' => 'int(12)', 'unsigned' => true, 'NULL' => false); $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Devices in a Down State'; api_plugin_db_table_create('thold', 'plugin_thold_host_failed', $data); db_execute("DELETE FROM settings WHERE name='thold_failed_hosts'"); /* increase the size of the settings table */ db_execute("ALTER TABLE settings MODIFY column `value` varchar(1024) not null default ''"); } if (version_compare($oldv, '0.6', '<')) { api_plugin_db_add_column('thold', 'thold_data', array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2')); api_plugin_db_add_column('thold', 'thold_data', array('name' => 'thold_daemon_pid', 'type' => 'varchar(25)', 'NULL' => false, 'default' => '')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'snmp_event_category', 'type' => 'varchar(255)', 'NULL' => true)); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'snmp_event_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '3')); api_plugin_db_add_column('thold', 'thold_template', array('name' => 'snmp_event_warning_severity', 'type' => 'tinyint(1)', 'NULL' => false, 'default' => '2')); $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'NULL' => false); $data['columns'][] = array('name' => 'pid', 'type' => 'varchar(25)', 'NULL' => false); $data['columns'][] = array('name' => 'rrd_reindexed', 'type' => 'varchar(600)', 'NULL' => false); $data['columns'][] = array('name' => 'rrd_time_reindexed', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false); $data['keys'][] = array('name' => 'id', 'columns' => 'id`, `pid'); $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Poller Outdata needed for queued daemon processes'; api_plugin_db_table_create('thold', 'plugin_thold_daemon_data', $data); $data = array(); $data['columns'][] = array('name' => 'pid', 'type' => 'varchar(25)', 'NULL' => false); $data['columns'][] = array('name' => 'start', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'end', 'type' => 'int(10)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'processed_items', 'type' => 'mediumint(8)', 'NULL' => false, 'default' => '0'); $data['primary'] = 'pid'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Thold Daemon Processes being queued'; api_plugin_db_table_create('thold', 'plugin_thold_daemon_processes', $data); // Rename some columns db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN rra_id local_data_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_id data_template_rrd_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN template thold_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN data_template data_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE thold_data CHANGE COLUMN graph_template graph_template_id int(11) UNSIGNED NOT NULL default "0"'); db_execute('ALTER IGNORE TABLE plugin_thold_log CHANGE COLUMN graph_id local_graph_id int(11) UNSIGNED NOT NULL default "0"'); } if (version_compare($oldv, '1.0', '<')) { $data = array(); $data['columns'][] = array('name' => 'id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'auto_increment' => true); $data['columns'][] = array('name' => 'device_template_id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['columns'][] = array('name' => 'thold_template_id', 'type' => 'int(11)', 'unsigned' => true, 'NULL' => false, 'default' => '0'); $data['primary'] = 'id'; $data['type'] = 'InnoDB'; $data['comment'] = 'Table of Device Template Threshold Templates'; api_plugin_db_table_create('thold', 'plugin_thold_device_template', $data); api_plugin_register_hook('thold', 'device_template_edit', 'thold_device_template_edit', 'setup.php'); api_plugin_register_hook('thold', 'device_template_top', 'thold_device_template_top', 'setup.php'); api_plugin_register_hook('thold', 'device_edit_pre_bottom', 'thold_device_edit_pre_bottom', 'setup.php'); api_plugin_register_hook('thold', 'api_device_new', 'thold_api_device_new', 'setup.php'); if (api_plugin_is_enabled('thold')) { api_plugin_enable_hooks('thold'); } } db_execute('UPDATE settings SET value = "' . $v['version'] . '" WHERE name = "plugin_thold_version"'); db_execute('UPDATE plugin_config SET version = "' . $v['version'] . '" WHERE directory = "thold"'); }
function api_plugin_enable($plugin) { $ready = api_plugin_check_config($plugin); if ($ready) { api_plugin_enable_hooks($plugin); db_execute_prepared('UPDATE plugin_config SET status = 1 WHERE directory = ?', array($plugin)); } }
function hmib_check_upgrade() { global $config, $database_default; include_once $config['library_path'] . '/database.php'; include_once $config['library_path'] . '/functions.php'; // Let's only run this check if we are on a page that actually needs the data $files = array('plugins.php', 'hmib.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } $version = plugin_hmib_version(); $current = $version['version']; $old = db_fetch_cell("SELECT version FROM plugin_config WHERE directory='hmib'"); if ($current != $old) { if (api_plugin_is_enabled('hmib')) { # may sound ridiculous, but enables new hooks api_plugin_enable_hooks('hmib'); } db_execute("UPDATE plugin_config SET version='{$current}' WHERE directory='hmib'"); db_execute("UPDATE plugin_config SET \n\t\t\tversion='" . $version['version'] . "', \n\t\t\tname='" . $version['longname'] . "', \n\t\t\tauthor='" . $version['author'] . "', \n\t\t\twebpage='" . $version['url'] . "' \n\t\t\tWHERE directory='" . $version['name'] . "' "); $columns = db_fetch_assoc('SHOW columns FROM plugin_hmib_hrSWRun_last_seen'); foreach ($columns as $c) { $cols[] = $c[0]; } if (!db_column_exists('plugin_hmib_hrSWRun_last_seen', 'total_time')) { db_execute("ALTER TABLE plugin_hmib_hrSWRun_last_seen ADD COLUMN `total_time` BIGINT unsigned not null default '0' AFTER `name`"); } } }
function mactrack_check_upgrade() { global $config; $files = array('index.php', 'plugins.php', 'mactrack_devices.php'); if (isset($_SERVER['PHP_SELF']) && !in_array(basename($_SERVER['PHP_SELF']), $files)) { return; } include_once $config['base_path'] . '/plugins/mactrack/lib/mactrack_functions.php'; $current = plugin_mactrack_version(); $current = $current['version']; $old = db_fetch_row("SELECT * FROM plugin_config WHERE directory='mactrack'"); if (!sizeof($old) || $current != $old['version']) { /* if the plugin is installed and/or active */ if (!sizeof($old) || $old['status'] == 1 || $old['status'] == 4) { /* re-register the hooks */ plugin_mactrack_install(); if (api_plugin_is_enabled('mactrack')) { # may sound ridiculous, but enables new hooks api_plugin_enable_hooks('mactrack'); } /* perform a database upgrade */ mactrack_database_upgrade(); } if (read_config_option('mt_convert_readstrings', true) != 'on') { convert_readstrings(); } // If are realms are not present in plugin_realms recreate them with the old realm ids (minus 100) so that upgraded installs are not broken if (!db_fetch_cell("SELECT id FROM plugin_realms WHERE plugin = 'mactrack'")) { db_execute("INSERT INTO plugin_realms (id, plugin, file, display) VALUES (2020, 'mactrack', 'mactrack_view_ips.php,mactrack_view_arp.php,mactrack_view_macs.php,mactrack_view_sites.php,mactrack_view_devices.php,mactrack_view_interfaces.php,mactrack_view_graphs.php,mactrack_ajax.php', 'Plugin -> MacTrack Viewer')"); db_execute("INSERT INTO plugin_realms (id, plugin, file, display) VALUES (2021, 'mactrack', 'mactrack_ajax_admin.php,mactrack_devices.php,mactrack_snmp.php,mactrack_sites.php,mactrack_device_types.php,mactrack_utilities.php,mactrack_macwatch.php,mactrack_macauth.php,mactrack_vendormacs.php', 'Plugin -> MacTrack Administrator')"); } /* rebuild the scanning functions */ mactrack_rebuild_scanning_funcs(); /* update the plugin information */ $info = plugin_mactrack_version(); $id = db_fetch_cell("SELECT id FROM plugin_config WHERE directory='mactrack'"); db_execute("UPDATE plugin_config\n\t\t\tSET name='" . $info['longname'] . "',\n\t\t\tauthor='" . $info['author'] . "',\n\t\t\twebpage='" . $info['homepage'] . "',\n\t\t\tversion='" . $info['version'] . "'\n\t\t\tWHERE id='{$id}'"); } }