diff --git a/INFO b/INFO new file mode 100644 index 0000000..c652eda --- /dev/null +++ b/INFO @@ -0,0 +1,8 @@ +[info] +name = export +version = 1.0 +longname = Graph Export Package for Cacti +author = The Cacti Group +email = +homepage = http://www.cacti.net +compat = 1.0.0 diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..207a79c --- /dev/null +++ b/LICENSE @@ -0,0 +1,278 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + diff --git a/README b/README new file mode 100644 index 0000000..a724e48 --- /dev/null +++ b/README @@ -0,0 +1,41 @@ +/******************************************************************************* + + Author ......... The Cacti Group + Contact ........ http://forums.cacti.net + Home Site ...... http://www.cacti.net + Program ........ Cacti Export Plugin + Version ........ 1.0 + Purpose ........ Allows Graph Trees to be Exported + +*******************************************************************************/ + + +----[ Purpose + + This plugin allows Cacti Graphs to be Exported + +----[ Features + + Allows you to Export Cacti Graphs. It replaces the legacy Cacti Export + functionality. + +----[ Installation + + Install just like any other plugin, just throw it in the plugin directory, + and Install and Enabled from the Plugin Management Interface. + + Once this is done, you can configure what graph trees to be exported and + using which user. + +----[ Possible Bugs? + + If you figure out this problem, see the Cacti forums! + +----[ Future Changes + + Got any ideas or complaints, please use Mantis! + +----[ Changelog + + --- 1.0 --- + Initial Release diff --git a/functions.php b/functions.php new file mode 100644 index 0000000..d5c86ca --- /dev/null +++ b/functions.php @@ -0,0 +1,1322 @@ + 0) { + $sql_where = ' AND id=' . $id; + } + + $exports = db_fetch_assoc('SELECT * FROM graph_exports WHERE enabled="on"' . $sql_where); + + if (sizeof($exports)) { + foreach($exports as $export) { + /* insert poller stats into the settings table */ + db_execute_prepared('UPDATE graph_exports + SET last_checked = NOW() + WHERE id = ?', + array($export['id'])); + + $runnow = false; + + if (!$force) { + if ($export['export_timing'] == 'periodic') { + if ($export['last_checked'] == '0000-00-00 00:00:00') { + $runnow = true; + }else{ + $last_checked = strtotime($export['export_timing']); + if ($last_checked + $export['export_skip'] * $poller_interval < $start_time) { + $runnow = true; + } + } + }else{ + switch($export['export_timing']) { + case 'hourly': + $current = date('H:i:s', $start_time); + $seconds = date('s', $start_time); + $hours = date('H', $start_time); + $today = date('Y-m-d', $start_time); + $nextst = $export['export_hourly']; + + $stn = strtotime($today . ' ' . $hours . ':' . $nextst . ':' . $seconds); + $stp = $start_time - $poller_interval; + + if ($stn < $stp && $stn < $start_time) { + $runnow = true; + } + + break; + case 'daily': + $current = date('H:i:s', $start_time); + $seconds = date('s', $start_time); + $today = date('Y-m-d', $start_time); + $nextst = $export['export_daily']; + + $stn = strtotime($today . ' ' . $nextst . ':' . $seconds); + $stp = $start_time - $poller_interval; + + if ($stn < $stp && $stn < $start_time) { + $runnow = true; + } + + break; + } + } + }else{ + $runnow = true; + } + + if ($runnow) { + export_debug('Running Export for id ' . $export['id']); + run_export($export); + } + } + } +} + +function exporter(&$export, $export_path) { + $exported = export_graphs($export, $export_path); + if ($export['export_presentation'] == 'tree') { + tree_export($export, $export_path); + }else{ + site_export($export, $export_path); + } + + return $exported; +} + +function run_export(&$export) { + global $export_path; + + $exported = 0; + + switch ($export['export_type']) { + case 'local': + export_debug("Export Type is 'local'"); + + $export_path = $export['export_directory']; + + $exported = exporter($export, $export_path); + + break; + case 'sftp': + export_debug("Export Type is 'sftp_php'"); + + if (!function_exists('ftp_ssl_connect')) { + export_fatal($export, 'Secure FTP Function does not exist. Export can not continue.'); + } + case 'ftp': + export_debug("Export Type is 'ftp'"); + + /* set the temp directory */ + if (strlen($export['export_temp_directory']) == 0) { + $stExportDir = $_ENV['TMP'] . '/cacti-ftp-temp'; + }else{ + $stExportDir = $export['export_temp_directory'] . '/cacti-ftp-temp'; + } + + $exported = exporter($export, $stExportDir); + + export_pre_ftp_upload($export, $stExportDir); + + export_log('Using PHP built-in FTP functions.'); + export_ftp_php_execute($export, $stExportDir); + export_post_ftp_upload($export, $stExportDir); + + break; + case 'ftp_nc': + export_debug("Export Type is 'ftp_nc'"); + if (strstr(PHP_OS, 'WIN')) export_fatal($export, 'ncftpput only available in unix environment! Export can not continue.'); + + /* set the temp directory */ + if (strlen($export['export_temp_directory']) == 0) { + $stExportDir = $_ENV['TMP'] . '/cacti-ftp-temp'; + }else{ + $stExportDir = $export['export_temporary_directory'] . '/cacti-ftp-temp'; + } + + $exported = exporter($export, $stExportDir); + + export_pre_ftp_upload($export, $stExportDir); + + export_log('Using ncftpput.'); + export_ftp_ncftpput_execute($export, $stExportDir); + export_post_ftp_upload($export, $stExportDir); + + break; + case 'rsync': + export_debug("Export Type is 'rsync'"); + + /* set the temp directory */ + if (strlen($export['export_temp_directory']) == 0) { + $stExportDir = $_ENV['TMP'] . '/cacti-rsync-temp'; + }else{ + $stExportDir = $export['export_temporary_directory'] . '/cacti-rsync-temp'; + } + + $exported = exporter($export, $stExportDir); + + break; + case 'scp': + export_debug("Export Type is 'scp'"); + + /* set the temp directory */ + if (strlen($export['export_temp_directory']) == 0) { + $stExportDir = $_ENV['TMP'] . '/cacti-scp-temp'; + }else{ + $stExportDir = $export['export_temporary_directory'] . '/cacti-scp-temp'; + } + + $exported = exporter($export, $stExportDir); + + break; + default: + export_fatal($export, 'Export method not specified. Exporting can not continue. Please set method properly in Cacti configuration.'); + } + + config_export_stats($export, $exported); +} + +function config_export_stats(&$export, $exported) { + global $start; + /* take time to log performance data */ + $end = microtime(true); + + $export_stats = sprintf( + 'ExportID:%s ExportDate:%s ExportDuration:%01.2f TotalGraphsExported:%s', + $export['id'], date('Y-m-d_G:i:s'), $end - $start, $exported); + + cacti_log('STATS: ' . $export_stats, true, 'EXPORT'); + + /* insert poller stats into the settings table */ + db_execute_prepared('UPDATE graph_exports + SET last_runtime = ?, total_graphs = ?, last_ended=NOW(), status=0 + WHERE id = ?', + array($end - $start, $exported, $export['id'])); + + db_execute_prepared(sprintf("REPLACE INTO settings (name,value) values ('stats_export_%s', ?)", $export['id']), array($export_stats)); +} + +function export_fatal(&$export, $stMessage) { + cacti_log('FATAL ERROR: ' . $stMessage, true, 'EXPORT'); + + /* insert poller stats into the settings table */ + db_execute_prepared('UPDATE graph_exports + SET last_error = ?, last_ended=NOW(), status=2 + WHERE id = ?', + array($stMessage, $export['id'])); + + export_debug($stMessage); + + exit; +} + +function export_log($stMessage) { + cacti_log($stMessage, true, 'EXPORT', POLLER_VERBOSITY_HIGH); + + export_debug($stMessage); +} + +function export_debug($message) { + global $debug; + + if ($debug) { + print rtrim($message) . "\n"; + } +} + +function export_pre_ftp_upload(&$export) { + global $config, $aFtpExport; + + $aFtpExport['server'] = $export['export_host']; + if (empty($aFtpExport['server'])) { + export_fatal($export, 'FTP Hostname is not expected to be blank!'); + } + + $aFtpExport['remotedir'] = $export['export_directory']; + if (empty($aFtpExport['remotedir'])) { + export_fatal($export, 'FTP Remote export path is not expected to be blank!'); + } + + $aFtpExport['port'] = $export['export_port']; + $aFtpExport['port'] = empty($aFtpExport['port']) ? '21' : $aFtpExport['port']; + + $aFtpExport['username'] = $export['export_ftp_user']; + $aFtpExport['password'] = $export['export_ftp_password']; + + if (empty($aFtpExport['username'])) { + $aFtpExport['username'] = 'Anonymous'; + $aFtpExport['password'] = ''; + export_log('Using Anonymous transfer method.'); + } + + if ($export['export_passive'] == 'on') { + $aFtpExport['passive'] = TRUE; + export_log('Using passive transfer method.'); + }else { + $aFtpExport['passive'] = FALSE; + export_log('Using active transfer method.'); + } +} + +function check_cacti_paths(&$export, $export_path) { + global $config; + + $cacti_root_path = $config['base_path']; + + /* check for bad directories within the cacti path */ + if (strcasecmp($cacti_root_path, $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($export_path), strtolower($cacti_system_path)) > 0) { + export_fatal($export, "Export path '" . $export_path . "' is potentially within a Cacti system path '" . $cacti_system_path . "'. Can not continue."); + } + } + } + + /* can not be the web root */ + if ((strcasecmp($cacti_root_path, $export_path) == 0) && + (read_config_option('export_type') == 'local')) { + export_fatal($export, "Export path '" . $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, $export_path, strlen($export_path))== 0) { + export_fatal($export, "Export path '" . $export_path . "' is a parent folder from the Cacti web root. Can not continue."); + } + +} + +function check_system_paths(&$export, $export_path) { + /* don't allow to export to system paths */ + $system_paths = array( + '/boot', + '/lib', + '/usr', + '/usr/bin', + '/bin', + '/sbin', + '/usr/sbin', + '/usr/lib', + '/var/lib', + '/var/log', + '/root', + '/etc', + 'windows', + 'winnt', + 'program files'); + + foreach($system_paths as $system_path) { + if (substr($system_path, 0, 1) == '/') { + if ($system_path == substr($export_path, 0, strlen($system_path))) { + export_fatal($export, "Export path '" . $export_path . "' is within a system path '" . $system_path . "'. Can not continue."); + } + }elseif (substr_count(strtolower($export_path), strtolower($system_path)) > 0) { + export_fatal($export, "Export path '" . $export_path . "' is within a system path '" . $system_path . "'. Can not continue."); + } + } +} + +function export_graphs(&$export, $export_path) { + global $config; + + /* insert started time into database */ + db_execute_prepared('UPDATE graph_exports + SET last_started = NOW(), status=1 + WHERE id = ?', + array($export['id'])); + + /* check for bad directories */ + check_cacti_paths($export, $export_path); + check_system_paths($export, $export_path); + + /* if the path is not a directory, don't continue */ + if (!is_dir($export_path)) { + if (!mkdir($export_path)) { + export_fatal($export, "Unable to create path '" . $export_path . "'! Export can not continue."); + } + } + + if (!is_dir($export_path . '/graphs')) { + if (!mkdir($export_path . '/graphs')) { + export_fatal($export, "Unable to create path '" . $export_path . "/graphs'! Export can not continue."); + } + } + + if (!is_writable($export_path)) { + export_fatal($export, "Unable to write to path '" . $export_path . "'! Export can not continue."); + } + + if (!is_writable($export_path . '/graphs')) { + export_fatal($export, "Unable to write to path '" . $export_path . "/graphs'! Export can not continue."); + } + + /* blank paths are not good */ + if (strlen($export_path) == 0) { + export_fatal($export, 'Export path is null! Export can not continue.'); + } + + export_log('Running graph export'); + + $user = $export['export_effective_user']; + $trees = $export['graph_tree']; + $sites = $export['graph_site']; + + $ntree = array(); + $graphs = array(); + $ngraph = array(); + + $limit = 1000; + $sql_where = ''; + $hosts = ''; + $total_rows = 0; + $exported = 0; + $metadata = array(); + + if ($user == 0) { + $user = -1; + } + + if ($export['export_presentation'] == 'tree') { + if ($trees != '') { + $sql_where = 'gt.id IN(' . $trees . ')'; + } + + $trees = get_allowed_trees(false, false, $sql_where, 'name', '', $total_rows, $user); + + if (sizeof($trees)) { + foreach($trees as $tree) { + $ntree[] = $tree['id']; + } + } + + if (sizeof($ntree)) { + $graphs = array_rekey( + db_fetch_assoc('SELECT DISTINCT local_graph_id + FROM graph_tree_items + WHERE local_graph_id > 0 + AND graph_tree_id IN(' . implode(', ', $ntree) . ')'), + 'local_graph_id', 'local_graph_id' + ); + + if (sizeof($graphs)) { + foreach($graphs as $local_graph_id) { + if (is_graph_allowed($local_graph_id, $user)) { + $ngraph[$local_graph_id] = $local_graph_id; + } + } + } + + $hosts = db_fetch_cell_prepared('SELECT GROUP_CONCAT(DISTINCT host_id) + FROM graph_tree_items + WHERE graph_tree_id IN(?)', + array(implode(', ', $ntree))); + + if ($hosts != '') { + $sql_where = 'gl.host_id IN(' . $hosts . ')'; + $graphs = get_allowed_graphs($sql_where, 'gtg.title_cache', '', $total_rows, $user); + + if (sizeof($graphs)) { + foreach($graphs as $graph) { + if (is_graph_allowed($graph['local_graph_id'], $user)) { + $ngraph[$graph['local_graph_id']] = $graph['local_graph_id']; + } + } + } + } + } + }else{ + if ($sites != '') { + $hosts = db_fetch_cell('SELECT GROUP_CONCAT(id) FROM host WHERE site_id IN(' . $sites . ')'); + } + + if ($hosts != '') { + $sql_where = 'gl.host_id IN(' . $hosts . ')'; + } + + $graphs = get_allowed_graphs($sql_where, 'gtg.title_cache', '', $total_rows, $user); + + if (sizeof($graphs)) { + foreach($graphs as $graph) { + if (is_graph_allowed($graph['local_graph_id'], $user)) { + $ngraph[$graph['local_graph_id']] = $graph['local_graph_id']; + } + } + } + } + + if (sizeof($ngraph)) { + /* open a pipe to rrdtool for writing */ + $rrdtool_pipe = rrd_init(); + + foreach($ngraph as $local_graph_id) { + /* settings for preview graphs */ + $graph_data_array['export_filename'] = $export_path . '/graphs/thumb_' . $local_graph_id . '.png'; + + $graph_data_array['graph_height'] = $export['graph_height']; + $graph_data_array['graph_width'] = $export['graph_width']; + $graph_data_array['graph_nolegend'] = true; + $graph_data_array['export'] = true; + + check_remove($graph_data_array['export_filename']); + check_remove($export_path . '/graph_' . $local_graph_id . '.html'); + + export_log("Creating Graph '" . $graph_data_array['export_filename'] . "'"); + + rrdtool_function_graph($local_graph_id, 0, $graph_data_array, $rrdtool_pipe, $metadata, $user); + + $exported++; + + /* generate html files for each graph */ + export_log("Creating File '" . $export_path . '/graph_' . $local_graph_id . '.html'); + + $fp_graph_index = fopen($export_path . '/graph_' . $local_graph_id . '.html', 'w'); + + fwrite($fp_graph_index, ''); + + $rras = get_associated_rras($local_graph_id, ' AND dspr.id IS NOT NULL'); + + /* reset vars for actual graph image creation */ + unset($graph_data_array); + + /* generate graphs for each rra */ + if (sizeof($rras)) { + foreach ($rras as $rra) { + $graph_data_array['export_filename'] = $export_path . '/graphs/graph_' . $local_graph_id . '_' . $rra['id'] . '.png'; + $graph_data_array['export'] = true; + + check_remove($graph_data_array['export_filename']); + + export_log("Creating Graph '" . $graph_data_array['export_filename'] . "'"); + + rrdtool_function_graph($local_graph_id, $rra['id'], $graph_data_array, $rrdtool_pipe, $metadata, $user); + + $exported++; + + fwrite($fp_graph_index, "\n"); + fwrite($fp_graph_index, "'); + } + + fwrite($fp_graph_index, '
Graph - ' . get_graph_title($local_graph_id) . '
" . $rra['name'] . '
'); + fclose($fp_graph_index); + } + } + + /* close the rrdtool pipe */ + rrd_close($rrdtool_pipe); + } + + return $exported; +} + +function export_ftp_php_execute(&$export, $stExportDir, $stFtpType = 'ftp_php') { + global $aFtpExport; + + /* connect to foreign system */ + switch($stFtpType) { + case 'ftp': + $oFtpConnection = ftp_connect($aFtpExport['server'], $aFtpExport['port']); + + if (!$oFtpConnection) { + export_fatal($export, 'FTP Connection failed! Check hostname and port. Export can not continue.'); + }else { + export_log('Conection to remote server was successful.'); + } + break; + case 'sftp': + $oFtpConnection = ftp_ssl_connect($aFtpExport['server'], $aFtpExport['port']); + + if (!$oFtpConnection) { + export_fatal($export, 'SFTP Connection failed! Check hostname and port. Export can not continue.'); + }else { + export_log('Conection to remote server was successful.'); + } + break; + } + + /* login to foreign system */ + if (!ftp_login($oFtpConnection, $aFtpExport['username'], $aFtpExport['password'])) { + ftp_close($oFtpConnection); + export_fatal($export, 'FTP Login failed! Check username and password. Export can not continue.'); + }else { + export_log('Remote login was successful.'); + } + + /* set connection type */ + if ($aFtpExport['passive']) { + ftp_pasv($oFtpConnection, TRUE); + }else { + ftp_pasv($oFtpConnection, FALSE); + } + + /* change directories into the remote upload directory */ + if (!@ftp_chdir($oFtpConnection, $aFtpExport['remotedir'])) { + ftp_close($oFtpConnection); + export_fatal($export, "FTP Remote directory '" . $aFtpExport['remotedir'] . "' does not exist!. Export can not continue."); + } + + /* sanitize the remote location if the user has asked so */ + if ($export['export_sanitize_remote'] == 'on') { + export_log('Deleting remote files.'); + + /* get rid of the files first */ + $aFtpRemoteFiles = ftp_nlist($oFtpConnection, $aFtpExport['remotedir']); + + if (is_array($aFtpRemoteFiles)) { + foreach ($aFtpRemoteFiles as $stFile) { + export_log("Deleting remote file '" . $stFile . "'"); + @ftp_delete($oFtpConnection, $stFile); + } + } + + /* if the presentation is tree, you will have some directories too */ + if ($export['export_presentation'] == 'tree') { + $aFtpRemoteDirs = ftp_nlist($oFtpConnection, $aFtpExport['remotedir']); + + foreach ($aFtpRemoteDirs as $remote_dir) { + if (ftp_chdir($oFtpConnection, addslashes($remote_dir))) { + $aFtpRemoteFiles = ftp_nlist($oFtpConnection, '.'); + if (is_array($aFtpRemoteFiles)) { + foreach ($aFtpRemoteFiles as $stFile) { + export_log("Deleting Remote File '" . $stFile . "'"); + ftp_delete($oFtpConnection, $stFile); + } + } + ftp_chdir($oFtpConnection, '..'); + + export_log("Removing Remote Directory '" . $remote_dir . "'"); + ftp_rmdir($oFtpConnection, $remote_dir); + }else{ + ftp_close($oFtpConnection); + export_fatal($export, 'Unable to cd on remote system'); + } + } + } + + $aFtpRemoteFiles = ftp_nlist($oFtpConnection, $aFtpExport['remotedir']); + if (sizeof($aFtpRemoteFiles) > 0) { + ftp_close($oFtpConnection); + export_fatal($export, 'Problem sanitizing remote ftp location, must exit.'); + } + } + + /* upload files to remote system */ + export_log('Uploading files to remote location.'); + ftp_chdir($oFtpConnection, $aFtpExport['remotedir']); + export_ftp_php_uploaddir($stExportDir,$oFtpConnection); + + /* end connection */ + export_log('Closing ftp connection.'); + ftp_close($oFtpConnection); +} + +function export_ftp_php_uploaddir($dir,$oFtpConnection) { + global $aFtpExport; + + export_log("Uploading directory: '$dir' to remote location."); + if($dh = opendir($dir)) { + export_log('Uploading files to remote location.'); + while(($file = readdir($dh)) !== false) { + $filePath = $dir . '/' . $file; + if($file != '.' && $file != '..' && !is_dir($filePath)) { + if(!ftp_put($oFtpConnection, $file, $filePath, FTP_BINARY)) { + export_log("Failed to upload '$file'."); + } + } + + if (($file != '.') && + ($file != '..') && + (is_dir($filePath))) { + + export_log("Create remote directory: '$file'."); + ftp_mkdir($oFtpConnection,$file); + + export_log("Change remote directory to: '$file'."); + ftp_chdir($oFtpConnection,$file); + export_ftp_php_uploaddir($filePath,$oFtpConnection); + + export_log('Change remote directory: one up.'); + ftp_cdup($oFtpConnection); + } + } + closedir($dh); + } +} + +function export_ftp_ncftpput_execute($stExportDir) { + global $aFtpExport; + + chdir($stExportDir); + + /* set the initial command structure */ + $stExecute = 'ncftpput -R -V -r 1 -u ' . cacti_escapeshellarg($aFtpExport['username']) . ' -p ' . cacti_escapeshellarg($aFtpExport['password']); + + /* if the user requested passive mode, use it */ + if ($aFtpExport['passive']) { + $stExecute .= ' -F '; + } + + /* setup the port, server, remote directory and all files */ + $stExecute .= ' -P ' . cacti_escapeshellarg($aFtpExport['port']) . ' ' . cacti_escapeshellarg($aFtpExport['server']) . ' ' . cacti_escapeshellarg($aFtpExport['remotedir']) . '.'; + + /* run the command */ + $iExecuteReturns = 0; + system($stExecute, $iExecuteReturns); + + $aNcftpputStatusCodes = array ( + 'Success.', + 'Could not connect to remote host.', + 'Could not connect to remote host - timed out.', + 'Transfer failed.', + 'Transfer failed - timed out.', + 'Directory change failed.', + 'Directory change failed - timed out.', + 'Malformed URL.', + 'Usage error.', + 'Error in login configuration file.', + 'Library initialization failed.', + 'Session initialization failed.'); + + export_log('Ncftpput returned: ' . $aNcftpputStatusCodes[$iExecuteReturns]); +} + +function export_post_ftp_upload(&$export, $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 ($export['export_temp_directory'] != $stExportDir) { + rmdir($stExportDir); + } + } +} + +function write_branch_conf($tree_id, $branch_id, $type, $host_id, $sub_id, $user, $export_path) { + static $conf_files = array(); + $total_rows = 0; + $graph_count = 0; + + if ($type == 'branch') { + $conf_file = $export_path . '/tree_' . $tree_id . '_branch_' . $branch_id . '.conf'; + + if (isset($conf_files[$conf_file])) return; + + $graphs = db_fetch_assoc_prepared('SELECT DISTINCT local_graph_id + FROM graph_tree_items + WHERE graph_tree_id = ? + AND parent = ? + AND local_graph_id > 0 + ORDER BY position', array($tree_id, $branch_id)); + }elseif ($type == 'host') { + $conf_file = $export_path . '/host_' . $host_id . '.conf'; + + if (isset($conf_files[$conf_file])) return; + + $graphs = get_allowed_graphs('gl.host_id=' . $host_id, 'gtg.title_cache', '', $total_rows, $user); + }elseif ($type == 'host_gt') { + $conf_file = $export_path . '/host_' . $host_id . '_gt_' . $sub_id . '.conf'; + + if (isset($conf_files[$conf_file])) return; + + $graphs = get_allowed_graphs('gl.host_id=' . $host_id . ' AND gl.graph_template_id=' . $sub_id, 'gtg.title_cache', '', $total_rows, $user); + }elseif ($type == 'host_dq') { + $conf_file = $export_path . '/host_' . $host_id . '_dq_' . $sub_id . '.conf'; + + if (isset($conf_files[$conf_file])) return; + + $graphs = get_allowed_graphs('gl.host_id=' . $host_id . ' AND gl.snmp_query_id=' . $sub_id, 'gtg.title_cache', '', $total_rows, $user); + }elseif ($type == 'host_dqi') { + $parts = explode(':', $sub_id); + $dq = $parts[0]; + $index = clean_up_name($parts[1]); + $conf_file = $export_path . '/host_' . $host_id . '_dq_' . $dq . '_dqi_' . $index . '.conf'; + + if (isset($conf_files[$conf_file])) return; + + $graphs = get_allowed_graphs('gl.host_id=' . $host_id . ' AND gl.snmp_query_id=' . $dq . ' AND gl.snmp_index=' . db_qstr($parts[1]), 'gtg.title_cache', '', $total_rows, $user); + } + + if (sizeof($graphs)) { + $fp = fopen($conf_file, 'w'); + $graph_str = ''; + + foreach($graphs as $graph) { + if ($host_id == 0) { + if (is_graph_allowed($graph['local_graph_id'], $user)) { + $graph_str .= ($graph_count > 0 ? ',':'') . $graph['local_graph_id']; + $graph_count++; + } + }else{ + $graph_str .= ($graph_count > 0 ? ',':'') . $graph['local_graph_id']; + $graph_count++; + } + } + + fwrite($fp, $graph_str . "\n"); + fclose($fp); + } + + return $graph_count; +} + +function export_generate_tree_html($export_path, $tree, $parent, $expand_hosts, $user, $jstree) { + static $depth = 2; + + $total_rows = 0; + + $jstree .= str_repeat("\t", $depth) . "\n"; + + return $jstree; +} + +function tree_export(&$export, $export_path) { + global $config; + + $jstree = "
\n"; + $user = $export['export_effective_user']; + $trees = $export['graph_tree']; + $ntree = array(); + $sql_where = ''; + $total_rows = 0; + $parent = 0; + + if ($user == 0) { + $user = -1; + } + + if ($trees != '') { + $sql_where = 'gt.id IN(' . $trees . ')'; + } + + $trees = get_allowed_trees(false, false, $sql_where, 'name', '', $total_rows, $user); + + if (sizeof($trees)) { + foreach($trees as $tree) { + $jstree .= "\t
  • " . get_tree_name($tree['id']) . "\n";; + $jstree = export_generate_tree_html($export_path, $tree, $parent, $export['export_expand_hosts'], $user, $jstree); + $jstree .= "\t
  • \n"; + } + } + + if ($jstree != '') { + $jstree .= "
    \n"; + + $fp = fopen($export_path . '/index.html', 'w'); + + if (is_resource($fp)) { + fwrite($fp, $jstree); + fclose($fp); + } + } +} + +/* create_export_directory_structure - builds the export directory strucutre and copies + graphics and treeview scripts to those directories. + @arg $cacti_root_path - the directory where Cacti is installed + $dir - the export directory where graphs will either be staged or located. +*/ +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($export, "Create directory '" . $dir . "/js' failed. Can not continue"); + } + if (!mkdir("$dir/js/themes/default", 0755, true)) { + export_fatal($export, "Create directory '" . $dir . "/js/themes/default' failed. Can not continue"); + } + if (!mkdir("$dir/js/images", 0755, true)) { + export_fatal($export, "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($export, "Create directory '" . $dir . "/graphs' failed. Can not continue"); + } + } + + /* css */ + copy("$cacti_root_path/include/themes/modern/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/themes/modern/default/$file", "$dir/js/themes/default/$file"); + } + + /* jquery-ui theme files */ + $files = array( + 'bar-alpha.png', + 'bar-opacity.png', + 'bar.png', + 'bar-pointer.png', + 'map-opacity.png', + 'map.png', + 'map-pointer.png', + 'preview-opacity.png', + 'ui-bg_flat_0_aaaaaa_40x100.png', + 'ui-bg_flat_75_ffffff_40x100.png', + 'ui-bg_glass_55_fbf9ee_1x400.png', + 'ui-bg_glass_65_ffffff_1x400.png', + 'ui-bg_glass_75_dadada_1x400.png', + 'ui-bg_glass_75_e6e6e6_1x400.png', + 'ui-bg_glass_95_fef1ec_1x400.png', + 'ui-bg_highlight-soft_75_cccccc_1x100.png', + 'ui-colorpicker.png', + 'ui-icons_222222_256x240.png', + 'ui-icons_2e83ff_256x240.png', + 'ui-icons_454545_256x240.png', + 'ui-icons_888888_256x240.png', + 'ui-icons_cd0a0a_256x240.png' + ); + foreach($files as $file) { + copy("$cacti_root_path/include/themes/modern/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/themes/modern/jquery-ui.css", "$dir/js/jquery-ui.css"); +} + +function get_host_description($host_id) { + return db_fetch_cell_prepared('SELECT description FROM host WHERE id = ?', array($host_id)); +} + +function get_tree_name($tree_id) { + return db_fetch_cell_prepared('SELECT name FROM graph_tree WHERE id = ?', array($tree_id)); +} + +/* $path to the directory to delete or clean */ +/* $deldir (optionnal parameter, true as default) delete the diretory (true) or just clean it (false) */ +function del_directory($path, $deldir = true) { + /* check if the directory name have a '/' at the end, add if not */ + if ($path[strlen($path)-1] != '/') { + $path .= '/'; + } + + /* cascade through the directory structure(s) until they are all delected */ + if (is_dir($path)) { + $d = opendir($path); + while ($f = readdir($d)) { + if ($f != '.' && $f != '..') { + $rf = $path . $f; + + /* if it is a directory, recursive call to the function */ + if (is_dir($rf)) { + del_directory($rf); + }else if (is_file($rf) && is_writable($rf)) { + unlink($rf); + } + } + } + closedir($d); + + /* if $deldir is true, remove the directory */ + if ($deldir && is_writable($path)) { + rmdir($path); + } + } +} + +function check_remove($filename) { + if (file_exists($filename) && is_writable($filename)) { + unlink($filename); + } +} + +define('HTML_HEADER_TREE', +" + + + + Cacti + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    + + + + + +
    +  Cacti - http://www.cacti.net/ + + +
    +
    +
    +
    + + + + +
    + Exported Graphs +
    +
    +
    +
    +
    + + + + +
    \n"); + +define('HTML_GRAPH_FOOTER_TREE', " +
    \n" +); + +define('HTML_FOOTER_TREE', " + + + + + + +\n" +); + +/* HTML header for the Classic Presentation */ +define('HTML_HEADER_CLASSIC', " + + + + cacti + + + + + + + + + + + + + + + + + + + + +
    + + + + + +
    +  Cacti - http://www.cacti.net/ + + +
    +
    +
    +
    + + + + +
    + Exported Graphs +
    +
    + +
    +
    \n" +); + +/* Traditional Graph Export Representation Graph Headers */ +define('HTML_GRAPH_HEADER_ONE_CLASSIC', " + + + + + " +); + +define('HTML_GRAPH_FOOTER_CLASSIC', " +
    + + + +
    " +); + +define('HTML_GRAPH_HEADER_TWO_CLASSIC', " +
    +
    +

    " +); + +define('HTML_FOOTER_CLASSIC', " +
    + + " +); + diff --git a/gexport.php b/gexport.php new file mode 100644 index 0000000..653345e --- /dev/null +++ b/gexport.php @@ -0,0 +1,757 @@ + __('Delete'), + '2' => __('Enable'), + '3' => __('Disable'), + '4' => __('Export Now') +); + +$export_timing = array( + __('Periodic'), + __('Daily'), + __('Hourly') +); + +set_default_action(); + +switch (get_request_var('action')) { + case 'save': + export_form_save(); + + break; + case 'actions': + export_form_actions(); + + break; + case 'edit': + top_header(); + + export_edit(); + + bottom_footer(); + + break; + default: + top_header(); + + gexport(); + + bottom_footer(); + + break; +} + +/* -------------------------- + The Save Function + -------------------------- */ + +function export_form_save() { + if (isset_request_var('save_component_export')) { + $save['id'] = get_filter_request_var('id'); + $save['name'] = form_input_validate(get_nfilter_request_var('name'), 'name', '', false, 3); + $save['export_type'] = form_input_validate(get_nfilter_request_var('export_type'), 'export_type', '^local|ftp|scp|sftp|rsync$', false, 3); + + $save['enabled'] = isset_request_var('enabled') ? 'on':''; + + $save['export_presentation'] = form_input_validate(get_nfilter_request_var('export_presentation'), 'export_presentation', '^preview|tree$', false, 3); + $save['export_effective_user'] = form_input_validate(get_nfilter_request_var('export_effective_user'), 'export_effective_user', '', true, 3); + $save['export_expand_hosts'] = form_input_validate(get_nfilter_request_var('export_expand_hosts'), 'export_expand_hosts', '^on|off$', false, 3); + + $save['export_theme'] = form_input_validate(get_nfilter_request_var('export_theme'), 'export_theme', '', false, 3); + + if (isset_request_var('graph_tree')) { + $save['graph_tree'] = form_input_validate(implode(',', get_nfilter_request_var('graph_tree')), 'graph_tree', '', true, 3); + }else{ + $save['graph_tree'] = ''; + } + + if (isset_request_var('graph_tree')) { + $save['graph_site'] = form_input_validate(implode(',', get_nfilter_request_var('graph_site')), 'graph_site', '', true, 3); + }else{ + $save['graph_site'] = ''; + } + + $save['graph_width'] = form_input_validate(get_nfilter_request_var('graph_width'), 'graph_width', '^[0-9]+$', false, 3); + $save['graph_height'] = form_input_validate(get_nfilter_request_var('graph_height'), 'graph_height', '^[0-9]+$', false, 3); + $save['graph_thumbnails'] = isset_request_var('graph_thumbnails') ? 'on':''; + $save['graph_perpage'] = form_input_validate(get_nfilter_request_var('graph_perpage'), 'graph_perpage', '^[0-9]+$', false, 3); + $save['graph_columns'] = form_input_validate(get_nfilter_request_var('graph_columns'), 'graph_columns', '^[0-9]+$', false, 3); + $save['graph_max'] = form_input_validate(get_nfilter_request_var('graph_max'), 'graph_max', '^[0-9]+$', false, 3); + + $save['export_directory'] = form_input_validate(get_nfilter_request_var('export_directory'), 'export_directory', '', false, 3); + $save['export_temp_directory'] = form_input_validate(get_nfilter_request_var('export_temp_directory'), 'export_temp_directory', '', false, 3); + $save['export_timing'] = form_input_validate(get_nfilter_request_var('export_timing'), 'export_timing', '^periodic|hourly|daily$', false, 3); + $save['export_skip'] = form_input_validate(get_nfilter_request_var('export_skip'), 'export_skip', '^[0-9]+$', false, 3); + $save['export_hourly'] = form_input_validate(get_nfilter_request_var('export_hourly'), 'export_hourly', '^[0-9]+$', false, 3); + $save['export_daily'] = form_input_validate(get_nfilter_request_var('export_daily'), 'export_daily', '^[0-9]+:[0-9]+$', false, 3); + + $save['export_sanitize_remote'] = isset_request_var('export_sanitize_remote') ? 'on':''; + + $save['export_host'] = form_input_validate(get_nfilter_request_var('export_host'), 'export_host', '', true, 3); + $save['export_port'] = form_input_validate(get_nfilter_request_var('export_port'), 'export_port', '^[0-9]+$', true, 3); + + $save['export_passive'] = isset_request_var('export_passive') ? 'on':''; + + $save['export_user'] = form_input_validate(get_nfilter_request_var('export_user'), 'export_user', '', true, 3); + $save['export_password'] = form_input_validate(get_nfilter_request_var('export_password'), 'export_password', '', true, 3); + $save['export_private_key_path'] = form_input_validate(get_nfilter_request_var('export_private_key_path'), 'export_private_key_path', '', true, 3); + + if (!is_error_message()) { + $export_id = sql_save($save, 'graph_exports'); + + if ($export_id) { + raise_message(1); + }else{ + raise_message(2); + } + } + + header('Location: gexport.php?action=edit&header=false&id=' . (empty($export_id) ? get_request_var('id') : $export_id)); + } +} + +function duplicate_export($_export_id, $export_title) { + global $fields_export_edit; + + $export = db_fetch_row_prepared('SELECT * FROM graph_exports WHERE id = ?', array($_export_id)); + + /* substitute the title variable */ + $export['name'] = str_replace('', $export['name'], $export_title); + + /* create new entry: device_template */ + $save['id'] = 0; + + reset($fields_export_edit); + while (list($field, $array) = each($fields_export_edit)) { + if (!preg_match('/^hidden/', $array['method'])) { + $save[$field] = $export[$field]; + } + } + + $export_id = sql_save($save, 'export'); +} + +/* ------------------------ + The 'actions' function + ------------------------ */ + +function export_form_actions() { + global $export_actions; + + /* if we are to save this form, instead of display it */ + if (isset_request_var('selected_items')) { + $selected_items = sanitize_unserialize_selected_items(get_nfilter_request_var('selected_items')); + + if ($selected_items != false) { + if (get_nfilter_request_var('drp_action') === '1') { /* delete */ + /* do a referential integrity check */ + if (sizeof($selected_items)) { + foreach($selected_items as $export_id) { + /* ================= input validation ================= */ + input_validate_input_number($export_id); + /* ==================================================== */ + + $export_ids[] = $export_id; + } + } + + if (isset($export_ids)) { + db_execute('DELETE FROM graph_exports WHERE ' . array_to_sql_or($export_ids, 'id')); + } + }elseif (get_nfilter_request_var('drp_action') === '2') { /* enable */ + for ($i=0;($i'; + $export_array[] = $matches[1]; + } + } + + top_header(); + + form_start('gexport.php', 'export_actions'); + + html_start_box($export_actions{get_nfilter_request_var('drp_action')}, '60%', '', '3', 'center', ''); + + if (isset($export_array)) { + if (get_nfilter_request_var('drp_action') === '1') { /* delete */ + print " + +

    " . __n('Click \'Continue\' to delete the following Graph Export Definition.', 'Click \'Continue\' to delete following Graph Export Definitions.', sizeof($export_array)) . "

    +
      $export_list
    + + \n"; + + $save_html = " "; + }elseif (get_nfilter_request_var('drp_action') === '2') { /* disable */ + print " + +

    " . __n('Click \'Continue\' to disable the following Graph Export Definition.', 'Click \'Continue\' to disable following Graph Export Definitions.', sizeof($export_array)) . "

    +
      $export_list
    + + \n"; + + $save_html = " "; + }elseif (get_nfilter_request_var('drp_action') === '3') { /* enable */ + print " + +

    " . __n('Click \'Continue\' to enable the following Graph Export Definition.', 'Click \'Continue\' to enable following Graph Export Definitions.', sizeof($export_array)) . "

    +
      $export_list
    + + \n"; + + $save_html = " "; + } + }else{ + print "" . __('You must select at least one Graph Export Definition.') . "\n"; + $save_html = ""; + } + + print " + + + + + $save_html + + \n"; + + html_end_box(); + + form_end(); + + bottom_footer(); +} + +/* --------------------- + Graph Export Functions + --------------------- */ + +function export_edit() { + global $fields_export_edit; + + /* ================= input validation ================= */ + get_filter_request_var('id'); + /* ==================================================== */ + + if (!isempty_request_var('id')) { + $export = db_fetch_row_prepared('SELECT * FROM graph_exports WHERE id = ?', array(get_request_var('id'))); + $header_label = __('Graph Export Definition [edit: %s]', $export['name']); + }else{ + $header_label = __('Graph Export Definition [new]'); + } + + form_start('gexport.php', 'export_edit'); + + html_start_box($header_label, '100%', '', '3', 'center', ''); + + draw_edit_form( + array( + 'config' => array('no_form_tag' => true), + 'fields' => inject_form_variables($fields_export_edit, (isset($export) ? $export : array())) + ) + ); + + html_end_box(); + + form_hidden_box('id', (isset($export['id']) ? $export['id'] : '0'), ''); + form_hidden_box('save_component_export', '1', ''); + + form_save_button('gexport.php', 'return'); + + ?> + + + + +
    + + + + + + + + + +
    + + + '> + + + + + + ' id='refresh'> + + ' id='clear'> +
    + '> +
    + + + + array( + 'filter' => FILTER_VALIDATE_INT, + 'pageset' => true, + 'default' => '-1' + ), + 'page' => array( + 'filter' => FILTER_VALIDATE_INT, + 'default' => '1' + ), + 'filter' => array( + 'filter' => FILTER_CALLBACK, + 'pageset' => true, + 'default' => '', + 'options' => array('options' => 'sanitize_search_string') + ), + 'sort_column' => array( + 'filter' => FILTER_CALLBACK, + 'default' => 'name', + 'options' => array('options' => 'sanitize_search_string') + ), + 'sort_direction' => array( + 'filter' => FILTER_CALLBACK, + 'default' => 'ASC', + 'options' => array('options' => 'sanitize_search_string') + ) + ); + + validate_store_request_vars($filters, 'sess_gexport'); + /* ================= input validation ================= */ + + export_filter(); + + $total_rows = 0; + $exports = array(); + + if (get_request_var('rows') == '-1') { + $rows = read_config_option('num_rows_table'); + }else{ + $rows = get_request_var('rows'); + } + + $exports = get_export_records($total_rows, $rows); + + $nav = html_nav_bar('gexport.php?filter=' . get_request_var('filter'), MAX_DISPLAY_PAGES, get_request_var('page'), $rows, $total_rows, 5, __('Export Definitions'), 'page', 'main'); + + form_start('gexport.php', 'chk'); + + print $nav; + + html_start_box('', '100%', '', '3', 'center', ''); + + $display_text = array( + 'name' => array('display' => __('Export Name'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The name of this Graph Export Definition.')), + 'id' => array('display' => __('ID'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The internal ID of the Graph Export Definition.')), + 'export_timing' => array('display' => __('Schedule'), 'align' => 'right', 'sort' => 'DESC', 'tip' => __('The frequency that Graphs will be exported.')), + 'nosort2' => array('display' => __('Export Time'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The either the time between exports, or the export time.')), + 'nosort' => array('display' => __('Enabled'), 'align' => 'right', 'tip' => __('If enabled, this Graph Export definition will run as required.')), + 'status' => array('display' => __('Status'), 'align' => 'right', 'tip' => __('The current Graph Export Status.')), + + 'nosort1' => array('display' => __('Exporting (Sites/Trees)'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('What is being Exported.')), + 'export_effective_user' => array('display' => __('Effective User'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The user that this export will impersonate.')), + 'last_runtime' => array('display' => __('Last Runtime'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The last runtime for the Graph Export.')), + 'total_graphs' => array('display' => __('Graphs'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The number of Graphs Exported on the last run.')), + 'last_started' => array('display' => __('Last Started'), 'align' => 'right', 'sort' => 'ASC', 'tip' => __('The last time that this Graph Export was started.')) + ); + + html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false); + + $i = 0; + if (sizeof($exports)) { + foreach ($exports as $export) { + $user = db_fetch_cell_prepared('SELECT username + FROM user_auth + WHERE id = ?', + array($export['export_effective_user'])); + + form_alternate_row('line' . $export['id'], true); + form_selectable_cell(filter_value($export['name'], get_request_var('filter'), 'gexport.php?action=edit&id=' . $export['id']), $export['id']); + form_selectable_cell($export['id'], $export['id'], '', 'text-align:right'); + + form_selectable_cell(__(ucfirst($export['export_timing'])), $export['id'], '', 'text-align:right'); + + // ToDo: Export Timing + switch($export['export_timing']) { + case 'periodic': + form_selectable_cell($export['export_skip'] . ' Intervals', $export['id'], '', 'text-align:right'); + break; + case 'hourly': + form_selectable_cell($export['export_hourly'] . ' ' . __('MM'), $export['id'], '', 'text-align:right'); + break; + case 'daily': + form_selectable_cell($export['export_daily'] . ' ' . __('HH:MM'), $export['id'], '', 'text-align:right'); + break; + } + + form_selectable_cell($export['enabled'] == '' ? __('No'):__('Yes'), $export['id'], '', 'text-align:right'); + + switch($export['status']) { + case '0': + form_selectable_cell("" . __('Idle') . "", $export['id'], '', 'text-align:right'); + break; + case '1': + form_selectable_cell("" . __('Running') . "", $export['id'], '', 'text-align:right'); + break; + case '2': + form_selectable_cell("" . __('Error') . "", $export['id'], '', 'text-align:right'); + break; + } + + if ($export['export_presentation'] == 'preview') { + if ($export['graph_site'] == '0') { + form_selectable_cell(__('All Sites'), $export['id'], '', 'text-align:right'); + }else{ + $sites = db_fetch_cell('SELECT GROUP_CONCAT(name ORDER BY name SEPARATOR ", ") FROM sites WHERE id IN(' . $export['graph_site'] . ')'); + form_selectable_cell($sites, $export['id'], '', 'text-align:right'); + } + }else{ + if ($export['graph_tree'] == '0') { + form_selectable_cell(__('All Trees'), $export['id'], '', 'text-align:right'); + }else{ + $trees = db_fetch_cell('SELECT GROUP_CONCAT(name ORDER BY name SEPARATOR ", ") FROM graph_tree WHERE id IN(' . $export['graph_tree'] . ')'); + form_selectable_cell($trees, $export['id'], '', 'text-align:right'); + } + } + + form_selectable_cell($export['export_effective_user'] == 0 ? __('N/A'):$user, $export['id'], '', 'text-align:right'); + + if ($export['last_started'] != '0000-00-00 00:00:00') { + form_selectable_cell(round($export['last_runtime'],2) . ' ' . __('Sec'), $export['id'], '', 'text-align:right'); + form_selectable_cell(number_format_i18n($export['total_graphs']), $export['id'], '', 'text-align:right'); + form_selectable_cell($export['last_started'], $export['id'], '', 'text-align:right'); + }else{ + form_selectable_cell(__('N/A'), $export['id'], '', 'text-align:right'); + form_selectable_cell(__('N/A'), $export['id'], '', 'text-align:right'); + form_selectable_cell(__('Never'), $export['id'], '', 'text-align:right'); + } + + form_checkbox_cell($export['name'], $export['id']); + form_end_row(); + } + }else{ + print "" . __('No Graph Export Definitions') . "\n"; + } + + html_end_box(false); + + if (sizeof($exports)) { + print $nav; + } + + /* draw the dropdown containing a list of available actions for this form */ + draw_actions_dropdown($export_actions); + + form_end(); +} diff --git a/poller_export.php b/poller_export.php new file mode 100644 index 0000000..737b22c --- /dev/null +++ b/poller_export.php @@ -0,0 +1,118 @@ +#!/usr/bin/php -q +This script is only meant to run at the command line.'); +} + +/* Start Initialization Section */ +$dir = dirname(__FILE__); +chdir($dir); + +if (substr_count(strtolower($dir), 'gexport')) { + chdir('../../'); +} + +include('./include/global.php'); +include_once($config['base_path'] . '/lib/poller.php'); +include_once($config['base_path'] . '/plugins/gexport/functions.php'); +include_once($config['base_path'] . '/lib/rrd.php'); + +/* Let PHP Run Just as Long as It Has To */ +ini_set('max_execution_time', '0'); + +/* process calling arguments */ +$parms = $_SERVER['argv']; +array_shift($parms); + +global $debug; + +$debug = FALSE; +$force = FALSE; +$id = 0; + +if (sizeof($parms)) { + foreach($parms as $parameter) { + if (strpos($parameter, '=')) { + list($arg, $value) = explode('=', $parameter); + } else { + $arg = $parameter; + $value = ''; + } + + switch ($arg) { + case '--id': + $id = $value; + break; + case '-d': + case '--debug': + $debug = TRUE; + break; + case '-f': + case '--force': + $force = TRUE; + break; + case '--version': + case '-V': + case '-v': + display_version(); + exit; + case '--help': + case '-H': + case '-h': + display_help(); + exit; + default: + echo 'ERROR: Invalid Parameter ' . $parameter . "\n\n"; + display_help(); + exit; + } + } +} + +/* graph export */ +graph_export($id, $force); + +/* display_version - displays version information */ +function display_version() { + $version = db_fetch_cell('SELECT cacti FROM version'); + echo "Cacti Graph Export Poller, Version $version, " . COPYRIGHT_YEARS . "\n"; +} + +/* display_help - displays the usage of the function */ +function display_help () { + display_version(); + + echo "\nusage: poller_export.php [-f|--force] [-d|--debug]\n\n"; + echo "Cacti's Graph Export poller. This poller will export parts of the Cacti\n"; + echo "website into a static representation.\n\n"; + echo "Optional:\n"; + echo " --force - Force export to run now running now\n"; + echo " --debug - Display verbose output during execution\n\n"; +} diff --git a/setup.php b/setup.php new file mode 100644 index 0000000..a5f1c4a --- /dev/null +++ b/setup.php @@ -0,0 +1,478 @@ +read())) { + if ($entry != '.' && $entry != '..') { + if (is_dir($config['base_path'] . '/include/themes/' . $entry)) { + $themes[$entry] = ucwords($entry); + } + } + } + asort($themes); + $dir->close(); + + if ($config['cacti_server_os'] == 'unix') { + $tmp = '/tmp/'; + }else{ + $tmp = getenv('TEMP'); + } + + if (isset($_SESSION['gexport_message']) && $_SESSION['gexport_message'] != '') { + $messages['gexport_message'] = array('message' => $_SESSION['gexport_message'], 'type' => 'info'); + } + + $menu['Configuration']['plugins/gexport/gexport.php'] = __('Graph Exports'); + + $sites = array_rekey(db_fetch_assoc('SELECT "0" AS id, "All Sites" AS name UNION SELECT id, name FROM sites ORDER BY name'), 'id', 'name'); + $trees = array_rekey(db_fetch_assoc('SELECT "0" AS id, "All Trees" AS name UNION SELECT id, name FROM graph_tree ORDER BY name'), 'id', 'name'); + + $fields_export_edit = array( + 'export_hdr_general' => array( + 'friendly_name' => __('General'), + 'collapsible' => 'true', + 'method' => 'spacer', + ), + 'name' => array( + 'friendly_name' => __('Export Name'), + 'description' => __('The name of this Graph Export Definition.'), + 'method' => 'textbox', + 'value' => '|arg1:name|', + 'default' => 'New Graph Export', + 'max_length' => '64', + 'size' => '40' + ), + 'export_type' => array( + 'friendly_name' => __('Export Method'), + 'description' => __('Choose which export method to use.'), + 'method' => 'drop_array', + 'value' => '|arg1:export_type|', + 'default' => 'disabled', + 'array' => array( + 'local' => __('Local'), + 'ftp' => __('FTP'), + 'sftp' => __('SFTP'), + 'scp' => __('SCP'), + 'rsync' => __('RSYNC') + ) + ), + 'enabled' => array( + 'friendly_name' => __('Enabled'), + 'description' => __('Check this Checkbox if you wish this Graph Export Definition to be enabled.'), + 'value' => '|arg1:enabled|', + 'default' => 'on', + 'method' => 'checkbox', + ), + 'export_theme' => array( + 'friendly_name' => __('Theme'), + 'description' => __('Please select one of the available Themes to skin your Cacti Graph Exports with.'), + 'method' => 'drop_array', + 'value' => '|arg1:export_theme|', + 'default' => 'modern', + 'array' => $themes + ), + 'export_presentation' => array( + 'friendly_name' => __('Presentation Method'), + 'description' => __('Choose which presentation would you want for the html generated pages. If you choose classical presentation, the Graphs will be in a only-one-html page. If you choose tree presentation, the graph tree architecture will be kept in the static html pages'), + 'method' => 'drop_array', + 'value' => '|arg1:export_presentation|', + 'default' => 'disabled', + 'array' => array( + 'preview' => __('Preview Presentation'), + 'tree' => __('Tree Presentation'), + ) + ), + 'export_hdr_timing' => array( + 'friendly_name' => __('Export Timing'), + 'method' => 'spacer', + ), + 'export_timing' => array( + 'friendly_name' => __('Timing Method'), + 'description' => __('Choose when to Export Graphs.'), + 'method' => 'drop_array', + 'value' => '|arg1:export_timing|', + 'default' => 'export_hourly', + 'array' => array( + 'periodic' => __('Periodic'), + 'hourly' => __('Hourly'), + 'daily' => __('Daily') + ), + ), + 'export_skip' => array( + 'friendly_name' => __('Periodic Export Cycle'), + 'description' => __('How often do you wish Cacti to Export Graphs. This is the unit of Polling Cycles you wish to export Graphs.'), + 'method' => 'drop_array', + 'value' => '|arg1:export_skip|', + 'array' => array( + 1 => __('Every Polling Cycle'), + 2 => __('Every %d Polling Cycles', 2), + 3 => __('Every %d Polling Cycles', 3), + 4 => __('Every %d Polling Cycles', 4), + 5 => __('Every %d Polling Cycles', 5), + 6 => __('Every %d Polling Cycles', 6), + 7 => __('Every %d Polling Cycles', 7), + 8 => __('Every %d Polling Cycles', 8), + 9 => __('Every %d Polling Cycles', 9), + 10 => __('Every %d Polling Cycles', 10), + 11 => __('Every %d Polling Cycles', 11), + 12 => __('Every %d Polling Cycles', 12) + ), + ), + 'export_hourly' => array( + 'friendly_name' => __('Hourly at specified minutes'), + 'description' => __('If you want Cacti to export static images on an hourly basis, put the minutes of the hour when to do that. Cacti assumes that you run the data gathering script every 5 minutes, so it will round your value to the one closest to its runtime. For instance, 43 would equal 40 minutes past the hour.'), + 'method' => 'textbox', + 'placeholder' => 'MM', + 'value' => '|arg1:export_hourly|', + 'default' => '00', + 'max_length' => '10', + 'size' => '5' + ), + 'export_daily' => array( + 'friendly_name' => __('Daily at specified time'), + 'description' => __('If you want Cacti to export static images on an daily basis, put here the time when to do that. Cacti assumes that you run the data gathering script every 5 minutes, so it will round your value to the one closest to its runtime. For instance, 21:23 would equal 20 minutes after 9 PM.'), + 'method' => 'textbox', + 'placeholder' => 'HH:MM', + 'value' => '|arg1:export_daily|', + 'default' => '00:00', + 'max_length' => '10', + 'size' => '5' + ), + 'export_thumb_options' => array( + 'friendly_name' => __('Graph Selection & Settings'), + 'collapsible' => 'true', + 'method' => 'spacer', + ), + 'export_effective_user' => array( + 'friendly_name' => __('Effective User'), + 'description' => __('The user name to utilize for establishing permissions to Cacti Graphs. This user name will be used to determine which Graphs/Trees can be exported. N/A means don\'t assume any security is in place.'), + 'method' => 'drop_sql', + 'value' => '|arg1:export_effective_user|', + 'sql' => 'SELECT id, username AS name FROM user_auth ORDER BY name', + 'none_value' => 'N/A', + 'default' => '0' + ), + 'graph_tree' => array( + 'friendly_name' => __('Tree'), + 'description' => __('The Tree(s) to export.'), + 'method' => 'drop_multi', + 'value' => '|arg1:graph_tree|', + 'array' => $trees, + 'default' => '0' + ), + 'export_expand_hosts' => array( + 'friendly_name' => __('Expand Tree Devices'), + 'description' => __('This settings determines if the tree hosts will be expanded or not. If set to expanded, each host will have a sub-folder containing either data templates or data query items.'), + 'method' => 'drop_array', + 'value' => '|arg1:export_expand_hosts|', + 'default' => 'off', + 'array' => array( + 'off' => __('Off'), + 'on' => __('On') + ) + ), + 'graph_site' => array( + 'friendly_name' => __('Site'), + 'description' => __('The the Site for Cacti Graphs to be Exported from.'), + 'method' => 'drop_multi', + 'value' => '|arg1:graph_site|', + 'array' => $sites, + 'default' => '0' + ), + 'graph_width' => array( + 'friendly_name' => __('Graph Thumbnail Width'), + 'description' => __('The default width of Thumbnail Graphs in pixels.'), + 'method' => 'textbox', + 'value' => '|arg1:graph_width|', + 'default' => '300', + 'max_length' => '10', + 'size' => '5' + ), + 'graph_height' => array( + 'friendly_name' => __('Graph Thumbnail Height'), + 'description' => __('The height of Thumbnail Graphs in pixels.'), + 'method' => 'textbox', + 'value' => '|arg1:graph_height|', + 'default' => '100', + 'max_length' => '10', + 'size' => '5' + ), + 'graph_thumbnails' => array( + 'friendly_name' => __('Default View Thumbnails'), + 'description' => __('Check this if you want the default Graph View to be in Thumbnail mode.'), + 'method' => 'checkbox', + 'value' => '|arg1:export_sanitize_remote|', + 'max_length' => '255' + ), + 'graph_columns' => array( + 'friendly_name' => __('Default Graph Columns'), + 'description' => __('The number of columns to use by default when displaying Graphs.'), + 'method' => 'textbox', + 'value' => '|arg1:graph_columns|', + 'default' => '2', + 'max_length' => '5', + 'size' => '5' + ), + 'graph_perpage' => array( + 'friendly_name' => __('Graphs Per Page'), + 'description' => __('Choose the number of Graphs Per Page to display.'), + 'method' => 'drop_array', + 'value' => '|arg1:graph_perpage|', + 'default' => 20, + 'array' => $graphs_per_page, + ), + 'graph_max' => array( + 'friendly_name' => __('Maximum Graphs to Export'), + 'description' => __('After this number is reached, an error will be generated, but exporting will continue. Set to 0 for no limit.'), + 'method' => 'textbox', + 'value' => '|arg1:graph_max|', + 'default' => '2000', + 'max_length' => '5', + 'size' => '5' + ), + 'export_hdr_paths' => array( + 'friendly_name' => __('Export Location Information'), + 'collapsible' => 'true', + 'method' => 'spacer', + ), + 'export_directory' => array( + 'friendly_name' => __('Export Directory'), + 'description' => __('This is the directory, either on the local system or on the remote system, that will contain the exported data.'), + 'method' => 'dirpath', + 'value' => '|arg1:export_directory|', + 'max_length' => '255' + ), + 'export_temp_directory' => array( + 'friendly_name' => __('Local Scratch Directory'), + 'description' => __('This is the a directory that Cacti will temporarily store output prior to sending to the remote site via the transfer method. The contents of this directory will be deleted after the data is transferred.'), + 'method' => 'dirpath', + 'value' => '|arg1:export_temp_directory|', + 'default' => $tmp, + 'max_length' => '255' + ), + 'export_hdr_remote' => array( + 'friendly_name' => __('Remote Options'), + 'method' => 'spacer', + 'collapsible' => 'true' + ), + 'export_sanitize_remote' => array( + 'friendly_name' => __('Sanitize remote directory'), + 'description' => __('Check this if you want to delete any existing files in the FTP remote directory. This option is in use only when using the PHP built-in ftp functions.'), + 'method' => 'checkbox', + 'value' => '|arg1:export_sanitize_remote|', + 'max_length' => '255' + ), + 'export_host' => array( + 'friendly_name' => __('Remote Host'), + 'description' => __('Denotes the host to send Exported Graphs to.'), + 'placeholder' => 'hostname', + 'method' => 'textbox', + 'value' => '|arg1:export_host|', + 'max_length' => '255' + ), + 'export_port' => array( + 'friendly_name' => __('Remote Port'), + 'description' => __('Communication port to use for the export method if non-standard (leave empty for defaults).'), + 'placeholder' => 'default', + 'method' => 'textbox', + 'value' => '|arg1:export_port|', + 'max_length' => '10', + 'size' => '5' + ), + 'export_passive' => array( + 'friendly_name' => __('Use passive mode'), + 'description' => __('Check this if you want to connect in passive mode to the FTP server.'), + 'method' => 'checkbox', + 'value' => '|arg1:export_passive|', + 'max_length' => '255' + ), + 'export_user' => array( + 'friendly_name' => __('User'), + 'description' => __('Account to logon on the remote server (leave empty for defaults).'), + 'method' => 'textbox', + 'value' => '|arg1:export_user|', + 'max_length' => '20', + 'size' => 10 + ), + 'export_password' => array( + 'friendly_name' => __('Password'), + 'description' => __('Password for the remote ftp account (leave empty for blank).'), + 'method' => 'textbox_password', + 'value' => '|arg1:export_password|', + 'max_length' => '255', + 'size' => 30 + ), + 'export_private_key_path' => array( + 'friendly_name' => __('Private Key Path'), + 'description' => __('For SCP and RSYNC, enter the Private Key path if required.'), + 'method' => 'filepath', + 'value' => '|arg1:export_private_key_path|', + 'max_length' => '255', + 'size' => 50 + ) + ); +} + +function gexport_draw_navigation_text($nav) { + $nav['gexport.php:'] = array( + 'title' => __('Exported Cacti Graph Pages'), + 'mapping' => '', + 'url' => 'gexport.php', + 'level' => '0' + ); + + return $nav; +} +