您好,欢迎来到吉趣旅游网。
搜索
您的当前位置:首页Cacti和weathermap插件安装及使用文档

Cacti和weathermap插件安装及使用文档

来源:吉趣旅游网


使用Cacti监控你的网络

Cacti使用手册

摘自石头记(有部分修改)

作者:Warship

目录:

一、概述及Cacti的工作流程

二、Ubuntu的安装

三、Cacti的安装

四、Cacti的使用

五、Cacti插件weathermap

六、参考

七、附件

声明:本系列文档部分摘自石头记,如若转载请注明出处,本人保留文档的所有权,并

欢迎转载。也请继续关注石头记的其它技术文档。

一、概述及Cacti的工作流程

(一)概述

1. Cacti是用php语言实现的一个软件,它的主要功能是用snmp服务获取数据,然后用rrdtool储存和更新数据,当用户需要查看数据的时候用rrdtool生成图表呈现给用户。因此,snmp和rrdtool是cacti的关键。Snmp关系着数据的收集,rrdtool关系着数据存储和图表的生成。

2. Mysql配合PHP程序存储一些变量数据并对变量数据进行调用,如:主机名、主机ip、snmp团体名、端口号、模板信息等变量。

3. Snmp抓到数据不是存储在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对rrd文件的处理,rrd文件是大小固定的档案文件(Round Robin Archive),它能够存储的数据笔数在创建时就已经定义。关于RRDTool的知识请参阅RRDTool教学。

(二)Cacti的架构及工作流程

1. Cacti的架构

2. Cacti的工作流程

二、Ubuntu的安装

Ubuntu 是一个由社区开发的基于linux的操作系统,适用于笔记本电脑、桌面电脑和服务器。无论是在家庭、学校还是工作时使用,Ubuntu 都包含了所需的所有程序:无论是文字处理和电子邮件,还是 Web 服务和编程工具。

Ubuntu永远免费。无需支付任何许可费用。可以下载、使用以及与朋友、家庭、同学或同事分享,而绝对无需任何代价。

Ubuntu每6个月推出新的桌面版本和服务器版本。这意味着总是能够享受开源世界所提供的最新、最好的应用程序。

对于桌面版本,将拥有完整的创作、网络、绘图、图像处理程序和游戏。对于服务器版本,将只需获得配置运行时所需的软件,而没有任何额外的软件。

Ubuntu不会像传统linux那样需要繁琐的安装过程,它只需要执行一条或多条命令即可安装并建立好各个服务之间的关联,非常方便。所以在这里cacti采用的安装环境就是ubuntu 8.04 server 。

下面先来介绍一下ubuntu 8.04 server的安装。

1.Ubuntu的安装界面如图1所示,按回车键进行安装。

图1

2.安装过程中需要输入系统的主机名,如图2。

图2

3.进行磁盘分区,这里选择“使用整个磁盘”。之后按提示进行默认安装。

图3

4.设置非root用户的用户名和密码,如图4、图5、图6和图7所示。

图4

图5

图6

图7

5.设置代理服务器,这里选择置空。

图8

6.安装时应选择LAMP和OpenSSH服务,如图9。

图9

7.设置mysql-server-5.0的密码,如图10和图11所示。

图10

图11

8.结束安装。

图12

9.Ubuntu的默认网络配置使用的是dhcp ,网络参数保存在文档 /etc/network/interfaces中,内容如下:

# The primary network interface auto eth0

iface eth0 inet dhcp

若要配置静态IP ,方法如下:

1) 编辑 /etc/network/interfaces ,命令为:

cupl@ubuntu:~$ vi /etc/network/interfaces

1.1)将dhcp 一行屏蔽

# The primary network interface auto eth0

#iface eth0 inet dhcp

1.2)添加和静态ip有关的参数 # The primary network interface iface eth0 inet static address 192.168.0.10

netmask 255.255.255.0 gateway 192.168.0.1

2)编辑 /etc/resolv.conf,配置dns

nameserver 202.96.134.133 nameserver 202.106.0.20

3)执行下面两个命令,启用新配置

$sudo ifdown eth0 $sudo ifup eth0

三、Cacti的安装

1.在安装好的ubuntu 8.04 server环境下执行sudo apt-get install cacti-cactid命令:

cupl@ubuntu:~$ sudo apt-get install cacti-cactid

如图13所示。

注意:该命令不能远程执行。现在安装的版本是cacti V0.8.7b 。

图13

2.注意图14的提示,现在安装cacti时adodb目录的路径已经改变(与08年7月相比),变为/usr/share/php/adodb 。这个变化对cacti没有什么影响,但是在安装weathermap插件时会报错,需要更改adodb目录的路径,这一点在cacti插件weathermap一节中再做说明。

图14

3.如图15 ,cacti的web server选择Apache2 。

图15

4.看图16、图17的提示,默认安装即可。

图16

图17

5.设置管理用户的数据库密码,如图18。

图18

6.设置MYSQL的密码,图19和图20。

图19

图20

7.Cacti安装完成,在浏览器中输入http://服务器IP/cacti ,打开如图21所示的页面。

图21

8.选择New Install ,默认安装直到Finish 。如图22、图23和图24。

图22

图23

图24

9.第一次登录的用户名和密码都是admin ,之后为admin用户设置新的密码。如图25和图26所示。

图25

图26

四、Cacti的使用

1.界面介绍

登陆Cacti后,可以看到左上角是两个选项卡,“console”和“graphs”。console表示控制台,在此进行所有的配置等操作;而graphs则是用来查看所有服务器的性能图像的界面。

图27

2.console菜单

Create:

New Graphs——创建新图像的快捷方式; Management:

Graph Management——图像管理。可以在此删除、复制图像,Cacti会自动创建图像。不过如果我们有特殊的需要,比如将几张图上的数据合并在一张图像上的话也可以在此手工新建图像;

Graph Trees——图像树。在graphs界面里,图像或devices是树状结构显示的,可以在此设置树的结构;

图28

Data Sources——管理rrd文件。一般无需修改,Cacti会自己创建rrd文件;

图29

Devices——设备管理。这是我们最经常需要修改的地方,可以在此创建新的设备或修改其名称等信息。

Collection Methods

Data Queries 和Data Input Methods是采集数据的方式,一般我们无需对这两项进行修改;

Templates

Graph Templates 、Host Templates和Data Templates 分别是图像模板、主机类型模板和数据模板。这些模板可以导出、导入也可以自己编写,一般无需修改。

Import/Export

Import Templates 和Export Templates,对上述模板的导入、导出。我们可以在Cacti的官方网站上找到这些模板,不过需要注意模板对于的Cacti的版本。

Configuration

Settings ——Cacti的主要配置菜单;

可以在此重新设置对应的程序的路径、版本等信息。也可以设置图像的输出方式(允许ftp)、显示效果、登陆方式(允许使用LDAP)等。

在settings里的Visual菜单的Maximum Field Length选项中改为30(默认是15),否则无法显示网络设备的端口名称。如图30:

图30

Utilities

System Utilities ——显示Cacti系统的一些cache和log信息,如果log文件太大建议直接到后台查看;

User Management ——用户管理。可以在此添加、删除用户,并对每个用户设置详细的权限;

Logout User ——注销用户。 3.创建监测点

假设被监测的服务器名叫“Test Host”,IP为192.168.0.100,SNMP的community为public。 进入Cacti的console面板-> 点击“Devices”进入设备面板->

图31

点击“Add”添加新设备->

图32

填写要监测服务器的各种信息,其中Host Template选择 “ucd/net SNMP Host”,SNMP Version选择“Version 2”,Downed Device Detection选择“SNMP”->

点击“Create”保存信息,如果SNMP连接没有问题,左上角会出现该服务器的信息,否则会出现“SNMP error”的红色字样->

图33

点击上部的“Create Graphs for this Host ”为该设备创建需监测的内容。监测的内容分两种,“Graph Templates”和“Data Query”,区别在于“Data Query”能根据SNMP信息列出监测项目的信息。例如Data Query里的“Interface Statistics”可以看到该主机所有网卡的信息,这样我们可以选择需要监测的网卡。点击右侧的正方形选择框勾选上要监测的项目->

图34

在“Select a graph type:”选择“In/Out Bits (-bit Counters)” ,否则绘制的流量监测数据会不准确(数据将溢出)。见图35:

图35

点击“Create”创建选择的监测内容,已经选择创建的内容会自动变成灰色并且不能再点选。Cacti会自动创建该监测点的rrd文件(在rra文件夹中)、“Data Source”和“graph”条目。

图36

图37

创建监测点完毕。

附:如果不能显示图象,则需要在Ubuntu上执行snmpwalk命令来设置snmp陷阱,命令如下:

snmpwalk -v snmp版本号 -c snmp字符串 监控设备ip if (例如:snmpwalk -v 2c -c public 192.168.0.100 if)

4.查看监测点

点击“Graph Management”可以看到刚才创建的监测点对应的图像,注意由于Cacti默认每5分钟到监测服务器上取一次数据,所以刚创建的监测点会出现图像不能显示的现象,需要等几分钟查看才会正常显示。

图38

为了方便查看,可以将刚才新创建的设备或图像加入到“图像树”上: 点击“Graph Tree”进入“图像树”面板->

图39

点击分支名称或“Add”新的分支->

图40

点击“Add”,添加新的“Tree Items”->

图41

“Tree Item Type”中选择“Host”,“Tree Item Value”的“host”中选择刚才新添加的主机“Test Host”->

图42

点击“Create”。

图43

直接在ViewTree中添加一个host节点进行监控无疑是一个简单的方法,但随监控图的增多,将所有的图像放到一个host节点上,当查看图像时图像的显示速度会变慢,而且监控图的条理也不清除,所以通常可以根据监控图监控的功能和监控服务的类型等进行分类,整理出一棵有条理的图像树。可以按下面步骤添加节点。

首先添加一个root节点,“Tree Item Type”中选择“Header”,“Title”中填写一个合适

的描述性信息,如本例填写“Host Monitor”,Host Monitor节点的图像主要是和主机性能相关的一些图像,如CPU、内存、磁盘空间等;

图44

点击刚创建的root节点(Host Monitor)后面的Add链接来添加一个Graph;

图45

在“Tree Item Type”中选择“Graph”,在“graph”中选择加入想要加入的监控图,重复此过程加入所有你想加入的监控图。

图46

图47

你还可以添加Tree Items,如MySQL Monitor,此节点用来监控与MySQL服务相关的信息,重复上面的过程直到一颗有条例的树创建完成。

图48

这样,我们就可以在“graphs”界面中查看“Test Host”的所有监测图像了。

图49

5.为已有host添加新的监控图 在console控制台下点击“New Graphs”,选择要添加监控图的主机。在Graph Templates中选择一个Graph模板,本例选择SNMP - Ceneric OID Template,点击create按钮。

图50

填写以下信息,在“Title”文本框中填写Graph的名字,在“Vertical Lable”文本框中填写描述信息或是所绘图片使用的单位等,显示在所绘图片的左侧,在“name”文本框中填写此数据源的名字,在“LegendColor”中选择画图使用的颜色,在“Legend Text”填写图例的名字,在“OID”文本框中填写要监控的主机的OID信息,点击“create”按钮完成Graph的创建。

图51

完成后监控图如下:

图52

6.合并多个数据源到一张图上

在console控制台下点击“Graph Management”,然后点击Add链接。

图53

在“Select Graph Template”下拉框中选择None,在“Host”下拉框中选择None,然后点击create按钮。

在“Title”文本框中输入Graph的名字。

图55

点击Add链接,添加Graph Items。

图56

添加多个数据源,将所选的多个数据源画到一张监控图上。

图57

图58

图59

图60

完成后将所画的监控图放到Graph Trees中。

五、Cacti插件weathermap

1.Weathermap安装时需要gd库的支持,所以先要安装gd库。执行sudo apt-get install php5-gd命令:

cupl@ubuntu:~$ sudo apt-get install php5-gd

如图61所示。

注意:该命令不能远程执行,而且安装完gd库后需要重启服务器才能生效。

图61

2.要使用cacti插件必须先扩展cacti架构,来支持插件。所以在安装weathermap之前,必须先安装cacti插件架构扩展。

下载地址:http://cactiusers.org/downloads/cacti-plugin-arch.tar.gz 当前版本是V2.1,是专门针对cacti V0.8.7b设计的。

1).下载并解压cacti-plugin-arch.tar.gz包,你会得到一个cacti-plugin-arch目录

cupl@ubuntu:~$ cd /tmp

cupl@ubuntu:/tmp$ sudo wget http://cactiusers.org/downloads/cacti-plugin-arch.tar.gz cupl@ubuntu:/tmp$ sudo tar -zxvf cacti-plugin-arch.tar.gz

