~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to frontends/php/include/nodes.inc.php

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
/*
 
3
** ZABBIX
 
4
** Copyright (C) 2000-2005 SIA Zabbix
 
5
**
 
6
** This program is free software; you can redistribute it and/or modify
 
7
** it under the terms of the GNU General Public License as published by
 
8
** the Free Software Foundation; either version 2 of the License, or
 
9
** (at your option) any later version.
 
10
**
 
11
** This program is distributed in the hope that it will be useful,
 
12
** but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
** GNU General Public License for more details.
 
15
**
 
16
** You should have received a copy of the GNU General Public License
 
17
** along with this program; if not, write to the Free Software
 
18
** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
**/
 
20
        require_once    "include/db.inc.php";
 
21
?>
 
22
<?php
 
23
        function        detect_node_type($node_data)
 
24
        {
 
25
                global $ZBX_CURNODEID, $ZBX_CURMASTERID;
 
26
 
 
27
                if($node_data['nodeid'] == $ZBX_CURNODEID)              $node_type = ZBX_NODE_LOCAL;
 
28
                else if($node_data['nodeid'] == $ZBX_CURMASTERID)       $node_type = ZBX_NODE_MASTER;
 
29
                else if($node_data['masterid'] == $ZBX_CURNODEID)       $node_type = ZBX_NODE_REMOTE;
 
30
                else $node_type = -1;
 
31
 
 
32
                return $node_type;
 
33
        }
 
34
 
 
35
        function        node_type2str($node_type)
 
36
        {
 
37
                $result = '';
 
38
                switch($node_type)
 
39
                {
 
40
                        case ZBX_NODE_REMOTE:   $result = S_REMOTE;     break;
 
41
                        case ZBX_NODE_MASTER:   $result = S_MASTER;     break;
 
42
                        case ZBX_NODE_LOCAL:    $result = S_LOCAL;      break;
 
43
                        default:                $result = S_UNKNOWN;    break;
 
44
                }
 
45
 
 
46
                return $result;
 
47
        }
 
48
 
 
49
        function        add_node($new_nodeid,$name,$timezone,$ip,$port,$slave_history,$slave_trends,$node_type)
 
50
        {
 
51
                global $ZBX_CURNODEID, $ZBX_CURMASTERID;
 
52
 
 
53
                if( !eregi('^'.ZBX_EREG_NODE_FORMAT.'$', $name) )
 
54
                {
 
55
                        error("Incorrect characters used for Node name");
 
56
                        return false;
 
57
                }
 
58
 
 
59
                switch($node_type)
 
60
                {
 
61
                        case ZBX_NODE_REMOTE:
 
62
                                $masterid = $ZBX_CURNODEID;
 
63
                                $nodetype = 0;
 
64
                                break;
 
65
                        case ZBX_NODE_MASTER:
 
66
                                $masterid = 0;
 
67
                                $nodetype = 0;
 
68
                                if($ZBX_CURMASTERID)
 
69
                                {
 
70
                                        error('Master node already exist');
 
71
                                        return false;
 
72
                                }
 
73
                                break;
 
74
                        case ZBX_NODE_LOCAL:
 
75
                                $masterid = $ZBX_CURMASTERID;
 
76
                                $nodetype = 1;
 
77
                                break;
 
78
                        default:
 
79
                                error('Incorrect node type');
 
80
                                return false;
 
81
                                break;
 
82
                }
 
83
 
 
84
                if(DBfetch(DBselect('select nodeid from nodes where nodeid='.$new_nodeid)))
 
85
                {
 
86
                        error('Node with same ID already exist.');
 
87
                        return false;
 
88
                }
 
89
 
 
90
                $result = DBexecute('insert into nodes (nodeid,name,timezone,ip,port,slave_history,slave_trends,'.
 
91
                                'event_lastid,history_lastid,nodetype,masterid) values ('.
 
92
                                $new_nodeid.','.zbx_dbstr($name).','.$timezone.','.zbx_dbstr($ip).','.$port.','.$slave_history.','.$slave_trends.','.
 
93
                                '0,0,'.$nodetype.','.$masterid.')');
 
94
 
 
95
                if($result && $node_type == ZBX_NODE_MASTER)
 
96
                {
 
97
                        DBexecute('update nodes set masterid='.$new_nodeid.' where nodeid='.$ZBX_CURNODEID);
 
98
                        $ZBX_CURMASTERID = $new_nodeid; /* applay Master node for this script */
 
99
                }
 
100
 
 
101
                return ($result ? $new_nodeid : $result);
 
102
        }
 
103
 
 
104
        function        update_node($nodeid,$new_nodeid,$name,$timezone,$ip,$port,$slave_history,$slave_trends)
 
105
        {
 
106
                if( !eregi('^'.ZBX_EREG_NODE_FORMAT.'$', $name) )
 
107
                {
 
108
                        error("Incorrect characters used for Node name");
 
109
                        return false;
 
110
                }
 
111
 
 
112
                $result = DBexecute('update nodes set nodeid='.$new_nodeid.',name='.zbx_dbstr($name).','.
 
113
                                'timezone='.$timezone.',ip='.zbx_dbstr($ip).',port='.$port.','.
 
114
                                'slave_history='.$slave_history.',slave_trends='.$slave_trends.
 
115
                                ' where nodeid='.$nodeid);
 
116
                return $result;
 
117
        }
 
118
 
 
119
        function        delete_node($nodeid)
 
120
        {
 
121
                $result = false;
 
122
                $node_data = DBfetch(DBselect('select * from nodes where nodeid='.$nodeid));
 
123
 
 
124
                $node_type = detect_node_type($node_data);
 
125
 
 
126
                if($node_type == ZBX_NODE_LOCAL)
 
127
                {
 
128
                        error('Unable to remove local node');
 
129
                }
 
130
                else
 
131
                {
 
132
                        $housekeeperid = get_dbid('housekeeper','housekeeperid');
 
133
                        $result = (
 
134
                                DBexecute("insert into housekeeper (housekeeperid,tablename,field,value)".
 
135
                                        " values ($housekeeperid,'nodes','nodeid',$nodeid)") &&
 
136
                                DBexecute('delete from nodes where nodeid='.$nodeid) &&
 
137
                                DBexecute('update nodes set masterid=0 where masterid='.$nodeid)
 
138
                                );
 
139
                        error('Please be aware that database still contains data related to the deleted Node');
 
140
                }
 
141
                return $result;
 
142
        }
 
143
 
 
144
        function        get_node_by_nodeid($nodeid)
 
145
        {
 
146
                return DBfetch(DBselect('select * from nodes where nodeid='.$nodeid));
 
147
        }
 
148
 
 
149
        function        get_node_path($nodeid, $result='/')
 
150
        {
 
151
                if($node_data = get_node_by_nodeid($nodeid))
 
152
                {
 
153
                        if($node_data['masterid'])
 
154
                        {
 
155
                                $result = get_node_path($node_data['masterid'],$result);
 
156
                        }
 
157
                        $result .= $node_data['name'].'/';
 
158
                }
 
159
                return $result;
 
160
        }
 
161
?>