function config_graph_export() { $total_graphs_created = 0; switch (read_config_option("export_type")) { case "local": $total_graphs_created = export(); break; case "ftp_php": // set the temp directory $stExportDir = $_ENV["TMP"].'/cacti-ftp-temp'; $total_graphs_created = export_pre_ftp_upload($stExportDir); export_log("Using PHP built-in FTP functions."); export_ftp_php_execute($stExportDir); export_post_ftp_upload($stExportDir); break; case "ftp_ncftpput": if (strstr(PHP_OS, "WIN")) export_fatal("ncftpput only available in unix environment! Export can not continue."); // set the temp directory $stExportDir = $_ENV["TMP"].'/cacti-ftp-temp'; $total_graphs_created = export_pre_ftp_upload($stExportDir); export_log("Using ncftpput."); export_ftp_ncftpput_execute($stExportDir); export_post_ftp_upload($stExportDir); break; case "disabled": break; default: export_log("Export method not specified. Updated config to use local exporting."); db_execute("insert into settings (name,value) values ('export_type','local')"); } return $total_graphs_created; }
function export_post_ftp_upload($stExportDir) { /* clean-up after ftp-put */ if ($dh = opendir($stExportDir)) { while (($file = readdir($dh)) !== false) { $filePath = $stExportDir . "/" . $file; if ($file != "." && $file != ".." && !is_dir($filePath)) { export_log("Removing Local File '" . $file . "'"); unlink($filePath); } /* if the directory turns out to be a sub-directory, delete it too */ if ($file != "." && $file != ".." && is_dir($filePath)) { export_log("Removing Local Directory '" . $filePath . "'"); export_post_ftp_upload($filePath); } } closedir($dh); /* don't delete the root of the temporary export directory */ if (read_config_option("export_temporary_directory") != $stExportDir) { rmdir($stExportDir); } } }