예제 #1
0
function export() {
	global $config;

	/* count how many graphs are created */
	$total_graphs_created = 0;

	if (!file_exists(read_config_option("path_html_export"))) {
		export_fatal("Export path '" . read_config_option("path_html_export") . "' does not exist!  Export can not continue.");
	}

	export_log("Running graph export");

	$cacti_root_path = $config["base_path"];
	$cacti_export_path = read_config_option("path_html_export");

	if (substr_count($cacti_root_path, $cacti_export_path) ||
		(substr_count($cacti_export_path, $cacti_root_path))) {
		export_fatal("Export path '" . read_config_option("path_html_export") . "' is to closely related to the Cacti web root.  You must be out of your mind.");
	}

	/* delete all files and directories in the cacti_export_path */
	del_directory($cacti_export_path, false);

	/* test how will the export will be made */
	if (read_config_option('export_presentation') == 'tree') {
		export_log("Running graph export with tree organization");
		$total_graphs_created = tree_export();
	}else {
		/* copy the css/images on the first time */
		if (file_exists("$cacti_export_path/main.css") == false) {
			copy("$cacti_root_path/include/main.css", "$cacti_export_path/main.css");
			copy("$cacti_root_path/images/tab_cacti.gif", "$cacti_export_path/tab_cacti.gif");
			copy("$cacti_root_path/images/cacti_backdrop.gif", "$cacti_export_path/cacti_backdrop.gif");
			copy("$cacti_root_path/images/transparent_line.gif", "$cacti_export_path/transparent_line.gif");
			copy("$cacti_root_path/images/shadow.gif", "$cacti_export_path/shadow.gif");
		}

		/* if the index file already exists, delete it */
		check_remove($cacti_export_path . "/index.html");

		/* open pointer to the new index file */
		$fp_index = fopen($cacti_export_path . "/index.html", "w");

		/* get a list of all graphs that need exported */
		$graphs = db_fetch_assoc("select
			graph_templates_graph.id,
			graph_templates_graph.local_graph_id,
			graph_templates_graph.height,
			graph_templates_graph.width,
			graph_templates_graph.title_cache,
			graph_templates.name,
			graph_local.host_id
			from graph_templates_graph
			left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id)
			left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id)
			where graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on'
			order by graph_templates_graph.title_cache");

		$rras = db_fetch_assoc("select
			rra.id,
			rra.name
			from rra
			order by steps");

		/* write the html header data to the index file */
		fwrite($fp_index, HTML_HEADER);
		fwrite($fp_index, HTML_GRAPH_HEADER_ONE);
		fwrite($fp_index, "<strong>Displaying " . sizeof($graphs) . " Exported Graph" . ((sizeof($graphs) > 1) ? "s" : "") . "</strong>");
		fwrite($fp_index, HTML_GRAPH_HEADER_TWO);

		/* open a pipe to rrdtool for writing */
		$rrdtool_pipe = rrd_init();

		/* for each graph... */
		$i = 0; $k = 0;
		if ((sizeof($graphs) > 0) && (sizeof($rras) > 0)) {
		foreach ($graphs as $graph) {
			check_remove($cacti_export_path . "/thumb_" . $graph["local_graph_id"] . ".png");
			check_remove($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html");

			/* settings for preview graphs */
			$graph_data_array["graph_height"] = "100";
			$graph_data_array["graph_width"] = "300";
			$graph_data_array["graph_nolegend"] = true;
			$graph_data_array["export"] = true;
			$graph_data_array["export_filename"] = "thumb_" . $graph["local_graph_id"] . ".png";
			rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);
			$total_graphs_created++;

			/* generate html files for each graph */
			$fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w");

			fwrite($fp_graph_index, HTML_HEADER);
			fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE);
			fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong>");
			fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO);
			fwrite($fp_graph_index, "<td>");

			/* reset vars for actual graph image creation */
			reset($rras);
			unset($graph_data_array);

			/* generate graphs for each rra */
			foreach ($rras as $rra) {
				$graph_data_array["export"] = true;
				$graph_data_array["export_filename"] = "graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";

				rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe);
				$total_graphs_created++;

				/* write image related html */
				fwrite($fp_graph_index, "<div align=center><img src='graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n
					<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
			}

			fwrite($fp_graph_index, "</td>");
			fwrite($fp_graph_index, HTML_GRAPH_FOOTER);
			fwrite($fp_graph_index, HTML_FOOTER);
			fclose($fp_graph_index);

			/* main graph page html */
			fwrite($fp_index, "<td align='center' width='" . (98 / 2) . "%'><a href='graph_" . $graph["local_graph_id"] . ".html'><img src='thumb_" . $graph["local_graph_id"] . ".png' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n");

			$i++;
			$k++;

			if (($i == 2) && ($k < count($graphs))) {
				$i = 0;
				fwrite($fp_index, "</tr><tr>");
			}

		}
		}else{ fwrite($fp_index, "<td><em>No Graphs Found.</em></td>");
		}

		/* close the rrdtool pipe */
		rrd_close($rrdtool_pipe);

		fwrite($fp_index, HTML_GRAPH_FOOTER);
		fwrite($fp_index, HTML_FOOTER);
		fclose($fp_index);
	}

	return $total_graphs_created;
}
예제 #2
0
function export_tree_graphs_and_graph_html($path, $tree_id)
{
    global $colors, $config;
    include_once $config["library_path"] . "/tree.php";
    include_once $config["library_path"] . "/data_query.php";
    /* start the count of graphs */
    $total_graphs_created = 0;
    $exported_files = array();
    $cacti_export_path = read_config_option("path_html_export");
    /* auth check for hosts on the trees */
    $current_user = db_fetch_row("SELECT * FROM user_auth WHERE id=" . read_config_option("export_user_id"));
    if (!export_is_tree_allowed($tree_id)) {
        return 0;
    }
    $sql_join = "LEFT JOIN graph_local ON (graph_templates_graph.local_graph_id=graph_local.id)\n\t\tLEFT JOIN graph_templates ON (graph_templates.id=graph_local.graph_template_id)\n\t\tLEFT JOIN host ON (host.id=graph_local.host_id)\n\t\tLEFT JOIN user_auth_perms ON ((graph_templates_graph.local_graph_id=user_auth_perms.item_id and user_auth_perms.type=1 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (host.id=user_auth_perms.item_id AND user_auth_perms.type=3 AND user_auth_perms.user_id=" . $current_user["id"] . ") OR (graph_templates.id=user_auth_perms.item_id AND user_auth_perms.type=4 AND user_auth_perms.user_id=" . $current_user["id"] . "))";
    $sql_where = get_graph_permissions_sql($current_user["policy_graphs"], $current_user["policy_hosts"], $current_user["policy_graph_templates"]);
    $sql_where = empty($sql_where) ? "" : "AND {$sql_where}";
    $graphs = array();
    if ($tree_id == 0) {
        $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items");
    } else {
        $hosts = db_fetch_assoc("SELECT DISTINCT host_id FROM graph_tree_items WHERE graph_tree_id=" . $tree_id);
    }
    /* get a list of host graphs first */
    if (sizeof($hosts)) {
        foreach ($hosts as $host) {
            $hosts_sql = "SELECT DISTINCT\n\t\t\tgraph_templates_graph.id,\n\t\t\tgraph_templates_graph.local_graph_id,\n\t\t\tgraph_templates_graph.height,\n\t\t\tgraph_templates_graph.width,\n\t\t\tgraph_templates_graph.title_cache,\n\t\t\tgraph_templates.name,\n\t\t\tgraph_local.host_id\n\t\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t\t{$sql_join}\n\t\t\tWHERE ((graph_templates_graph.local_graph_id<>0)\n\t\t\t{$sql_where}\n\t\t\tAND (graph_local.host_id=" . $host["host_id"] . ")\n\t\t\tAND (graph_templates_graph.export='on'))\n\t\t\tORDER BY graph_templates_graph.title_cache";
            $host_graphs = db_fetch_assoc($hosts_sql);
            if (sizeof($host_graphs)) {
                if (sizeof($graphs)) {
                    $graphs = array_merge($host_graphs, $graphs);
                } else {
                    $graphs = $host_graphs;
                }
            }
        }
    }
    /* now get the list of graphs placed within the tree */
    if ($tree_id == 0) {
        $sql_where = "WHERE graph_templates_graph.local_graph_id!=0\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.export='on'";
    } else {
        $sql_where = "WHERE graph_tree_items.graph_tree_id =" . $tree_id . "\n\t\t\t{$sql_where}\n\t\t\tAND graph_templates_graph.local_graph_id!=0\n\t\t\tAND graph_templates_graph.export='on'";
    }
    $non_host_sql = "SELECT\n\t\tgraph_templates_graph.id,\n\t\tgraph_templates_graph.local_graph_id,\n\t\tgraph_templates_graph.height,\n\t\tgraph_templates_graph.width,\n\t\tgraph_templates_graph.title_cache,\n\t\tgraph_templates.name,\n\t\tgraph_local.host_id,\n\t\tgraph_tree_items.id AS gtid\n\t\tFROM (graph_tree_items, graph_templates_graph)\n\t\t{$sql_join}\n\t\t{$sql_where}\n\t\tAND graph_tree_items.local_graph_id = graph_templates_graph.local_graph_id\n\t\tAND graph_templates_graph.export='on'\n\t\tORDER BY graph_templates_graph.title_cache";
    $non_host_graphs = db_fetch_assoc($non_host_sql);
    if (sizeof($non_host_graphs)) {
        if (sizeof($graphs)) {
            $graphs = array_merge($non_host_graphs, $graphs);
        } else {
            $graphs = $non_host_graphs;
        }
    }
    /* open a pipe to rrdtool for writing */
    $rrdtool_pipe = rrd_init();
    /* for each graph... */
    $i = 0;
    if (sizeof($graphs) > 0) {
        foreach ($graphs as $graph) {
            $rras = get_associated_rras($graph["local_graph_id"]);
            /* settings for preview graphs */
            $graph_data_array["graph_height"] = read_config_option("export_default_height");
            $graph_data_array["graph_width"] = read_config_option("export_default_width");
            $graph_data_array["graph_nolegend"] = true;
            $graph_data_array["export"] = true;
            if (read_config_option("export_tree_isolation") == "on") {
                $graph_data_array["export_filename"] = "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
                $export_filename = $cacti_export_path . "/" . $path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
            } else {
                $graph_data_array["export_filename"] = "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
                $export_filename = $cacti_export_path . "/graphs/thumb_" . $graph["local_graph_id"] . ".png";
            }
            if (!array_search($export_filename, $exported_files)) {
                /* add the graph to the exported list */
                array_push($exported_files, $export_filename);
                export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'");
                /* generate the graph */
                rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);
                $total_graphs_created++;
                /* generate html files for each graph */
                if (read_config_option("export_tree_isolation") == "on") {
                    export_log("Creating File  '" . $cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html'");
                    $fp_graph_index = fopen($cacti_export_path . "/" . $path . "/graph_" . $graph["local_graph_id"] . ".html", "w");
                } else {
                    export_log("Creating File  '" . $cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html'");
                    $fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w");
                }
                fwrite($fp_graph_index, HTML_HEADER_TREE);
                /* write the code for the tree at the left */
                draw_html_left_tree($fp_graph_index, $tree_id);
                fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE_TREE);
                fwrite($fp_graph_index, "<strong>Graph - " . $graph["title_cache"] . "</strong></td></tr>");
                fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO_TREE);
                fwrite($fp_graph_index, "<td>");
                /* reset vars for actual graph image creation */
                reset($rras);
                unset($graph_data_array);
                /* generate graphs for each rra */
                foreach ($rras as $rra) {
                    $graph_data_array["export"] = true;
                    if (read_config_option("export_tree_isolation") == "on") {
                        $graph_data_array["export_filename"] = "/" . $path . "/graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";
                    } else {
                        $graph_data_array["export_filename"] = "/graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";
                    }
                    export_log("Creating Graph '" . $cacti_export_path . $graph_data_array["export_filename"] . "'");
                    rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe);
                    $total_graphs_created++;
                    /* write image related html */
                    if (read_config_option("export_tree_isolation") == "off") {
                        fwrite($fp_graph_index, "<div align=center><img src='graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n\n\t\t\t\t\t\t<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
                    } else {
                        fwrite($fp_graph_index, "<div align=center><img src='" . "graphs/graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n\n\t\t\t\t\t\t<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
                    }
                }
                fwrite($fp_graph_index, "</td></tr></table></td></tr></table>");
                fwrite($fp_graph_index, HTML_FOOTER_TREE);
                fclose($fp_graph_index);
            }
        }
    }
    /* close the rrdtool pipe */
    rrd_close($rrdtool_pipe);
    return $total_graphs_created;
}
예제 #3
0
            export_rector();
            break;
        case 'students':
            export_students();
            break;
        case 'agreements':
            export_agreements();
            break;
        case 'travels':
            export_travels();
            break;
        case 'files':
            export_files();
            break;
        case 'log':
            export_log();
            break;
    }
}
$link->close();
function export_rector()
{
    headers_for_export('fmfi_erasmus.csv');
    db_export_rector();
}
function export_students()
{
    headers_for_export('students.csv');
    db_export_students();
}
function export_agreements()
예제 #4
0
function export()
{
    global $config;
    /* count how many graphs are created */
    $total_graphs_created = 0;
    $cacti_root_path = $config["base_path"];
    $cacti_export_path = read_config_option("path_html_export");
    /* if the path is not a directory, don't continue */
    if (!is_dir($cacti_export_path)) {
        export_fatal("Export path '" . $cacti_export_path . "' does not exist!  Export can not continue.");
    }
    /* blank paths are not good */
    if (strlen($cacti_export_path) == 0) {
        export_fatal("Export path is null!  Export can not continue.");
    }
    /* can not be the web root */
    if (strcasecmp($cacti_root_path, $cacti_export_path) == 0 && read_config_option("export_type") == "local") {
        export_fatal("Export path '" . $cacti_export_path . "' is the Cacti web root.  Can not continue.");
    }
    /* can not be a parent of the Cacti web root */
    if (strncasecmp($cacti_root_path, $cacti_export_path, strlen($cacti_export_path)) == 0) {
        export_fatal("Export path '" . $cacti_export_path . "' is a parent folder from the Cacti web root.  Can not continue.");
    }
    /* check for bad directories within the cacti path */
    if (strcasecmp($cacti_root_path, $cacti_export_path) < 0) {
        $cacti_system_paths = array("include", "lib", "install", "rra", "log", "scripts", "plugins", "images", "resource");
        foreach ($cacti_system_paths as $cacti_system_path) {
            if (substr_count(strtolower($cacti_export_path), strtolower($cacti_system_path)) > 0) {
                export_fatal("Export path '" . $cacti_export_path . "' is potentially within a Cacti system path '" . $cacti_system_path . "'.  Can not continue.");
            }
        }
    }
    /* don't allow to export to system paths */
    $system_paths = array("/boot", "/lib", "/usr", "/bin", "/sbin", "/root", "/etc", "windows", "winnt", "program files");
    foreach ($system_paths as $system_path) {
        if (substr_count(strtolower($cacti_export_path), strtolower($system_path)) > 0) {
            export_fatal("Export path '" . $cacti_export_path . "' is within a system path '" . $system_path . "'.  Can not continue.");
        }
    }
    export_log("Running graph export");
    /* delete all files and directories in the cacti_export_path */
    del_directory($cacti_export_path, false);
    /* test how will the export will be made */
    if (read_config_option('export_presentation') == 'tree') {
        export_log("Running graph export with tree organization");
        $total_graphs_created = tree_export();
    } else {
        export_log("Running graph export with legacy organization");
        $total_graphs_created = classical_export($cacti_root_path, $cacti_export_path);
    }
    return $total_graphs_created;
}
예제 #5
0
function export() {
	require_once(CACTI_BASE_PATH . "/lib/sys/rrd.php");

	/* count how many graphs are created */
	$total_graphs_created = 0;

	export_log(_("Running graph export"));

	$cacti_root_path = CACTI_BASE_PATH;
	$cacti_export_path = read_config_option("path_html_export");

	/* copy the css/images on the first time */
	if (file_exists("$cacti_export_path/main.css") == false) {
		copy("$cacti_root_path/" . html_get_theme_css(), "$cacti_export_path/main.css");
		copy("$cacti_root_path/themes" . read_config_option("current_theme") . "/images/tab_cacti.gif", "$cacti_export_path/tab_cacti.gif");
		copy("$cacti_root_path/themes" . read_config_option("current_theme") . "/images/cacti_backdrop.gif", "$cacti_export_path/cacti_backdrop.gif");
		copy("$cacti_root_path/themes" . read_config_option("current_theme") . "/images/transparent_line.gif", "$cacti_export_path/transparent_line.gif");
		copy("$cacti_root_path/themes" . read_config_option("current_theme") . "/images/shadow.gif", "$cacti_export_path/shadow.gif");
	}

	/* if the index file already exists, delete it */
	check_remove($cacti_export_path . "/index.html");

	/* open pointer to the new index file */
	$fp_index = fopen($cacti_export_path . "/index.html", "w");

	/* get a list of all graphs that need exported */
	$graphs = db_fetch_assoc("select
		graph_templates_graph.id,
		graph_templates_graph.local_graph_id,
		graph_templates_graph.height,
		graph_templates_graph.width,
		graph_templates_graph.title_cache,
		graph_templates.name,
		graph_local.host_id
		from graph_templates_graph left join graph_templates on (graph_templates_graph.graph_template_id=graph_templates.id)
		left join graph_local on (graph_templates_graph.local_graph_id=graph_local.id)
		where graph_templates_graph.local_graph_id!=0 and graph_templates_graph.export='on'
		order by graph_templates_graph.title_cache");
	$rras = db_fetch_assoc("select
		rra.id,
		rra.name
		from rra
		order by timespan");

	/* write the html header data to the index file */
	fwrite($fp_index, HTML_HEADER);
	fwrite($fp_index, HTML_GRAPH_HEADER_ONE);
	fwrite($fp_index, "<strong>" . sprintf(_("Displaying '%i' Exported Graph%s"), sizeof($graphs), ((sizeof($graphs) > 1) ? "s" : "")) . "</strong>");
	fwrite($fp_index, HTML_GRAPH_HEADER_TWO);

	/* open a pipe to rrdtool for writing */
	$rrdtool_pipe = rrd_init();

	/* for each graph... */
	$i = 0; $k = 0;
	if ((sizeof($graphs) > 0) && (sizeof($rras) > 0)) {
	foreach ($graphs as $graph) {
		check_remove($cacti_export_path . "/thumb_" . $graph["local_graph_id"] . ".png");
		check_remove($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html");

		/* settings for preview graphs */
		$graph_data_array["graph_height"] = "100";
		$graph_data_array["graph_width"] = "300";
		$graph_data_array["graph_nolegend"] = true;
		$graph_data_array["export"] = true;
		$graph_data_array["export_filename"] = "thumb_" . $graph["local_graph_id"] . ".png";
		rrdtool_function_graph($graph["local_graph_id"], 0, $graph_data_array, $rrdtool_pipe);
		$total_graphs_created++;

		/* generate html files for each graph */
		$fp_graph_index = fopen($cacti_export_path . "/graph_" . $graph["local_graph_id"] . ".html", "w");

		fwrite($fp_graph_index, HTML_HEADER);
		fwrite($fp_graph_index, HTML_GRAPH_HEADER_ONE);
		fwrite($fp_graph_index, "<strong>" . _("Graph") . " - " . $graph["title_cache"] . "</strong>");
		fwrite($fp_graph_index, HTML_GRAPH_HEADER_TWO);
		fwrite($fp_graph_index, "<td>");

		/* reset vars for actual graph image creation */
		reset($rras);
		unset($graph_data_array);

		/* generate graphs for each rra */
		foreach ($rras as $rra) {
			$graph_data_array["export"] = true;
			$graph_data_array["export_filename"] = "graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png";

			rrdtool_function_graph($graph["local_graph_id"], $rra["id"], $graph_data_array, $rrdtool_pipe);
			$total_graphs_created++;

			/* write image related html */
			fwrite($fp_graph_index, "<div align=center><img src='graph_" . $graph["local_graph_id"] . "_" . $rra["id"] . ".png' border=0></div>\n
				<div align=center><strong>" . $rra["name"] . "</strong></div><br>");
		}

		fwrite($fp_graph_index, "</td>");
		fwrite($fp_graph_index, HTML_GRAPH_FOOTER);
		fwrite($fp_graph_index, HTML_FOOTER);
		fclose($fp_graph_index);

		/* main graph page html */
		fwrite($fp_index, "<td align='center' width='" . (98 / 2) . "%'><a href='graph_" . $graph["local_graph_id"] . ".html'><img src='thumb_" . $graph["local_graph_id"] . ".png' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n");

		$i++;
		$k++;

		if (($i == 2) && ($k < count($graphs))) {
			$i = 0;
			fwrite($fp_index, "</tr><tr>");
		}

	}
	}else{ fwrite($fp_index, "<td><em>" . _("No Graphs Found.") . "</em></td>");
	}

	/* close the rrdtool pipe */
	rrd_close($rrdtool_pipe);

	fwrite($fp_index, HTML_GRAPH_FOOTER);
	fwrite($fp_index, HTML_FOOTER);
	fclose($fp_index);

	return $total_graphs_created;
}