Exemplo n.º 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;
}
Exemplo n.º 2
0
function create_export_directory_structure($cacti_root_path, $dir)
{
    /* create the treeview sub-directory */
    if (!is_dir("{$dir}/js")) {
        if (!mkdir("{$dir}/js", 0755, true)) {
            export_fatal("Create directory '" . $dir . "/js' failed.  Can not continue");
        }
        if (!mkdir("{$dir}/js/themes/default", 0755, true)) {
            export_fatal("Create directory '" . $dir . "/js/themes/default' failed.  Can not continue");
        }
        if (!mkdir("{$dir}/js/images", 0755, true)) {
            export_fatal("Create directory '" . $dir . "/js/images' failed.  Can not continue");
        }
    }
    /* create the graphs sub-directory */
    if (!is_dir("{$dir}/graphs")) {
        if (!mkdir("{$dir}/graphs", 0755, true)) {
            export_fatal("Create directory '" . $dir . "/graphs' failed.  Can not continue");
        }
    }
    /* css */
    copy("{$cacti_root_path}/include/main.css", "{$dir}/main.css");
    /* images for html */
    copy("{$cacti_root_path}/images/tab_cacti.gif", "{$dir}/tab_cacti.gif");
    copy("{$cacti_root_path}/images/cacti_backdrop.gif", "{$dir}/cacti_backdrop.gif");
    copy("{$cacti_root_path}/images/transparent_line.gif", "{$dir}/transparent_line.gif");
    copy("{$cacti_root_path}/images/shadow.gif", "{$dir}/shadow.gif");
    copy("{$cacti_root_path}/images/shadow_gray.gif", "{$dir}/shadow_gray.gif");
    $files = array("server_chart_curve.png", "server_chart.png", "server_dataquery.png", "server.png");
    foreach ($files as $file) {
        copy("{$cacti_root_path}/images/{$file}", "{$dir}/{$file}");
    }
    /* jstree theme files */
    $files = array("32px.png", "40px.png", "style.css", "style.min.css", "throbber.gif");
    foreach ($files as $file) {
        copy("{$cacti_root_path}/include/js/themes/default/{$file}", "{$dir}/js/themes/default/{$file}");
    }
    /* jquery-ui theme files */
    $files = array("ui-bg_diagonals-thick_18_b81900_40x40.png", "ui-bg_diagonals-thick_20_666666_40x40.png", "ui-bg_flat_10_000000_40x100.png", "ui-bg_glass_100_f6f6f6_1x400.png", "ui-bg_glass_100_fdf5ce_1x400.png", "ui-bg_glass_65_ffffff_1x400.png", "ui-bg_gloss-wave_35_f6a828_500x100.png", "ui-bg_highlight-soft_100_eeeeee_1x100.png", "ui-bg_highlight-soft_75_ffe45c_1x100.png", "ui-icons_222222_256x240.png", "ui-icons_228ef1_256x240.png", "ui-icons_ef8c08_256x240.png", "ui-icons_ffd27a_256x240.png", "ui-icons_ffffff_256x240.png");
    foreach ($files as $file) {
        copy("{$cacti_root_path}/include/js/images/{$file}", "{$dir}/js/images/{$file}");
    }
    /* java scripts for the tree */
    copy("{$cacti_root_path}/include/js/jquery.js", "{$dir}/js/jquery.js");
    copy("{$cacti_root_path}/include/js/jquery-ui.js", "{$dir}/js/jquery-ui.js");
    copy("{$cacti_root_path}/include/js/jstree.js", "{$dir}/js/jstree.js");
    copy("{$cacti_root_path}/include/js/jquery.cookie.js", "{$dir}/js/jquery.cookie.js");
    copy("{$cacti_root_path}/include/js/jquery-ui.css", "{$dir}/js/jquery-ui.css");
}
Exemplo n.º 3
0
function create_export_directory_structure($cacti_root_path, $dir)
{
    /* create the treeview sub-directory */
    if (!is_dir("{$dir}/treeview")) {
        if (!mkdir("{$dir}/treeview", 0755)) {
            export_fatal("Create directory '" . $dir . "/treeview' failed.  Can not continue");
        }
    }
    /* create the graphs sub-directory */
    if (!is_dir("{$dir}/graphs")) {
        if (!mkdir("{$dir}/graphs", 0755)) {
            export_fatal("Create directory '" . $dir . "/graphs' failed.  Can not continue");
        }
    }
    $treeview_dir = $dir . "/treeview";
    /* css */
    copy("{$cacti_root_path}/include/main.css", "{$dir}/main.css");
    /* images for html */
    copy("{$cacti_root_path}/images/tab_cacti.gif", "{$dir}/tab_cacti.gif");
    copy("{$cacti_root_path}/images/cacti_backdrop.gif", "{$dir}/cacti_backdrop.gif");
    copy("{$cacti_root_path}/images/transparent_line.gif", "{$dir}/transparent_line.gif");
    copy("{$cacti_root_path}/images/shadow.gif", "{$dir}/shadow.gif");
    copy("{$cacti_root_path}/images/shadow_gray.gif", "{$dir}/shadow_gray.gif");
    /* java scripts for the tree */
    copy("{$cacti_root_path}/include/treeview/ftiens4_export.js", "{$treeview_dir}/ftiens4.js");
    copy("{$cacti_root_path}/include/treeview/ua.js", "{$treeview_dir}/ua.js");
    /* images for the tree */
    copy("{$cacti_root_path}/include/treeview/ftv2blank.gif", "{$treeview_dir}/ftv2blank.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2lastnode.gif", "{$treeview_dir}/ftv2lastnode.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2mlastnode.gif", "{$treeview_dir}/ftv2mlastnode.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2mnode.gif", "{$treeview_dir}/ftv2mnode.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2node.gif", "{$treeview_dir}/ftv2node.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2plastnode.gif", "{$treeview_dir}/ftv2plastnode.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2pnode.gif", "{$treeview_dir}/ftv2pnode.gif");
    copy("{$cacti_root_path}/include/treeview/ftv2vertline.gif", "{$treeview_dir}/ftv2vertline.gif");
}
Exemplo n.º 4
0
function export_ftp_php_execute($stExportDir) {
	global $aFtpExport;

	$oFtpConnection = ftp_connect($aFtpExport['server'], $aFtpExport['port']);
	if (!$oFtpConnection) {
		export_fatal("EXPORT (fatal): FTP Connection failed! Check hostname and port.");
	} else {
		export_log("Conection to remote server was successful.");
	};

	if (!ftp_login($oFtpConnection, $aFtpExport['username'], $aFtpExport['password'])) {
		ftp_close($oFtpConnection);
		export_fatal("EXPORT (fatal): FTP Login failed! Check username and password.");
	} else {
		export_log("Remote login was successful.");
	};

	if ($aFtpExport['passive']) {
		ftp_pasv($oFtpConnection, TRUE);
	} else {
		ftp_pasv($oFtpConnection, FALSE);
	};

	if (!@ftp_chdir($oFtpConnection, $aFtpExport['remotedir'])) {
		ftp_close($oFtpConnection);
		export_fatal("EXPORT (fatal): FTP Remote directory does not exist!.");
	};

	// sanitize remote path
	if (read_config_option('export_ftp_sanitize') == 'on') {
		export_log("Deleting remote files.");
		$aFtpRemoteFiles = ftp_nlist($oFtpConnection, $aFtpExport['remotedir']);
		if (is_array($aFtpRemoteFiles)) {
			foreach ($aFtpRemoteFiles as $stFile) {
				ftp_delete($oFtpConnection, $aFtpExport['remotedir'].'/'.$stFile);
			};
		};
	};

	if ($dh = opendir($stExportDir)) {
		export_log("Uploading files to remote location.");
		while (($file = readdir($dh)) !== false) {
			$filePath = $stExportDir."/".$file;
			if ($file != "." && $file != ".." && !is_dir($filePath)) {
				if (!ftp_put($oFtpConnection, $aFtpExport['remotedir'].'/'.$file, $filePath, FTP_BINARY)) {
				export_log("Failed to upload '$file'.");
				}
			};
		};
		closedir($dh);
	};
	ftp_close($oFtpConnection);
	export_log("Closed ftp connection.");
};