Exemplo n.º 1
0
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'");
	}
}
Exemplo n.º 2
0
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}'");
    }
}