2).有两中方法来安装cacti的插件架构扩展,第一种方法是使用patch文件,patch文件包含了原始文件与修改后文件的不同之处,所以可以使用patch文件来得到新的文件。第二种方法是将与cacti相对应版本的files-0.8.7b目录下的文件直接拷贝到/usr/share/cacti/site目录下进行覆盖。在此选择使用第二种方法进行安装。将files-0.8.7b目录下的文件拷贝到/usr/share/cacti/site目录下进行覆盖。

cupl@ubuntu:/tmp$ cd cacti-plugin-arch

cupl@ubuntu:/tmp/cacti-plugin-arch$ sudo cp files-0.8.7b/* /usr/share/cacti/site/ -R

把pa.sql 文件导入mysql数据库,如果这个文件不导入的话,将来会看不到plugin management这个页面,对其他的影响不大。命令如下:

cupl@ubuntu:/tmp/cacti-plugin-arch$ mysql -u root -p cacti3).安装后配置,编辑/usr/share/cacti/site/include目录下的global.php文件:

cupl@ubuntu:~$ vi /usr/share/cacti/site/include/global.php

修改mysql的用户密码

$database_username = \"cactiuser\"; $database_password = \"cactiuser\";

另外,由于我们的浏览器路径是http://yourserver/cacti/,所以还要修改下面一项 $config['url_path'] = '/cacti/';

这样,plugin arch的安装完成了,下面就是weathermap的安装了。

注:由于本人不懂PHP,而PHP又有一定的格式要求,所以global.php的修改请高手来完成,其具体内容见附件一。

3.Weathermap的安装

1).下载并解压php-weathermap-0.95b.zip包(当前版本是0.95b),你会得到一个weathermap目录,下载地址为

http://www.network-weathermap.com/files/php-weathermap-0.95b.zip 。

在解压php-weathermap-0.95b.zip包之前,需要先给ubuntu安装unzip程序,命令如下:

cupl@ubuntu:~$ sudo apt-get install unzip

下载并解压php-weathermap-0.95b.zip包,命令如下:

cupl@ubuntu:~$ cd /tmp

cupl@ubuntu:/tmp$ sudo wget http://www.network-weathermap.com/files/php-weathermap-0.95b.zip cupl@ubuntu:/tmp$ sudo unzip php-weathermap-0.95b.zip

2).将整个weathermap目录复制到/usr/share/cacti/site/plugins目录下,命令如下:

cupl@ubuntu:/tmp$ sudo cp weathermap/ /usr/share/cacti/site/plugins -R

3). 编辑/usr/share/cacti/site/include目录下的global.php文件,并在行开头($plugins = array();)添加

$plugins[] = 'weathermap';

具体global.php文件详见附件一。

4). 由于图14的提示,安装cacti时adodb目录的路径已经改变。所以需要复制/usr/share/php路径下的adodb目录到/usr/share/cacti/site/lib路径,命令为:

cupl@ubuntu:/tmp$ cd /usr/share/php

cupl@ubuntu:/usr/share/php$ sudo cp adodb/ /usr/share/cacti/site/lib -R

5). 在 cacti 网页界面下,不要忘记启用这个 weathermap 插件: 登录到你的 cacti 界面 -> 点击 console 标签页 -> 在 \"Utilities\" 选项上点击 \"User Management\" -> 点击一个用户 -> 启用 \" Plugin Management \" ,\" Plugin -> Weathermap: Configure/Manage\" 和\" Plugin -> Weathermap: View\" ,复选框。

6). 这时在退出cacti是,会报错。所以还需要修改/usr/share/cacti/site/lib目录下的functions.php 。

注:文件functions.php的具体内容详见附件二。

7). 最后还需要修改/usr/share/cacti/site/plugins/weathermap路径下configs和output两个目录及其子文件的属性。

用ls –l命令来查看configs和output目录的属性:

cupl@ubuntu:/usr/share/cacti/site/plugins/weathermap$ ls –l

configs和output目录的属性如下:

drwxr-xr-x 2 root root 4096 2008-08-29 15:00 configs drwxr-xr-x 2 root root 4096 2008-08-29 15:00 output

现将configs和output目录的属性改为

drwxr-xr-x 2 www-data www-data 4096 2008-08-29 15:00 configs drwxr-xr-x 2 www-data root 4096 2008-08-29 15:00 output

命令如下:

cupl@ubuntu:/usr/share/cacti/site/plugins/weathermap$ sudo chown -R www-data.www-data configs cupl@ubuntu:/usr/share/cacti/site/plugins/weathermap$ sudo chown -R www-data.root output

注:在使用weathermap添加链接时,默认的数据来源是/usr/share/cacti/site/rra目录,应将其改为/var/lib/cacti/rra目录。

六、参考

Ubuntu主页:http://www.ubuntu.com/ Ubuntu中文主页:http://www.ubuntu.com.cn/

Cacti官网:http://www.cacti.net/index.php Cacti官网论坛:http://forums.cacti.net/ Cacti文档:http://docs.cacti.net/

Cacti插件:http://cactiusers.org/index.php

Network Weathermap:http://www.network-weathermap.com/ RRDTool官网:http://oss.oetiker.ch/rrdtool/

NET-SNMP官方网站:http://www.net-snmp.org/ Apache官网:http://httpd.apache.org/ MySQL官网:http://www.mysql.com/ PHP官网:http://www.php.net/

七、附件

附件一(global.php):

+-------------------------------------------------------------------------+ | Copyright (C) 2004-2008 The Cacti Group | | | | This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | +-------------------------------------------------------------------------+ | Cacti: The Complete RRDTool-based Graphing Solution | +-------------------------------------------------------------------------+ | This code is designed, written, and maintained by the Cacti Group. See | | about.php and/or the AUTHORS file for specific developer information. | +-------------------------------------------------------------------------+ | http://www.cacti.net/ |

+-------------------------------------------------------------------------+ */ /*

!!! IMPORTANT !!!

The following defaults are not to be altered. Please refer to include/config.php for user configurable database settings. */

/* Default database settings*/ $database_type = \"mysql\"; $database_default = \"cacti\"; $database_hostname = \"localhost\"; $database_username = \"cactiuser\"; $database_password = \"cactiuser\"; $database_port = \"3306\";

/* Default session name - Session name must contain alpha characters */ $cacti_session_name = \"Cacti\";

$plugins = array(); //$plugins[] = 'thold'; $plugins[] = 'weathermap';

/* Do not edit this line */ $config = array(); /*

Edit this to point to the default URL of your Cacti install ex: if your cacti install as at http://serverip/cacti/ this would be set to /cacti/ */

$config['url_path'] = '/cacti/';

define('URL_PATH', $config['url_path']);

/* Include configuration */

include(dirname(__FILE__) . \"/config.php\");

if (isset($config[\"cacti_version\"])) {

die(\"Invalid include/config.php file detected.\");

}

exit;

/* Files that do not need http header information - Command line scripts */ $no_http_header_files = array( );

$colors = array();

/* this should be auto-detected, set it manually if needed */

$config[\"cacti_server_os\"] = (strstr(PHP_OS, \"WIN\")) ? \"win32\" : \"unix\";

/* built-in snmp support */

$config[\"php_snmp_support\"] = function_exists(\"snmpget\");

/* used for includes */

$config[\"base_path\"] = strtr(ereg_replace(\"(.*)[\\/\\\\]include\dirname(__FILE__)), \"\\\\\

$config[\"library_path\"] = ereg_replace(\"(.*[\\/\\\\])include\dirname(__FILE__));

$config[\"include_path\"] = dirname(__FILE__); $config[\"rra_path\"] = '/var/lib/cacti/rra';

/* colors */

\"cmd.php\\"poller.php\

\"poller_commands.php\\"script_server.php\\"query_host_cpu.php\\"query_host_partitions.php\\"sql.php\

\"ss_host_cpu.php\\"ss_host_disk.php\\"ss_sql.php\\"add_device.php\\"add_graphs.php\\"add_perms.php\\"add_tree.php\\"copy_user.php\\"poller_export.php\

\"poller_graphs_reapply_names.php\\"poller_output_empty.php\\"poller_reindex_hosts.php\\"rebuild_poller_cache.php\"

$colors[\"dark_outline\"] = \"4E53\"; $colors[\"dark_bar\"] = \"AEB4B7\"; $colors[\"panel\"] = \"E5E5E5\"; $colors[\"panel_text\"] = \"000000\"; $colors[\"panel_link\"] = \"000000\"; $colors[\"light\"] = \"F5F5F5\"; $colors[\"alternate\"] = \"E7E9F2\"; $colors[\"panel_dark\"] = \"C5C5C5\";

$colors[\"header\"] = \"00438C\"; $colors[\"header_panel\"] = \"6d88ad\"; $colors[\"header_text\"] = \"ffffff\";

$colors[\"form_background_dark\"] = \"E1E1E1\";

$colors[\"form_alternate1\"] = \"F5F5F5\"; $colors[\"form_alternate2\"] = \"E5E5E5\";

if ((!in_array(basename($_SERVER[\"PHP_SELF\"]), $no_http_header_files, true)) && ($_SERVER[\"PHP_SELF\"] != \"\")) {

/* detect and handle get_magic_quotes */ if (!get_magic_quotes_gpc()) { /* initilize php session */ session_name($cacti_session_name); session_start();

/* we don't want these pages cached */

header(\"Expires: Mon, 26 Jul 1997 05:00:00 GMT\");

header(\"Last-Modified: \" . gmdate(\"D, d M Y H:i:s\") . \" GMT\"); header(\"Cache-Control: no-store, no-cache, must-revalidate\"); header(\"Cache-Control: post-check=0, pre-check=0\header(\"Pragma: no-cache\");

/* Sanity Check on \"Corrupt\" PHP_SELF */

if ((!is_file($_SERVER[\"PHP_SELF\"])) && (!is_file($config[\"base_path\"] . '/' . }

if (!is_file($_SERVER[\"DOCUMENT_ROOT\"] . $_SERVER[\"PHP_SELF\"])) { }

if (!((is_file($_SERVER[\"SCRIPT_FILENAME\"])) && }

echo \"\\nInvalid PHP_SELF Path\\n\"; exit;

$_SERVER[\"PHP_SELF\"]))) {

(substr_count($_SERVER[\"SCRIPT_FILENAME\"], basename($_SERVER[\"PHP_SELF\"]))))) {

}

}

function addslashes_deep($value) { }

$_POST = array_map('addslashes_deep', $_POST); $_GET = array_map('addslashes_deep', $_GET); $_COOKIE = array_map('addslashes_deep', $_COOKIE);

$value = is_array($value) ? array_map('addslashes_deep', $value) : return $value;

addslashes($value);

/* make sure to start only only Cacti session at a time */ if (!isset($_SESSION[\"cacti_cwd\"])) { }

$_SESSION[\"cacti_cwd\"] = $config[\"base_path\"]; if ($_SESSION[\"cacti_cwd\"] != $config[\"base_path\"]) { }

session_unset(); session_destroy();

}else{

/* emulate 'register_globals' = 'off' if turned on */ if ((bool)ini_get(\"register_globals\")) {

$not_unset = array(\"_GET\\"_FILES\\"database_username\

while (list($var,) = @each($input)) {

if (!in_array($var, $not_unset)) {

unset($$var);

unset($input[\"input\"]); unset($input[\"not_unset\"]);

/* Merge all into one extremely huge array; unset this later */

$input = array_merge($_GET, $_POST, $_COOKIE, $_SERVER, $_SESSION, $_ENV, /* Not only will array_merge give a warning if a parameter is not an array, it will * actually fail. So we check if HTTP_SESSION_VARS has been initialised. */ if (!isset($_SESSION)) { }

$_SESSION = array();

$_FILES);

}

}

}

unset($input);

/* display ALL errors */ error_reporting(E_ALL);

/* current cacti version */

$config[\"cacti_version\"] = \"0.8.7b\";

/* include base modules */

include($config[\"library_path\"] . \"/adodb/adodb.inc.php\"); #include(\"/usr/share/php/adodb/adodb.inc.php\"); include($config[\"library_path\"] . \"/database.php\");

/* connect to the database server */

db_connect_real($database_hostname, $database_username, $database_password, $database_default, $database_type, $database_port);

/* include additional modules */

include_once($config[\"library_path\"] . \"/functions.php\"); include_once($config[\"include_path\"] . \"/global_constants.php\"); include_once($config[\"library_path\"] . \"/plugins.php\"); include_once($config[\"include_path\"] . \"/plugins.php\"); include_once($config[\"include_path\"] . \"/global_arrays.php\"); include_once($config[\"include_path\"] . \"/global_settings.php\"); include_once($config[\"include_path\"] . \"/global_form.php\"); include_once($config[\"library_path\"] . \"/html.php\"); include_once($config[\"library_path\"] . \"/html_form.php\"); include_once($config[\"library_path\"] . \"/html_utility.php\"); include_once($config[\"library_path\"] . \"/html_validate.php\"); include_once($config[\"library_path\"] . \"/variables.php\"); include_once($config[\"library_path\"] . \"/auth.php\"); ?>

附件二(functions.php):

+-------------------------------------------------------------------------+ | Copyright (C) 2004-2008 The Cacti Group | | |

| This program is free software; you can redistribute it and/or | | modify it under the terms of the GNU General Public License | | as published by the Free Software Foundation; either version 2 | | of the License, or (at your option) any later version. | | | | This program is distributed in the hope that it will be useful, | | but WITHOUT ANY WARRANTY; without even the implied warranty of | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | | GNU General Public License for more details. | +-------------------------------------------------------------------------+ | Cacti: The Complete RRDTool-based Graphing Solution | +-------------------------------------------------------------------------+ | This code is designed, written, and maintained by the Cacti Group. See | | about.php and/or the AUTHORS file for specific developer information. | +-------------------------------------------------------------------------+ | http://www.cacti.net/ | +-------------------------------------------------------------------------+ */

/* title_trim - takes a string of text, truncates it to $max_length and appends three periods onto the end @arg $text - the string to evaluate

@arg $max_length - the maximum number of characters the string can contain before it is truncated

@returns - the truncated string if len($text) is greater than $max_length, else the original string */

function title_trim($text, $max_length) { }

/* read_default_graph_config_option - finds the default value of a graph configuration setting

@arg $config_name - the name of the configuration setting as specified $settings array in 'include/global_settings.php'

@returns - the default value of the configuration option */ function read_default_graph_config_option($config_name) {

reset($settings_graphs);

while (list($tab_name, $tab_array) = each($settings_graphs)) { global $config, $settings_graphs; if (strlen($text) > $max_length) { }

return substr($text, 0, $max_length) . \"...\"; return $text; }else{

if ((isset($tab_array[$config_name])) &&

return $tab_array[$config_name][\"default\"];

while (list($field_name, $field_array) = each($tab_array)) {

if ((isset($field_array[\"items\"])) &&

(isset($tab_array[$config_name][\"default\"]))) {

}else{

(isset($field_array[\"items\"][$config_name])) &&

(isset($field_array[\"items\"][$config_name][\"default\"]))) { }

/* read_graph_config_option - finds the current value of a graph configuration setting @arg $config_name - the name of the configuration setting as specified $settings_graphs array

in 'include/global_settings.php'

@returns - the current value of the graph configuration option */ function read_graph_config_option($config_name, $force = FALSE) {

if (isset($db_setting[\"value\"])) {

return $db_setting[\"value\"];

$db_setting = db_fetch_row(\"select value from settings_graphs where

name='$config_name' and user_id=\" . $effective_uid);

if (strlen($effective_uid) == 0) { }

$effective_uid = 0;

if (isset($_SESSION[\"sess_user_id\"])) {

$effective_uid = $_SESSION[\"sess_user_id\"];

$effective_uid = $config[\"config_options_array\"][\"export_user_id\"]; /* first attempt to get the db setting for guest */

$effective_uid = db_fetch_cell(\"SELECT id FROM user_auth WHERE username='\" . }else if (isset($config[\"config_options_array\"][\"export_user_id\"])) { }else if ((read_config_option(\"auth_method\") == 0)) {

/* users must have cacti user auth turned on to use this, or the guest account must be active */

global $config; }

}

}

}

return $field_array[\"items\"][$config_name][\"default\"];

read_config_option(\"guest_user\") . \"'\");

}

}

}else{ }

$effective_uid = 0;

return read_default_graph_config_option($config_name);

}else{

if (!$force) { }

if (!isset($graph_config_array[$config_name])) {

$db_setting = db_fetch_row(\"select value from settings_graphs where if (isset($_SESSION[\"sess_graph_config_array\"])) { }

$graph_config_array = $_SESSION[\"sess_graph_config_array\"]; if (isset($config[\"config_graph_settings_array\"])) { }

$graph_config_array = $config[\"config_graph_settings_array\"];

}else if (isset($config[\"config_options_array\"][\"export_user_id\"])) {

name='$config_name' and user_id=\" . $effective_uid);

}

return $graph_config_array[$config_name];

if (isset($db_setting[\"value\"])) { }

if (isset($_SESSION)) { }

$_SESSION[\"sess_graph_config_array\"] = $graph_config_array; $config[\"config_graph_settings_array\"] = $graph_config_array; }else{

$graph_config_array[$config_name] = $db_setting[\"value\"]; $graph_config_array[$config_name] = }else{

read_default_graph_config_option($config_name);

/* config_value_exists - determines if a value exists for the current user/setting specified

@arg $config_name - the name of the configuration setting as specified $settings array in 'include/global_settings.php'

@returns (bool) - true if a value exists, false if a value does not exist */ function config_value_exists($config_name) {

}

return sizeof(db_fetch_assoc(\"select value from settings where

name='$config_name'\"));

/* graph_config_value_exists - determines if a value exists for the current user/setting specified

@arg $config_name - the name of the configuration setting as specified $settings_graphs array

in 'include/global_settings.php'

@arg $user_id - the id of the user to check the configuration value for @returns (bool) - true if a value exists, false if a value does not exist */ function graph_config_value_exists($config_name, $user_id) { }

/* read_default_config_option - finds the default value of a Cacti configuration setting @arg $config_name - the name of the configuration setting as specified $settings array in 'include/global_settings.php'

@returns - the default value of the configuration option */ function read_default_config_option($config_name) {

if (is_array($settings)) {

reset($settings);

while (list($tab_name, $tab_array) = each($settings)) {

if ((isset($tab_array[$config_name])) &&

return $tab_array[$config_name][\"default\"];

while (list($field_name, $field_array) = each($tab_array)) {

if ((isset($field_array[\"items\"])) &&

global $config, $settings;

return sizeof(db_fetch_assoc(\"select value from settings_graphs where name='$config_name' and user_id='$user_id'\"));

(isset($tab_array[$config_name][\"default\"]))) {

}else{

(isset($field_array[\"items\"][$config_name])) &&

(isset($field_array[\"items\"][$config_name][\"default\"]))) { } }

/* read_config_option - finds the current value of a Cacti configuration setting @arg $config_name - the name of the configuration setting as specified $settings array in 'include/global_settings.php'

}

}

}

}

return $field_array[\"items\"][$config_name][\"default\"];

@returns - the current value of the configuration option */ function read_config_option($config_name, $force = FALSE) { }

/* form_input_validate - validates the value of a form field and takes the appropriate action if the input is not valid

@arg $field_value - the value of the form field

@arg $field_name - the name of the $_POST field as specified in the HTML @arg $regexp_match - (optionally) enter a regular expression to match the value against

@arg $allow_nulls - (bool) whether to allow an empty string as a value or not @arg $custom_message - (int) the ID of the message to raise upon an error which is defined in the

$messages array in 'include/global_arrays.php' @returns - the original $field_value */

function form_input_validate($field_value, $field_name, $regexp_match, $allow_nulls, $custom_message = 3) {

return $config_array[$config_name]; }

if (isset($_SESSION)) { }

$_SESSION[\"sess_config_array\"] = $config_array; $config[\"config_options_array\"] = $config_array; }else{

if (isset($db_setting[\"value\"])) { }

$config_array[$config_name] = $db_setting[\"value\"];

$config_array[$config_name] = read_default_config_option($config_name); }else{

if ((!isset($config_array[$config_name])) || ($force)) {

$db_setting = db_fetch_row(\"select value from settings where if (isset($_SESSION[\"sess_config_array\"])) { }

$config_array = $_SESSION[\"sess_config_array\"]; $config_array = $config[\"config_options_array\"]; }else if (isset($config[\"config_options_array\"])) { global $config;

name='$config_name'\

}

/* write current values to the \"field_values\" array so we can retain them */ $_SESSION[\"sess_field_values\"][$field_name] = $field_value; if (($allow_nulls == true) && ($field_value == \"\")) { }

/* php 4.2+ complains about empty regexps */ if (empty($regexp_match)) { $regexp_match = \".*\"; }

if ((!ereg($regexp_match, $field_value) || (($allow_nulls == false) && }

return $field_value;

raise_message($custom_message);

$_SESSION[\"sess_error_fields\"][$field_name] = $field_name; $_SESSION[\"sess_field_values\"][$field_name] = $field_value; return $field_value;

($field_value == \"\")))) {

}else{

/* is_error_message - finds whether an error message has been raised and has not been outputted to the user

@returns - (bool) whether the messages array contains an error or not */ function is_error_message() { { }

return false; }

}

}

if ($messages[$current_message_id][\"type\"] == \"error\") { return

true; }

if (isset($_SESSION[\"sess_messages\"])) {

if (is_array($_SESSION[\"sess_messages\"])) {

foreach (array_keys($_SESSION[\"sess_messages\"]) as $current_message_id)

include($config[\"include_path\"] . \"/global_arrays.php\"); global $config, $messages;

/* raise_message - mark a message to be displayed to the user once display_output_messages() is called

@arg $message_id - the ID of the message to raise as defined in $messages in 'include/global_arrays.php' */ function raise_message($message_id) { }

/* display_output_messages - displays all of the cached messages from the raise_message() function and clears the message cache */

function display_output_messages() { {

}

} break;

print \"

print \"

Error: print \"


\"; break;

/* we don't need these if there are no error messages */ kill_session_var(\"sess_field_values\");

switch ($messages[$current_message_id][\"type\"]) { case 'info':

if ($error_message == false) {

print \"

\";

case 'error':

style='background-color: #ffffff; border: 1px solid #ff0000;'>\"; $message

\";

}

}

}

}

display_custom_error_message($_SESSION[\"sess_messages\"]);

}else{

kill_session_var(\"sess_messages\");

/* display_custom_error_message - displays a custom error message to the browser that looks like

the pre-defined error messages

@arg $text - the actual text of the error message to display */ function display_custom_error_message($message) { }

/* clear_messages - clears the message cache */ function clear_messages() { }

/* kill_session_var - kills a session variable using two methods -- session_unregister() and unset() */

function kill_session_var($var_name) { */ }

/* array_rekey - changes an array in the form: '$arr[0] = array(\"id\" => 23, \"name\" => \"blah\")' to the form

'$arr = array(23 => \"blah\")'

@arg $array - (array) the original array to manipulate @arg $key - the name of the key

unset($_SESSION[$var_name]);

/* register_global = on: reset local settings cache so the user sees the new settings /* register_global = off: reset local settings cache so the user sees the new session_unregister($var_name); settings */

kill_session_var(\"sess_messages\");

print \"


\";

eval ('$message = \"' . $messages[$current_message_id][\"message\"] .

'\";');

if (is_array($_SESSION[\"sess_messages\"])) {

foreach (array_keys($_SESSION[\"sess_messages\"]) as $current_message_id)

if (isset($_SESSION[\"sess_messages\"])) {

$error_message = is_error_message(); global $config, $messages;

$_SESSION[\"sess_messages\"][$message_id] = $message_id;

style='background-color: #ffffff; border: 1px solid #bbbbbb;'>\"; class='textInfo'>$message

Error: print \"


\"; border: 1px solid #ff0000;'>\"; $message

\";

@arg $key_value - the name of the key value @returns - the modified array */

function array_rekey($array, $key, $key_value) { }

/* strip_newlines - removes \\n\\r from lines */

function strip_newlines($string) { }

/* cacti_log - logs a string to Cacti's log file or optionally to the browser @arg $string - the string to append to the log file

@arg $output - (bool) whether to output the log line to the browser using pring() or not

@arg $environ - (string) tell's from where the script was called from */ function cacti_log($string, $output = false, $environ = \"CMDPHP\") {

/* determine how to log data */

$logdestination = read_config_option(\"log_destination\"); $logfile = read_config_option(\"path_cactilog\"); /* fill in the current date for printing in the log */ $date = date(\"m/d/Y h:i:s A\"); global $config;

return strtr(strtr($string, \"\\n\@arg $string - the string to strip return $ret_array; } }

if (is_array($key_value)) { }

for ($i=0; $i$ret_array[$item_key] = $item[$key_value];

$ret_array[$item_key]{$key_value[$i]} = $item{$key_value[$i]};

if (sizeof($array) > 0) { foreach ($array as $item) {

$item_key = $item[$key]; $ret_array = array();

}else{

/* format the message */

if (($environ != \"SYSTEM\") && ($environ != \"EXPORT\") && ($environ != \"RECACHE\") }

/* Log to Logfile */

if ((($logdestination == 1) || ($logdestination == 2)) && }

/* Log to Syslog/Eventlog */

/* Syslog is currently Unstable in Win32 */

if (($logdestination == 2) || ($logdestination == 3)) {

$log_type = \"\";

if (substr_count($string,\"ERROR:\"))

$log_type = \"err\"; $log_type = \"warn\"; $log_type = \"stat\"; $log_type = \"note\";

else if (substr_count($string,\"WARNING:\")) else if (substr_count($string,\"STATS:\")) else if (substr_count($string,\"NOTICE:\")) if ($logfile == \"\") { }

/* echo the data to the log (append) */ $fp = @fopen($logfile, \"a\"); if ($fp) { }

@fwrite($fp, $message); fclose($fp);

$logfile = $config[\"base_path\"] . \"/log/cacti.log\";

$message = \"$date - \" . $environ . \": Poller[0] \" . $string . \"\\n\"; $message = \"$date - \" . $environ . \" \" . $string . \"\\n\";

&& ($environ != \"AUTH\")) {

}else {

(read_config_option(\"log_verbosity\") != POLLER_VERBOSITY_NONE)) {

if (strlen($log_type)) {

define_syslog_variables();

if ($config[\"cacti_server_os\"] == \"win32\")

openlog(\"Cacti\openlog(\"Cacti\else

}

/* tail_file - Emulates the tail function with PHP native functions.

@arg $file_name - (char constant) the name of the file to tail

$line_cnt - (int constant) the number of lines to count $message_type - (int constant) the type of message to return $filter - (char) the filtering expression to search for

$line_size - (int constant) the average line size to use estimate bytes

to seek up from EOF. Defaults to 256 bytes */

It is used in 0.8.6 to speed the viewing of the Cacti log file, which can be problematic in the 0.8.6 branch. /* print output to standard out if required */

if (($output == true) && (isset($_SERVER[\"argv\"][0]))){ }

print $message;

}

closelog();

if ((($log_type == \"stat\") || ($log_type == \"note\")) && }

syslog(LOG_INFO, $environ . \": \" . $string);

(read_config_option(\"log_pstats\"))) {

if (($log_type == \"warn\") && (read_config_option(\"log_pwarn\"))) { }

syslog(LOG_WARNING, $environ . \": \" . $string);

if (($log_type == \"err\") && (read_config_option(\"log_perror\"))) { }

syslog(LOG_CRIT, $environ . \": \" . $string);

}

function tail_file($file_name, $number_of_lines, $message_type = -1, $filter = \"\$line_size = 256) {

/* reset back the number of bytes */ if ($number_of_lines > 0) {

$total_bytes = fseek($fp, -($number_of_lines * $line_size), SEEK_END);

if (file_exists($file_name)) {

$fp = fopen($file_name, \"r\"); $file_array = array();

}

/* load up the lines into an array */ $i = 0; while (1) {

$line = fgets($fp); $display = true;

/* determine if we are to display the line */ switch ($message_type) { case -1: /* all */

$display = true; break;

if (substr_count($line, \" SQL \")) { } break;

if (substr_count($line, \"STATS\")) { } break;

if (substr_count($line, \"WARN\")) { } break;

if (substr_count($line, \"ERROR\")) { }

$display=true; $display=false; }else{

$display=true; $display=false; }else{

$display=true; $display=false; }else{

$display=true; $display=false; }else{

case 5: /* sql calls */

case 1: /* stats */

case 2: /* warnings */

case 3: /* errors */

}

}

break;

if (substr_count($line, \"DEBUG\")) { }

if (substr_count($line, \" SQL \")) { } break;

$display=true; break;

$display=false; $display=true; $display=false; }else{

case 4: /* debug */

default: /* all other lines */

/* match any lines that match the search string */ if (strlen($filter)) { }

if (feof($fp)) { }

break;

$file_array[$i] = $line; $i++;

}else if ($display) {

if ((substr_count(strtolower($line), strtolower($filter))) || }

(@preg_match($filter, $line))) { $display=true; $display=false;

}else{

$file_array = array_slice($file_array, -$number_of_lines,

count($file_array));

}

fclose($fp); touch($file_name);

}else{

}

return $file_array;

/* update_host_status - updates the host table with informaton about it's status.

@arg $status - (int constant) the status of the host (Up/Down)

$host_id - (int) the host ID for the results $ping - (class array) results of the ping command

*/

$hosts - (array) a memory resident host table for speed

It will also output to the appropriate log file when an event occurs.

function update_host_status($status, $host_id, &$hosts, &$ping, $ping_availability, $print_data_to_stdout) {

/* determine if to send an alert and update remainder of statistics */ if ($hosts[$host_id][\"status\"] == HOST_UP) {

/* determine the error message to display */ if ($ping_availability == AVAIL_SNMP_AND_PING) { }

if ($hosts[$host_id][\"snmp_community\"] == \"\") { }

if ($hosts[$host_id][\"snmp_community\"] == \"\") {

$hosts[$host_id][\"status_last_error\"] = \"Device does not require $hosts[$host_id][\"status_last_error\"] = $ping->ping_response; $hosts[$host_id][\"status_last_error\"] = $ping->snmp_response . \\" . }else {

if ($status == HOST_DOWN) {

/* update total polls, failed polls and availability */ $hosts[$host_id][\"failed_polls\"]++; $hosts[$host_id][\"total_polls\"]++;

$hosts[$host_id][\"availability\"] = 100 * ($hosts[$host_id][\"total_polls\"] - $issue_log_message = false;

$ping_failure_count = read_config_option(\"ping_failure_count\"); $ping_recovery_count = read_config_option(\"ping_recovery_count\");

$hosts[$host_id][\"failed_polls\"]) / $hosts[$host_id][\"total_polls\"];

$ping->ping_response;

}elseif ($ping_availability == AVAIL_SNMP) {

SNMP\";

}else { }

$hosts[$host_id][\"status_last_error\"] = $ping->ping_response;

$hosts[$host_id][\"status_last_error\"] = $ping->snmp_response;

}else {

/* increment the event failure count */ $hosts[$host_id][\"status_event_count\"]++;

/* if it's time to issue an error message, indicate so */

if ($hosts[$host_id][\"status_event_count\"] >= $ping_failure_count) {

/* host is now down, flag it that way */ $hosts[$host_id][\"status\"] = HOST_DOWN; $issue_log_message = true;

/* update the failure date only if the failure count is 1 */ if ($ping_failure_count == 1) { }

$hosts[$host_id][\"status_fail_date\"] = date(\"Y-m-d H:i:s\");

/* host is down, but not ready to issue log message */ } else { }

/* host down for the first time, set event date */ if ($hosts[$host_id][\"status_event_count\"] == 1) { }

$hosts[$host_id][\"status_fail_date\"] = date(\"Y-m-d H:i:s\");

/* host is recovering, put back in failed state */

} elseif ($hosts[$host_id][\"status\"] == HOST_RECOVERING) {

$hosts[$host_id][\"status_event_count\"] = 1; $hosts[$host_id][\"status\"] = HOST_DOWN;

/* host was unknown and now is down */

} elseif ($hosts[$host_id][\"status\"] == HOST_UNKNOWN) { }

$hosts[$host_id][\"status\"] = HOST_DOWN; $hosts[$host_id][\"status_event_count\"] = 0; $hosts[$host_id][\"status_event_count\"]++;

} else {

/* host is up!! */ } else {

/* update total polls and availability */ $hosts[$host_id][\"total_polls\"]++;

$hosts[$host_id][\"availability\"] = 100 * ($hosts[$host_id][\"total_polls\"] -

$hosts[$host_id][\"failed_polls\"]) / $hosts[$host_id][\"total_polls\"];

if ((($ping_availability == AVAIL_SNMP_AND_PING) ||

($ping_availability == AVAIL_SNMP)) && (!is_numeric($ping->snmp_status))) {

cacti_log(\"WARNING: Poller[0] Host[$host_id] SNMP Time was not numeric\

TRUE, \"POLLER\");

/* average time */

$hosts[$host_id][\"avg_time\"] =

/* minimum time */

if ($ping_time < $hosts[$host_id][\"min_time\"])

$hosts[$host_id][\"min_time\"] = $ping_time;

/* maximum time */

if ($ping_time > $hosts[$host_id][\"max_time\"])

$hosts[$host_id][\"max_time\"] = $ping_time;

/* update times as required */

$hosts[$host_id][\"cur_time\"] = $ping_time;

if ((($ping_availability == AVAIL_SNMP_AND_PING) || }

/* determine the ping statistic to set and do so */ if ($ping_availability == AVAIL_SNMP_AND_PING) { }

if ($hosts[$host_id][\"snmp_community\"] == \"\") { }

if ($hosts[$host_id][\"snmp_community\"] == \"\") { }

$ping_time = 0.000;

$ping_time = $ping->ping_status;

$ping_time = 0.000;

$ping_time = $ping->snmp_status; }else {

$ping_time = 0.000;

/* calculate the average of the two times */

$ping_time = ($ping->snmp_status + $ping->ping_status) / 2; }else {

($ping_availability == AVAIL_PING)) && (!is_numeric($ping->ping_status))) {

cacti_log(\"WARNING: Poller[0] Host[$host_id] Ping Time was not numeric\$ping->ping_status = 0.000;

}

$ping->snmp_status = 0.000;

TRUE, \"POLLER\");

}elseif ($ping_availability == AVAIL_SNMP) {

}elseif ($ping_availability == AVAIL_NONE) { }else{

(($hosts[$host_id][\"total_polls\"]-1-$hosts[$host_id][\"failed_polls\"])

}

/* if the user wants a flood of information then flood them */ if (read_config_option(\"log_verbosity\") >= POLLER_VERBOSITY_HIGH) {

/* reset the event counter */

$hosts[$host_id][\"status_event_count\"] = 0;

/* update the recovery date only if the recovery count is 1 */ if ($ping_recovery_count == 1) { }

$hosts[$host_id][\"status_rec_date\"] = date(\"Y-m-d H:i:s\");

$issue_log_message = true;

/* if it's time to issue a recovery message, indicate so */

if ($hosts[$host_id][\"status_event_count\"] >= $ping_recovery_count) {

/* host is up, flag it that way */ $hosts[$host_id][\"status\"] = HOST_UP;

/* the host was down, now it's recovering */

if (($hosts[$host_id][\"status\"] == HOST_DOWN) || ($hosts[$host_id][\"status\"]

/* just up, change to recovering */

if ($hosts[$host_id][\"status\"] == HOST_DOWN) { }

$hosts[$host_id][\"status\"] = HOST_RECOVERING; $hosts[$host_id][\"status_event_count\"] = 1; $hosts[$host_id][\"status_event_count\"]++;

* $hosts[$host_id][\"avg_time\"] + $ping_time) /

($hosts[$host_id][\"total_polls\"]-$hosts[$host_id][\"failed_polls\"]);

== HOST_RECOVERING )) {

} else {

/* host is recovering, but not ready to issue log message */ } else { }

/* host recovering for the first time, set event date */ if ($hosts[$host_id][\"status_event_count\"] == 1) { }

$hosts[$host_id][\"status_rec_date\"] = date(\"Y-m-d H:i:s\");

} else {

/* host was unknown and now is up */ }

$hosts[$host_id][\"status\"] = HOST_UP; $hosts[$host_id][\"status_event_count\"] = 0;

}

if (($hosts[$host_id][\"status\"] == HOST_UP) || ($hosts[$host_id][\"status\"] == }

/* log ping result if we are to use a ping for reachability testing */ if ($ping_availability == AVAIL_SNMP_AND_PING) {

cacti_log(\"Host[$host_id] PING: \" . $ping->ping_response, cacti_log(\"Host[$host_id] SNMP: \" . $ping->snmp_response,

HOST_RECOVERING)) {

$print_data_to_stdout); $print_data_to_stdout);

} elseif ($ping_availability == AVAIL_SNMP) { }

if ($ping_availability == AVAIL_SNMP_AND_PING) {

cacti_log(\"Host[$host_id] PING: \" . $ping->ping_response, cacti_log(\"Host[$host_id] SNMP: \" . $ping->snmp_response, if ($hosts[$host_id][\"snmp_community\"] == \"\") {

cacti_log(\"Host[$host_id] SNMP: Device does not require SNMP\

$print_data_to_stdout);

}else{ }

cacti_log(\"Host[$host_id] PING: \" . $ping->ping_response,

cacti_log(\"Host[$host_id] SNMP: \" . $ping->snmp_response,

$print_data_to_stdout);

} else {

$print_data_to_stdout);

} else {

$print_data_to_stdout); $print_data_to_stdout);

} elseif ($ping_availability == AVAIL_SNMP) {

cacti_log(\"Host[$host_id] SNMP: \" . $ping->snmp_response,

$print_data_to_stdout);

} else { }

cacti_log(\"Host[$host_id] PING: \" . $ping->ping_response,

$print_data_to_stdout);

/* if there is supposed to be an event generated, do it */ if ($issue_log_message) {

if ($hosts[$host_id][\"status\"] == HOST_DOWN) {

cacti_log(\"Host[$host_id] ERROR: HOST EVENT: Host is DOWN Message: \" .

$hosts[$host_id][\"status_last_error\"], $print_data_to_stdout);

} else {

cacti_log(\"Host[$host_id] NOTICE: HOST EVENT: Host Returned from DOWN

State: \

}

}

db_execute(\"update host set status = '\" . $hosts[$host_id][\"status\"] . \"',

status_event_count = '\" . $hosts[$host_id][\"status_event_count\"] . \"', status_fail_date = '\" . $hosts[$host_id][\"status_fail_date\"] . \"', status_rec_date = '\" . $hosts[$host_id][\"status_rec_date\"] . \"', status_last_error = '\" . $hosts[$host_id][\"status_last_error\"] . \"', min_time = '\" . $hosts[$host_id][\"min_time\"] . \"', max_time = '\" . $hosts[$host_id][\"max_time\"] . \"', cur_time = '\" . $hosts[$host_id][\"cur_time\"] . \"', avg_time = '\" . $hosts[$host_id][\"avg_time\"] . \"', total_polls = '\" . $hosts[$host_id][\"total_polls\"] . \"', failed_polls = '\" . $hosts[$host_id][\"failed_polls\"] . \"', availability = '\" . $hosts[$host_id][\"availability\"] . \"'

where hostname = '\" . $hosts[$host_id][\"hostname\"] . \"'\");

}

/* strip_quotes - Strip single and double quotes from a string in addition remove non-numeric data from strings. @arg $result - (string) the result from the poll

@returns - (string) the string with quotes stripped */

function strip_quotes($result) {

/* first strip all single and double quotes from the string */ $result = strtr($result,\"'\ $result = strtr($result,'\"',' ');

/* clean off ugly non-numeric data */

if ((!is_numeric($result)) && ($result != \"U\")) { $len = strlen($result); for($a=$len-1; $a>=0; $a--){ $p = ord($result[$a]); if (($p > 47) && ($p < 58)) { $result = substr($result,0,$a+1); break;

}

}

}

return(trim($result));

}

/* validate_result - determine's if the result value is valid or not. If not valid

returns a \"U\"

@arg $result - (string) the result from the poll @returns - (int) either to result is valid or not */ function validate_result($result) {

if ($space_cnt+1 == $delim_cnt) {

$valid_result = true; } else {

$space_cnt = substr_count($result, \" \");

if (substr_count($result, \" \") != 0) {

$checked = true;

if (substr_count($result, \":\")) { }

$delim_cnt = substr_count($result, \":\"); $delim_cnt = substr_count($result, \"!\"); } else if (strstr($result, \"!\")) {

/* check the easy cases first */

/* it has no delimiters, and no space, therefore, must be numeric */

if ((substr_count($result, \":\") == 0) && (substr_count($result, \"!\") == 0) && }

/* it has delimiters and has no space */ if (!$checked) {

if (((substr_count($result, \":\")) || (substr_count($result, \"!\")))) {

if (substr_count($result, \" \") == 0) { }

$valid_result = true; $checked = true;

$checked = true;

if (is_numeric($result)) { }

$valid_result = true; $valid_result = true; $valid_result = false; } else if (is_float($result)) { } else {

$valid_result = false; $checked = false; $delim_cnt = 0; $space_cnt = 0;

(substr_count($result, \" \") == 0)) {

}

}

}

}

}

$valid_result = false;

/* default handling */ if (!$checked) { }

return($valid_result);

if (is_numeric($result)) { }

$valid_result = true; $valid_result = true; $valid_result = false; } else if (is_float($result)) { } else {

/* get_full_script_path - gets the full path to the script to execute to obtain data for a

given data source. this function does not work on SNMP actions, only script-based actions

@arg $local_data_id - (int) the ID of the data source

@returns - the full script path or (bool) false for an error */ function get_full_script_path($local_data_id) {

/* snmp-actions don't have paths */

if (($data_source[\"type_id\"] == DATA_INPUT_TYPE_SNMP) || ($data_source[\"type_id\"] }

return false;

$data_source = db_fetch_row(\"select

data_template_data.id,

data_template_data.data_input_id, data_input.type_id, data_input.input_string

from (data_template_data,data_input)

where data_template_data.data_input_id=data_input.id and data_template_data.local_data_id=$local_data_id\"); global $config;

== DATA_INPUT_TYPE_SNMP_QUERY)) {

}

$data = db_fetch_assoc(\"select

data_input_fields.data_name, data_input_data.value from data_input_fields left join data_input_data

on (data_input_fields.id=data_input_data.data_input_field_id)

where data_input_fields.data_input_id=\" . $data_source[\"data_input_id\"] . \" and data_input_data.data_template_data_id=\" . $data_source[\"id\"] . \" and data_input_fields.input_output='in'\");

$full_path = $data_source[\"input_string\"]; if (sizeof($data) > 0) { foreach ($data as $item) { } }

$full_path = str_replace(\"\$full_path = str_replace(\"\$full_path = str_replace(\"\

$full_path = str_replace(\"<\" . $item[\"data_name\"] . \">\

$full_path);

$full_path);

read_config_option(\"path_php_binary\"), $full_path);

/* sometimes a certain input value will not have anything entered... null out these in the input string so we don't mess up the script */

$full_path = preg_replace(\"/(<[A-Za-z0-9_]+>)+/\return $full_path;

fields

/* get_data_source_item_name - gets the name of a data source item or generates a new one if one does not already exist

@arg $data_template_rrd_id - (int) the ID of the data source item

@returns - the name of the data source item or an empty string for an error */ function get_data_source_item_name($data_template_rrd_id) {

$data_source = db_fetch_row(\"select

data_template_rrd.data_source_name, data_template_data.name

if (empty($data_template_rrd_id)) { return \"\"; }

from (data_template_rrd,data_template_data)

where data_template_rrd.local_data_id=data_template_data.local_data_id and data_template_rrd.id=$data_template_rrd_id\");

/* use the cacti ds name by default or the user defined one, if entered */ if (empty($data_source[\"data_source_name\"])) {

/* limit input to 19 characters */

$data_source_name = clean_up_name($data_source[\"name\"]); $data_source_name =

substr(strtolower($data_source_name),0,(19-strlen($data_template_rrd_id))) . $data_template_rrd_id; }

/* get_data_source_path - gets the full path to the .rrd file associated with a given data source

@arg $local_data_id - (int) the ID of the data source

@arg $expand_paths - (bool) whether to expand the variable into its full path or not

@returns - the full path to the data source or an empty string for an error */ function get_data_source_path($local_data_id, $expand_paths) {

if (sizeof($data_source) > 0) {

if (empty($data_source[\"data_source_path\"])) { }

/* no custom path was specified */

$data_source_path = generate_data_source_path($local_data_id); if (!strstr($data_source[\"data_source_path\"], \"/\")) {

$data_source_path = \"/\" .

$data_source = db_fetch_row(\"select name,data_source_path from data_template_data where local_data_id=$local_data_id\");

if (empty($local_data_id)) { return \"\"; } global $config; }

return $data_source_name;

return $data_source[\"data_source_name\"]; }else{

}else{

$data_source[\"data_source_path\"];

}else{ }

$data_source_path = $data_source[\"data_source_path\"];

}

/* stri_replace - a case insensitive string replace @arg $find - needle

@arg $replace - replace needle with this @arg $string - haystack

@returns - the original string with '$find' replaced by '$replace' */ function stri_replace($find, $replace, $string) { }

/* clean_up_name - runs a string through a series of regular expressions designed to eliminate \"bad\" characters

@arg $string - the string to modify/clean @returns - the modified string */ function clean_up_name($string) { }

/* clean_up_file name - runs a string through a series of regular expressions designed to

return $string;

$string = preg_replace(\"/[\\s\\.]+/\$string = preg_replace(\"/[^a-zA-Z0-9_]+/\$string = preg_replace(\"/_{2,}/\return (join($replace, $parts)); foreach ($parts as $key=>$part) { }

$parts[$key] = substr($string, $pos, strlen($part)); $pos += strlen($part) + strlen($find); $pos = 0;

$parts = explode(strtolower($find), strtolower($string)); }

return $data_source_path;

/* whether to show the \"actual\" path or the variable name (for edit if ($expand_paths == true) { }

$data_source_path = str_replace('', $config['rra_path'],

boxes) */

$data_source_path);

eliminate \"bad\" characters

@arg $string - the string to modify/clean @returns - the modified string */ function clean_up_file_name($string) { }

/* clean_up_path - takes any path and makes sure it contains the correct directory separators based on the current operating system @arg $path - the path to modify @returns - the modified path */ function clean_up_path($path) { }

/* get_data_source_title - returns the title of a data source without using the title cache

@arg $local_data_id - (int) the ID of the data source to get a title for @returns - the data source title */

function get_data_source_title($local_data_id) {

if ((strstr($data[\"name\"], \"|\")) && (!empty($data[\"host_id\"]))) { $data = db_fetch_row(\"select

data_local.host_id, data_local.snmp_query_id, data_local.snmp_index, data_template_data.name

from (data_template_data,data_local)

where data_template_data.local_data_id=data_local.id and data_local.id=$local_data_id\"); return $path; }

if ($config[\"cacti_server_os\"] == \"unix\" or read_config_option(\"using_cygwin\") ==

$path = str_replace(\"\\\\\$path = str_replace(\"/\

\"on\") {

}elseif ($config[\"cacti_server_os\"] == \"win32\") { global $config; return $string;

$string = preg_replace(\"/[\\s\\.]+/\$string = preg_replace(\"/[^a-zA-Z0-9_-]+/\$string = preg_replace(\"/_{2,}/\

}

return expand_title($data[\"host_id\"], $data[\"snmp_query_id\"],

$data[\"snmp_index\"], $data[\"name\"]);

}else{ }

return $data[\"name\"];

/* get_graph_title - returns the title of a graph without using the title cache @arg $local_graph_id - (int) the ID of the graph to get a title for @returns - the graph title */

function get_graph_title($local_graph_id) { }

/* generate_data_source_path - creates a new data source path from scratch using the first data source

item name and updates the database with the new value

@arg $local_data_id - (int) the ID of the data source to generate a new path for @returns - the new generated path */

function generate_data_source_path($local_data_id) {

if (!empty($host_name)) { }

$host_part = strtolower(clean_up_file_name($host_name)) . \"_\"; /* try any prepend the name with the host description */

$host_name = db_fetch_cell(\"select host.description from (host,data_local) where $host_part = \"\"; $ds_part = \"\";

if ((strstr($graph[\"title\"], \"|\")) && (!empty($graph[\"host_id\"]))) {

return expand_title($graph[\"host_id\"], $graph[\"snmp_query_id\"], $graph = db_fetch_row(\"select

graph_local.host_id, graph_local.snmp_query_id, graph_local.snmp_index, graph_templates_graph.title

from (graph_templates_graph,graph_local)

where graph_templates_graph.local_graph_id=graph_local.id and graph_local.id=$local_graph_id\");

$graph[\"snmp_index\"], $graph[\"title\"]);

}else{ }

return $graph[\"title\"];

data_local.host_id=host.id and data_local.id=$local_data_id\");

}

/* then try and use the internal DS name to identify it */

$data_source_rrd_name = db_fetch_cell(\"select data_source_name from

data_template_rrd where local_data_id=$local_data_id order by id\");

if (!empty($data_source_rrd_name)) { }

/* put it all together using the local_data_id at the end */

$new_path = \"/$host_part$ds_part\" . \"_\" . \"$local_data_id.rrd\"; /* update our changes to the db */

db_execute(\"update data_template_data set data_source_path='$new_path' where

$ds_part = strtolower(clean_up_file_name($data_source_rrd_name)); $ds_part = \"ds\"; }else{

local_data_id=$local_data_id\");

return $new_path;

/* generate graph_best_cf - takes the requested consolidation function and maps against the list of available consolidation functions for the consolidation functions and returns

the most appropriate. Typically, this will be the requested value @arg $data_template_id @arg $requested_cf

@returns - the best cf to use */

function generate_graph_best_cf($local_data_id, $requested_cf) {

}

}

/* if none was found, take the first */ return $avail_cf_functions[0];

if ($local_data_id > 0) {

$avail_cf_functions = get_rrd_cfs($local_data_id); /* workaround until we have RRA presets in 0.8.8 */ if (sizeof($avail_cf_functions)) {

/* check through the cf's and get the best */ foreach($avail_cf_functions as $cf) { }

if ($cf == $requested_cf) { }

return $requested_cf;

}

/* get_rrd_cfs - reads the RRDfile and get's the RRA's stored in it. @arg $local_data_id

@returns - array of the CF functions */ function get_rrd_cfs($local_data_id) {

$new_cfs = array(); }

}

}

}

if (!in_array(trim($values[1]), $cfs)) { }

$cfs[] = trim($values[1], '\" ');

if (sizeof($output)) {

foreach($output as $line) {

if (substr_count($line, \".cf\")) {

$values = explode(\"=\

/* search for * */

if (strlen($output)) {

$output = explode(\"\\n\

rra[0].cf = \"LAST\"

* or similar

$output = rrdtool_execute(\"info $rrdfile\$cfs = array();

if (!isset($rrd_cfs)) { }

$rrd_cfs = array();

return $rrd_cfs[$local_data_id];

}else if (array_key_exists($local_data_id, $rrd_cfs)) { $rrdfile = get_data_source_path($local_data_id, TRUE); global $rrd_cfs, $consolidation_functions; /* if you can not figure it out return average */ return \"1\";

}

/* generate_graph_def_name - takes a number and turns each digit into its letter-based counterpart for RRDTool DEF names (ex 1 -> a, 2 -> b, etc)

@arg $graph_item_id - (int) the ID to generate a letter-based representation of @returns - a letter-based representation of the input argument */ function generate_graph_def_name($graph_item_id) { }

/* generate_data_input_field_sequences - re-numbers the sequences of each field associated

with a particular data input method based on its position within the input string

return $result;

for ($i=0; $i$result .= $lookup_table{substr(strval($graph_item_id), $i, 1)}; $result = \"\";

$lookup_table = array(\"a\return $new_cfs;

$rrd_cfs[$local_data_id] = $new_cfs; if (sizeof($cfs)) { }

foreach($cfs as $cf) { }

switch($cf) { case \"AVG\": }

$new_cfs[] = array_search('AVERAGE', $consolidation_functions); break;

$new_cfs[] = array_search('MIN', $consolidation_functions); break;

$new_cfs[] = array_search('MAX', $consolidation_functions); break;

$new_cfs[] = array_search('LAST', $consolidation_functions); break;

case \"MIN\":

case \"MAX\":

case \"LAST\":

@arg $string - the input string that contains the field variables in a certain order @arg $data_input_id - (int) the ID of the data input method */ function generate_data_input_field_sequences($string, $data_input_id) {

if (preg_match_all(\"/<([_a-zA-Z0-9]+)>/\

$j = 0;

for ($i=0; ($i < count($matches[1])); $i++) {

if (in_array($matches[1][$i], $registered_cacti_names) == false) {

$j++; db_execute(\"update data_input_fields set sequence=$j where

include ($config[\"include_path\"] . \"/global_arrays.php\"); global $config;

data_input_id=$data_input_id and input_output='in' and data_name='\" . $matches[1][$i] . \"'\"); }

/* move_graph_group - takes a graph group (parent+children) and swaps it with another graph group

@arg $graph_template_item_id - (int) the ID of the (parent) graph item that was clicked

@arg $graph_group_array - (array) an array containing the graph group to be moved @arg $target_id - (int) the ID of the (parent) graph item of the target group @arg $direction - ('next' or 'previous') whether the graph group is to be swapped with

group above or below the current group */

function move_graph_group($graph_template_item_id, $graph_group_array, $target_id, $direction) {

$graph_items = db_fetch_assoc(\"select id,sequence from graph_templates_item where $sql_where order by sequence\");

if (empty($graph_item[\"local_graph_id\"])) {

$sql_where = \"graph_template_id = \" . $graph_item[\"graph_template_id\"] . \" and $graph_item = db_fetch_row(\"select local_graph_id,graph_template_id from graph_templates_item where id=$graph_template_item_id\");

}

}

}

local_graph_id=0\";

}else{ }

$sql_where = \"local_graph_id = \" . $graph_item[\"local_graph_id\"];

/* get a list of parent+children of our target group */ $target_graph_group_array = get_graph_group($target_id);

/* if this \"parent\" item has no children, then treat it like a regular gprint */ if (sizeof($target_graph_group_array) == 0) { }

/* start the sequence at '1' */ $sequence_counter = 1;

if (sizeof($graph_items) > 0) { foreach ($graph_items as $item) {

/* check to see if we are at the \"target\" spot in the loop; if we are, update if ($target_id == $item[\"id\"]) {

if ($direction == \"next\") { }

while (list($sequence,$graph_template_item_id) = each($group_array1)) {

db_execute(\"update graph_templates_item set $group_array1 = $target_graph_group_array; $group_array2 = $graph_group_array; $group_array1 = $graph_group_array; $group_array2 = $target_graph_group_array;

if ($direction == \"next\") {

move_item_down(\"graph_templates_item\

$sql_where);

}elseif ($direction == \"previous\") { } return;

move_item_up(\"graph_templates_item\

$sql_where);

the sequences and move on */

}elseif ($direction == \"previous\") {

sequence=$sequence_counter where id=$graph_template_item_id\");

/* propagate to ALL graphs using this template */ if (empty($graph_item[\"local_graph_id\"])) {

db_execute(\"update graph_templates_item set

sequence=$sequence_counter where

local_graph_template_item_id=$graph_template_item_id\");

$sequence_counter++;

}

}

while (list($sequence,$graph_template_item_id) = each($group_array2)) {

db_execute(\"update graph_templates_item set

sequence=$sequence_counter where id=$graph_template_item_id\");

/* propagate to ALL graphs using this template */ if (empty($graph_item[\"local_graph_id\"])) {

db_execute(\"update graph_templates_item set

sequence=$sequence_counter where

local_graph_template_item_id=$graph_template_item_id\"); }

/* get_graph_group - returns an array containing each item in the graph group given a single

graph item in that group

@arg $graph_template_item_id - (int) the ID of the graph item to return the group of

@returns - (array) an array containing each item in the graph group */ function get_graph_group($graph_template_item_id) {

$graph_item = db_fetch_row(\"select

graph_type_id,sequence,local_graph_id,graph_template_id from graph_templates_item where id=$graph_template_item_id\");

if (empty($graph_item[\"local_graph_id\"])) {

$sql_where = \"graph_template_id = \" . $graph_item[\"graph_template_id\"] . \" and global $graph_item_types; } }

/* make sure to \"ignore\" the items that we handled above */ if ((!isset($graph_group_array{$item[\"id\"]})) && }

db_execute(\"update graph_templates_item set sequence=$sequence_counter $sequence_counter++;

}

}

$sequence_counter++;

}

(!isset($target_graph_group_array{$item[\"id\"]}))) { where id=\" . $item[\"id\"]);

local_graph_id=0\";

}

}else{ }

/* a parent must NOT be the following graph item types */ if (ereg(\"(GPRINT|VRULE|HRULE|COMMENT)\ }

$graph_item_children_array = array();

/* put the parent item in the array as well */

$graph_item_children_array[$graph_template_item_id] = $graph_template_item_id; $graph_items = db_fetch_assoc(\"select id,graph_type_id from graph_templates_item

return;

$sql_where = \"local_graph_id = \" . $graph_item[\"local_graph_id\"];

$graph_item_types{$graph_item[\"graph_type_id\"]})) {

where sequence > \" . $graph_item[\"sequence\"] . \" and $sql_where order by sequence\");

if (sizeof($graph_items) > 0) { foreach ($graph_items as $item) { } }

return $graph_item_children_array;

if ($graph_item_types{$item[\"graph_type_id\"]} == \"GPRINT\") { }

/* a child must be a GPRINT */

$graph_item_children_array{$item[\"id\"]} = $item[\"id\"]; /* if not a GPRINT then get out */ return $graph_item_children_array;

}else{

/* get_graph_parent - returns the ID of the next or previous parent graph item id @arg $graph_template_item_id - (int) the ID of the current graph item

@arg $direction - ('next' or 'previous') whether to find the next or previous parent @returns - (int) the ID of the next or previous parent graph item id */ function get_graph_parent($graph_template_item_id, $direction) {

if (empty($graph_item[\"local_graph_id\"])) {

$sql_where = \"graph_template_id = \" . $graph_item[\"graph_template_id\"] . \" and $graph_item = db_fetch_row(\"select sequence,local_graph_id,graph_template_id from graph_templates_item where id=$graph_template_item_id\");

local_graph_id=0\";

}else{ }

if ($direction == \"next\") { }

$next_parent_id = db_fetch_cell(\"select id from graph_templates_item where

$sql_operator = \">\"; $sql_order = \"ASC\"; $sql_operator = \"<\"; $sql_order = \"DESC\";

$sql_where = \"local_graph_id = \" . $graph_item[\"local_graph_id\"];

}elseif ($direction == \"previous\") {

sequence $sql_operator \" . $graph_item[\"sequence\"] . \" and graph_type_id != 9 and $sql_where order by sequence $sql_order limit 1\"); }

/* get_item - returns the ID of the next or previous item id @arg $tblname - the table name that contains the target id @arg $field - the field name that contains the target id @arg $startid - (int) the current id

@arg $lmt_query - an SQL \"where\" clause to limit the query

@arg $direction - ('next' or 'previous') whether to find the next or previous item id

@returns - (int) the ID of the next or previous item id */

function get_item($tblname, $field, $startid, $lmt_query, $direction) {

$current_sequence = db_fetch_cell(\"select $field from $tblname where

$new_item_id = db_fetch_cell(\"select id from $tblname where $field $sql_operator id=$startid\");

$current_sequence and $lmt_query order by $field $sql_order limit 1\");

if ($direction == \"next\") { }

$sql_operator = \">\"; $sql_order = \"ASC\"; $sql_operator = \"<\"; $sql_order = \"DESC\"; if (empty($next_parent_id)) { }

return 0;

return $next_parent_id; }else{

}elseif ($direction == \"previous\") {

}

/* get_sequence - returns the next available sequence id @arg $id - (int) the current id

@arg $field - the field name that contains the target id @arg $table_name - the table name that contains the target id @arg $group_query - an SQL \"where\" clause to limit the query @returns - (int) the next available sequence id */

function get_sequence($id, $field, $table_name, $group_query) { }

/* move_item_down - moves an item down by swapping it with the item below it @arg $table_name - the table name that contains the target id @arg $current_id - (int) the current id

@arg $group_query - an SQL \"where\" clause to limit the query */ function move_item_down($table_name, $current_id, $group_query) {

$sequence = db_fetch_cell(\"select sequence from $table_name where $sequence_next = db_fetch_cell(\"select sequence from $table_name where db_execute(\"update $table_name set sequence=$sequence_next where id=$current_id\"); id=$next_item\"); id=$current_id\");

$next_item = get_item($table_name, \"sequence\\"next\");

}

if ($data[\"seq\"] == \"\") { }

$data = db_fetch_row(\"select $field from $table_name where id=$id\"); return $data[$field];

return 1;

return $data[\"seq\"]; }else{ if (empty($id)) {

$data = db_fetch_row(\"select max($field)+1 as seq from $table_name where if (empty($new_item_id)) { }

return $startid; return $new_item_id; }else{

$group_query\");

}else{

}

db_execute(\"update $table_name set sequence=$sequence where id=$next_item\");

/* move_item_up - moves an item down by swapping it with the item above it @arg $table_name - the table name that contains the target id @arg $current_id - (int) the current id

@arg $group_query - an SQL \"where\" clause to limit the query */ function move_item_up($table_name, $current_id, $group_query) { }

/* exec_into_array - executes a command and puts each line of its output into an array

@arg $command_line - the command to execute

@returns - (array) an array containing the command output */ function exec_into_array($command_line) { }

/* get_web_browser - determines the current web browser in use by the client @returns - ('ie' or 'moz' or 'other') */ function get_web_browser() {

if (!empty($_SERVER[\"HTTP_USER_AGENT\"])) {

if (stristr($_SERVER[\"HTTP_USER_AGENT\"], \"Mozilla\") &&

return \"moz\";

return $command_array;

for($i=0; list($key, $value) = each($out); $i++) { }

$command_array[$i] = $value; $command_array = array(); exec($command_line,$out,$err);

$sequence = db_fetch_cell(\"select sequence from $table_name where $sequence_last = db_fetch_cell(\"select sequence from $table_name where db_execute(\"update $table_name set sequence=$sequence_last where

db_execute(\"update $table_name set sequence=$sequence where id=$last_item\"); id=$current_id\"); id=$last_item\"); id=$current_id\");

$last_item = get_item($table_name, \"sequence\\"previous\");

(!(stristr($_SERVER[\"HTTP_USER_AGENT\"], \"compatible\")))) {

}elseif (stristr($_SERVER[\"HTTP_USER_AGENT\"], \"MSIE\")) {

}

}

}

return \"ie\"; return \"other\";

}else{

}else{

return \"other\";

/* get_graph_tree_array - returns a list of graph trees taking permissions into account if

necessary

@arg $return_sql - (bool) Whether to return the SQL to create the dropdown rather than an array

@arg $force_refresh - (bool) Force the refresh of the array from the database @returns - (array) an array containing a list of graph trees */

function get_graph_tree_array($return_sql = false, $force_refresh = false) {

$sql = \"select

graph_tree.id, graph_tree.name, user_auth_perms.user_id from graph_tree

left join user_auth_perms on (graph_tree.id=user_auth_perms.item_id

if ($current_user[\"policy_trees\"] == \"1\") { }

$sql_where = \"where user_auth_perms.user_id is null\"; $sql_where = \"where user_auth_perms.user_id is not null\"; }elseif ($current_user[\"policy_trees\"] == \"2\") {

if (read_config_option(\"auth_method\") != 0) {

$current_user = db_fetch_row(\"select policy_trees from user_auth where

/* build tree array */

if (!isset($_SESSION[\"tree_array\"]) || ($force_refresh) ||

(($_SESSION[\"tree_update_time\"] + read_graph_config_option(\"page_refresh\")) /* set the tree update time if not already set */ if (!isset($_SESSION[\"tree_update_time\"])) { }

$_SESSION[\"tree_update_time\"] = time();

< time())) {

id=\" . $_SESSION[\"sess_user_id\"]);

and user_auth_perms.type=2 and user_auth_perms.user_id=\" . $_SESSION[\"sess_user_id\"] . \") }

/* get_host_array - returns a list of hosts taking permissions into account if necessary @returns - (array) an array containing a list of hosts */ function get_host_array() {

$host_list = db_fetch_assoc(\"select

host.id,

CONCAT_WS('',host.description,' (',host.hostname,')') as name, user_auth_perms.user_id from host

left join user_auth_perms on (host.id=user_auth_perms.item_id and $sql_where

order by host.description,host.hostname\");

if ($current_user[\"policy_hosts\"] == \"1\") { }

$sql_where = \"where user_auth_perms.user_id is null\"; $sql_where = \"where user_auth_perms.user_id is not null\"; }elseif ($current_user[\"policy_hosts\"] == \"2\") { if (read_config_option(\"auth_method\") != 0) {

$current_user = db_fetch_row(\"select policy_hosts from user_auth where id=\" . if ($return_sql == true) { }

return $sql;

return db_fetch_assoc($sql); }else{ }

$_SESSION[\"tree_array\"] = $sql;

$_SESSION[\"tree_update_time\"] = time(); $sql = $_SESSION[\"tree_array\"];

}

$sql_where

order by graph_tree.name\";

}else{

$sql = \"select * from graph_tree order by name\";

} else {

$_SESSION[\"sess_user_id\"]);

user_auth_perms.type=3 and user_auth_perms.user_id=\" . $_SESSION[\"sess_user_id\"] . \")

}else{

}

}

$host_list = db_fetch_assoc(\"select id,CONCAT_WS('',description,'

(',hostname,')') as name from host order by description,hostname\");

return $host_list;

/* draw_navigation_text - determines the top header navigation text for the current page and displays it to the browser */

function draw_navigation_text() {

$nav = array(

\"graph_view.php:\" => array(\"title\" => \"Graphs\\"graph_view.php:tree\" => array(\"title\" => \"Tree Mode\\"graph_view.php:list\" => array(\"title\" => \"List Mode\\"graph_view.php:preview\" => array(\"title\" => \"Preview Mode\\"graph.php:\" => array(\"title\" => \"|current_graph_title|\\"graph.php:view\" => array(\"title\" => \"|current_graph_title|\\"graph.php:zoom\" => array(\"title\" => \"Zoom\

\"graph.php:properties\" => array(\"title\" => \"Properties\\"graph_settings.php:\" => array(\"title\" => \"Settings\\"index.php:\" => array(\"title\" => \"Console\\"graphs.php:\" => array(\"title\" => \"Graph Management\\"graphs.php:graph_edit\" => array(\"title\" => \"(Edit)\

\"graphs.php:graph_diff\" => array(\"title\" => \"Change Graph Template\\"mapping\" \"graphs.php:actions\" => array(\"title\" => \"Actions\global $config;

$nav_level_cache = (isset($_SESSION[\"sess_nav_level_cache\"]) ?

$_SESSION[\"sess_nav_level_cache\"] : array());

\"graph_view.php\

\"graph_view.php:\\"graph_view.php:\\"graph_view.php:\\"graph_view.php:,?\\"graph_view.php:,?\

\"graph_view.php:,?,graph.php:view\\"graph_view.php:,?,graph.php:view\

\"graph_view.php:\$config['url_path'] . \"index.php\\"index.php:\\"index.php:,graphs.php:\

=> \"index.php:,graphs.php:,graphs.php:graph_edit\\"index.php:,graphs.php:\

\"graphs_items.php:item_edit\" => array(\"title\" => \"Graph Items\\"graphs_new.php:\" => array(\"title\" => \"Create New Graphs\\"graphs_new.php:save\" => array(\"title\" => \"Create Graphs from Data Query\\"gprint_presets.php:\" => array(\"title\" => \"GPRINT Presets\\"gprint_presets.php:edit\" => array(\"title\" => \"(Edit)\\"gprint_presets.php:remove\" => array(\"title\" => \"(Remove)\\"cdef.php:\" => array(\"title\" => \"CDEF's\\"mapping\" => \"index.php:\\"url\" => \"cdef.php:edit\" => array(\"title\" => \"(Edit)\\"cdef.php:remove\" => array(\"title\" => \"(Remove)\\"cdef.php:item_edit\" => array(\"title\" => \"CDEF Items\\"tree.php:\" => array(\"title\" => \"Graph Trees\\"mapping\" => \"index.php:\\"url\" \"tree.php:edit\" => array(\"title\" => \"(Edit)\\"tree.php:remove\" => array(\"title\" => \"(Remove)\

\"tree.php:item_edit\" => array(\"title\" => \"Graph Tree Items\\"tree.php:item_remove\" => array(\"title\" => \"(Remove Item)\\"color.php:\" => array(\"title\" => \"Colors\\"color.php:edit\" => array(\"title\" => \"(Edit)\

\"graph_templates.php:\" => array(\"title\" => \"Graph Templates\\"graph_templates.php:template_edit\" => array(\"title\" => \"(Edit)\\"graph_templates.php:actions\" => array(\"title\" => \"Actions\\"graph_templates_items.php:item_edit\" => array(\"title\" => \"Graph Template

\"index.php:,graphs.php:,graphs.php:graph_edit\\"index.php:\

\"mapping\" => \"index.php:,graphs_new.php:\\"index.php:\\"index.php:,gprint_presets.php:\\"index.php:,gprint_presets.php:\\"cdef.php\

\"index.php:,cdef.php:\\"index.php:,cdef.php:\

\"index.php:,cdef.php:,cdef.php:edit\=> \"tree.php\

\"index.php:,tree.php:\\"index.php:,tree.php:\

\"index.php:,tree.php:,tree.php:edit\\"index.php:,tree.php:,tree.php:edit\=> \"color.php\

\"index.php:,color.php:\

\"index.php:\=> \"index.php:,graph_templates.php:\\"index.php:,graph_templates.php:\Items\

\"index.php:,graph_templates.php:,graph_templates.php:template_edit\\"level\" => \"3\"),

\"graph_templates_inputs.php:input_edit\" => array(\"title\" => \"Graph Item

Inputs\

\"index.php:,graph_templates.php:,graph_templates.php:template_edit\\"level\" => \"3\"),

\"graph_templates_inputs.php:input_remove\" => array(\"title\" => \"(Remove)\

\"mapping\" => \"index.php:,graph_templates.php:,graph_templates.php:template_edit\\"url\" => \"\

\"host_templates.php:\" => array(\"title\" => \"Host Templates\\"host_templates.php:edit\" => array(\"title\" => \"(Edit)\\"host_templates.php:actions\" => array(\"title\" => \"Actions\\"graph_templates.php:actions\" => array(\"title\" => \"Actions\\"data_templates.php:\" => array(\"title\" => \"Data Templates\\"data_templates.php:template_edit\" => array(\"title\" => \"(Edit)\\"mapping\" => \"data_templates.php:actions\" => array(\"title\" => \"Actions\\"data_sources.php:\" => array(\"title\" => \"Data Sources\\"data_sources.php:ds_edit\" => array(\"title\" => \"(Edit)\\"data_sources.php:actions\" => array(\"title\" => \"Actions\\"host.php:\" => array(\"title\" => \"Devices\\"host.php:edit\" => array(\"title\" => \"(Edit)\\"host.php:actions\" => array(\"title\" => \"Actions\\"rra.php:\" => array(\"title\" => \"Round Robin Archives\\"rra.php:edit\" => array(\"title\" => \"(Edit)\\"rra.php:remove\" => array(\"title\" => \"(Remove)\

\"data_input.php:\" => array(\"title\" => \"Data Input Methods\\"data_input.php:actions\" => array(\"title\" => \"Actions\\"data_input.php:edit\" => array(\"title\" => \"(Edit)\

\"index.php:\\"index.php:,host_templates.php:\\"index.php:,host_templates.php:\\"index.php:,graph_templates.php:\\"index.php:\\"index.php:,data_templates.php:\\"index.php:,data_templates.php:\\"index.php:\\"index.php:,data_sources.php:\\"index.php:,data_sources.php:\=> \"host.php\

\"index.php:,host.php:\\"index.php:,host.php:\\"index.php:\\"index.php:,rra.php:\\"index.php:,rra.php:\\"index.php:\\"index.php:,data_input.php:\

\"index.php:,data_input.php:\

\"data_input.php:remove\" => array(\"title\" => \"(Remove)\\"data_input.php:field_edit\" => array(\"title\" => \"Data Input Fields\\"mapping\" \"data_input.php:field_remove\" => array(\"title\" => \"(Remove Item)\\"data_queries.php:\" => array(\"title\" => \"Data Queries\\"data_queries.php:actions\" => array(\"title\" => \"Actions\\"data_queries.php:edit\" => array(\"title\" => \"(Edit)\

\"data_queries.php:item_edit\" => array(\"title\" => \"Associated Graph Templates\

\"index.php:,data_input.php:\

=> \"index.php:,data_input.php:,data_input.php:edit\=> \"index.php:,data_input.php:,data_input.php:edit\\"index.php:\\"index.php:,data_queries.php:\\"index.php:,data_queries.php:\

\"mapping\" => \"index.php:,data_queries.php:,data_queries.php:edit\\"level\" => \"3\"),

\"data_queries.php:item_remove\" => array(\"title\" => \"(Remove Item)\\"mapping\" \"utilities.php:\" => array(\"title\" => \"Utilities\\"utilities.php:view_poller_cache\" => array(\"title\" => \"View Poller Cache\\"utilities.php:view_snmp_cache\" => array(\"title\" => \"View SNMP Cache\\"utilities.php:clear_poller_cache\" => array(\"title\" => \"Clear Poller Cache\\"utilities.php:view_logfile\" => array(\"title\" => \"View Cacti Log File\\"utilities.php:clear_logfile\" => array(\"title\" => \"Clear Cacti Log File\\"utilities.php:view_user_log\" => array(\"title\" => \"View User Log File\\"utilities.php:clear_user_log\" => array(\"title\" => \"Clear User Log File\\"utilities.php:view_tech\" => array(\"title\" => \"Technical Support\\"settings.php:\" => array(\"title\" => \"Cacti Settings\\"user_admin.php:\" => array(\"title\" => \"User Management\\"user_admin.php:user_edit\" => array(\"title\" => \"(Edit)\\"user_admin.php:actions\" => array(\"title\" => \"(Action)\

=> \"index.php:,data_queries.php:,data_queries.php:edit\\"url\" => \"\\"level\" => \"3\"), \"url\" => \"utilities.php\

\"mapping\" => \"index.php:,utilities.php:\\"mapping\" => \"index.php:,utilities.php:\\"mapping\" => \"index.php:,utilities.php:\\"mapping\" => \"index.php:,utilities.php:\\"mapping\" => \"index.php:,utilities.php:\\"mapping\" => \"index.php:,utilities.php:\\"mapping\" => \"index.php:,utilities.php:\=> \"index.php:,utilities.php:\\"index.php:\\"index.php:\\"index.php:,user_admin.php:\\"index.php:,user_admin.php:\

\"user_admin.php:graph_perms_edit\" => array(\"title\" => \"Edit (Graph \"user_admin.php:user_realms_edit\" => array(\"title\" => \"Edit (Realm \"user_admin.php:graph_settings_edit\" => array(\"title\" => \"Edit (Graph \"about.php:\" => array(\"title\" => \"About Cacti\\"templates_export.php:\" => array(\"title\" => \"Export Templates\\"templates_export.php:save\" => array(\"title\" => \"Export Results\

Permissions)\\"mapping\" => \"index.php:,user_admin.php:\\"url\" => \"\\"level\" => \"2\"), Permissions)\\"mapping\" => \"index.php:,user_admin.php:\\"url\" => \"\\"level\" => \"2\"), Settings)\\"url\" => \"about.php\

\"index.php:\

=> \"index.php:,templates_export.php:\\"2\"),

if ($i == 0) {

/* always use the default for level == 0 */ $url = $nav{$current_mappings[$i]}[\"url\"];

/* found a match in the url cache for this level */ $url = $nav_level_cache{$i}[\"url\"];

/* found a default url in the above array */ $url = $current_array[\"url\"];

/* resolve all mappings to build the navigation string */ for ($i=0; ($iif (empty($current_mappings[$i])) { continue; } /* find the current page in the big array */

$current_array = $nav{$current_page . \":\" . $current_action}; $current_mappings = split(\$current_nav = \"\";

$current_action = (isset($_REQUEST[\"action\"]) ? $_REQUEST[\"action\"] : \"\"); input_validate_input_regex(get_request_var_request(\"action\"), \"^([a-zA-Z0-9_-]+)$\");

$current_page = basename($_SERVER[\"PHP_SELF\"]);

$nav = api_plugin_hook_function('draw_navigation_text', $nav);

\"templates_import.php:\" => array(\"title\" => \"Import Templates\);

\"index.php:\

}elseif (!empty($nav_level_cache{$i}[\"url\"])) {

}elseif (!empty($current_array[\"url\"])) {

}else{ }

if ($current_mappings[$i] == \"?\") {

/* '?' tells us to pull title from the cache at this level */ if (isset($nav_level_cache{$i})) {

$current_nav .= (empty($url) ? \"\" : \"\") . /* default to no url */ $url = \"\";

resolve_navigation_variables($nav{$nav_level_cache{$i}[\"id\"]}[\"title\"]) . (empty($url) ? \"\" : \"\") . \" -> \";

}

/* there is no '?' - pull from the above array */ $current_nav .= (empty($url) ? \"\" : \"\") . }else{

resolve_navigation_variables($nav{$current_mappings[$i]}[\"title\"]) . (empty($url) ? \"\" : \"\") . \" -> \"; }

/* resolve_navigation_variables - substitute any variables contained in the navigation text

@arg $text - the text to substitute in

@returns - the original navigation text with all substitutions made */ function resolve_navigation_variables($text) {

if (preg_match_all(\"/\\|([a-zA-Z0-9_]+)\\|/\

for ($i=0; $iswitch ($matches[1][$i]) { case 'current_graph_title': }

$text = str_replace(\"|\" . $matches[1][$i] . \"|\break;

print $current_nav;

/* keep a cache for each level we encounter */

$nav_level_cache{$current_array[\"level\"]} = array(\"id\" => $current_page . \":\" . $_SESSION[\"sess_nav_level_cache\"] = $nav_level_cache;

$current_nav .= resolve_navigation_variables($current_array[\"title\"]); }

}

$current_action, \"url\" => get_browser_query_string());

get_graph_title($_GET[\"local_graph_id\"]), $text);

}

}

return $text;

/* get_associated_rras - returns a list of all RRAs referenced by a particular graph @arg $local_graph_id - (int) the ID of the graph to retrieve a list of RRAs for @returns - (array) an array containing the name and id of each RRA found */ function get_associated_rras($local_graph_id) { ra) }

/* get_browser_query_string - returns the full url, including args requested by the browser

@returns - the url requested by the browser */ function get_browser_query_string() { }

/* get_hash_graph_template - returns the current unique hash for a graph template @arg $graph_template_id - (int) the ID of the graph template to return a hash for @arg $sub_type (optional) return the hash for a particlar sub-type of this type @returns - a 128-bit, hexadecimal hash */

if (!empty($_SERVER[\"REQUEST_URI\"])) { }

return basename($_SERVER[\"REQUEST_URI\"]);

return basename($_SERVER[\"PHP_SELF\"]) . (empty($_SERVER[\"QUERY_STRING\"]) ? }else{

where graph_templates_item.task_item_id=data_template_rrd.id

and data_template_rrd.local_data_id=data_template_data.local_data_id and data_template_data.id=data_template_data_rra.data_template_data_id and data_template_data_rra.rra_id=rra.id

and graph_templates_item.local_graph_id=$local_graph_id group by rra.id

order by rra.timespan\"); return db_fetch_assoc(\"select

rra.id, rra.steps, rra.rows, rra.name, rra.timespan,

data_template_data.rrd_step from

(graph_templates_item,data_template_data_rra,data_template_rrd,data_template_data,r

\"\" : \"?\" . $_SERVER[\"QUERY_STRING\"]);

function get_hash_graph_template($graph_template_id, $sub_type = \"graph_template\") { }

/* get_hash_data_template - returns the current unique hash for a data template @arg $graph_template_id - (int) the ID of the data template to return a hash for @arg $sub_type (optional) return the hash for a particlar sub-type of this type @returns - a 128-bit, hexadecimal hash */

function get_hash_data_template($data_template_id, $sub_type = \"data_template\") { }

/* get_hash_data_input - returns the current unique hash for a data input method @arg $graph_template_id - (int) the ID of the data input method to return a hash for @arg $sub_type (optional) return the hash for a particlar sub-type of this type @returns - a 128-bit, hexadecimal hash */

function get_hash_data_input($data_input_id, $sub_type = \"data_input_method\") {

if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

if ($sub_type == \"data_template\") {

$hash = db_fetch_cell(\"select hash from data_template where if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

if ($sub_type == \"graph_template\") {

$hash = db_fetch_cell(\"select hash from graph_templates where

id=$graph_template_id\");

}elseif ($sub_type == \"graph_template_item\") {

$hash = db_fetch_cell(\"select hash from graph_templates_item where

id=$graph_template_id\");

}elseif ($sub_type == \"graph_template_input\") { }

$hash = db_fetch_cell(\"select hash from graph_template_input where

id=$graph_template_id\");

id=$data_template_id\");

}elseif ($sub_type == \"data_template_item\") { }

$hash = db_fetch_cell(\"select hash from data_template_rrd where

id=$data_template_id\");

}

if ($sub_type == \"data_input_method\") { }

if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

$hash = db_fetch_cell(\"select hash from data_input where id=$data_input_id\"); $hash = db_fetch_cell(\"select hash from data_input_fields where }elseif ($sub_type == \"data_input_field\") {

id=$data_input_id\");

/* get_hash_cdef - returns the current unique hash for a cdef

@arg $graph_template_id - (int) the ID of the cdef to return a hash for

@arg $sub_type (optional) return the hash for a particlar sub-type of this type @returns - a 128-bit, hexadecimal hash */

function get_hash_cdef($cdef_id, $sub_type = \"cdef\") { }

/* get_hash_gprint - returns the current unique hash for a gprint preset

@arg $graph_template_id - (int) the ID of the gprint preset to return a hash for @returns - a 128-bit, hexadecimal hash */ function get_hash_gprint($gprint_id) {

if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

$hash = db_fetch_cell(\"select hash from graph_templates_gprint where id=$gprint_id\");

if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

if ($sub_type == \"cdef\") { }

$hash = db_fetch_cell(\"select hash from cdef where id=$cdef_id\"); $hash = db_fetch_cell(\"select hash from cdef_items where id=$cdef_id\"); }elseif ($sub_type == \"cdef_item\") {

}

/* get_hash_host_template - returns the current unique hash for a gprint preset @arg $host_template_id - (int) the ID of the host template to return a hash for @returns - a 128-bit, hexadecimal hash */

function get_hash_host_template($host_template_id) { }

/* get_hash_data_query - returns the current unique hash for a data query @arg $graph_template_id - (int) the ID of the data query to return a hash for @arg $sub_type (optional) return the hash for a particlar sub-type of this type @returns - a 128-bit, hexadecimal hash */

function get_hash_data_query($data_query_id, $sub_type = \"data_query\") { }

/* get_hash_round_robin_archive - returns the current unique hash for a round robin archive

@arg $rra_id - (int) the ID of the round robin archive to return a hash for

if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

if ($sub_type == \"data_query\") {

$hash = db_fetch_cell(\"select hash from snmp_query where id=$data_query_id\"); $hash = db_fetch_cell(\"select hash from snmp_query_graph where }elseif ($sub_type == \"data_query_graph\") { if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

$hash = db_fetch_cell(\"select hash from host_template where id=$host_template_id\");

id=$data_query_id\");

}elseif ($sub_type == \"data_query_sv_data_source\") {

$hash = db_fetch_cell(\"select hash from snmp_query_graph_rrd_sv where

id=$data_query_id\");

}elseif ($sub_type == \"data_query_sv_graph\") { }

$hash = db_fetch_cell(\"select hash from snmp_query_graph_sv where

id=$data_query_id\");

@returns - a 128-bit, hexadecimal hash */ function get_hash_round_robin_archive($rra_id) { }

/* get_hash_version - returns the item type and cacti version in a hash format @arg $type - the type of item to represent ('graph_template','data_template', 'data_input_method','cdef','gprint_preset','data_query','host_template') @returns - a 24-bit hexadecimal hash (8-bits for type, 16-bits for version) */ function get_hash_version($type) { }

/* generate_hash - generates a new unique hash @returns - a 128-bit, hexadecimal hash */ function generate_hash() { }

/* debug_log_insert - inserts a line of text into the debug log @arg $type - the 'category' or type of debug message @arg $text - the actual debug message */ function debug_log_insert($type, $text) { }

/* debug_log_clear - clears the debug log for a particular category

@arg $type - the 'category' to clear the debug log for. omitting this argument implies all categories */

function debug_log_clear($type = \"\") {

array_push($_SESSION[\"debug_log\"][$type], $text); if (!isset($_SESSION[\"debug_log\"][$type])) { }

$_SESSION[\"debug_log\"][$type] = array();

return md5(session_id() . microtime() . rand(0,1000)); global $config;

return $hash_type_codes[$type] . $hash_version_codes{$config[\"cacti_version\"]}; global $hash_type_codes, $hash_version_codes, $config; if (ereg(\"[a-fA-F0-9]{32}\ }

return $hash;

return generate_hash(); }else{

$hash = db_fetch_cell(\"select hash from rra where id=$rra_id\");

}

if ($type == \"\") { }

kill_session_var(\"debug_log\"); if (isset($_SESSION[\"debug_log\"])) { }

unset($_SESSION[\"debug_log\"][$type]);

}else{

/* debug_log_return - returns the debug log for a particular category @arg $type - the 'category' to return the debug log for. @returns - the full debug log for a particular category */ function debug_log_return($type) { }

/* sanitize_search_string - cleans up a search string submitted by the user to be passed to the database. NOTE: some of the code for this function came from the phpBB project.

@arg $string - the original raw search string @returns - the sanitized search string */ function sanitize_search_string($string) {

/* Replace line endings by a space */

$string = preg_replace('/[\\n\\r]/is', ' ', $string); /* HTML entities like   */

$string = preg_replace('/\\b&[a-z]+;\\b/', ' ', $string); /* Remove URL's */ $string =

static $drop_char_match = array('^', '$', '<', '>', '`', '\\'', '\"', '|', ',', static $drop_char_replace = array(' ', ' ', ' ', ' ', '', '', ' ', ' ', ' ', '?', '~', '+', '[', ']', '{', '}', '#', ';', '!', '='); ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ');

return $log_text;

if (isset($_SESSION[\"debug_log\"][$type])) { }

for ($i=0; $i$log_text .= \"+ \" . $_SESSION[\"debug_log\"][$type][$i] . \"
\";

$log_text = \"\";

preg_replace('/\\b[a-z0-9]+:\\/\\/[a-z0-9\\.\\-]+(\\/[a-z0-9\\?\\.%_\\-\\+=&\\/]+)?/', ' ', $string);

} ?>

/* Filter out strange characters like ^, $, &, change \"it's\" to \"its\" */ for($i = 0; $i < count($drop_char_match); $i++) { }

$string = str_replace('*', ' ', $string); return $string;

$string = str_replace($drop_char_match[$i], $drop_char_replace[$i],

$string);

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- jqkq.cn 版权所有 赣ICP备2024042794号-4

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务