-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd_dependency.php
132 lines (121 loc) · 3.89 KB
/
add_dependency.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<?php
/*
Lilac - A Nagios Configuration Tool
Copyright (C) 2018 EyesOfNetwork Team
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
* host_template.php
* Author: EyesOfNetwork Team (eyesofnetwork@eyesofnetwork.com)
* Description:
* Provides interface to maintain host templates
*
*/
include_once('includes/config.inc');
if(isset($_GET['host_template_id'])) {
$tempSource = NagiosHostTemplatePeer::retrieveByPK($_GET['host_template_id']);
$link = "host_template.php";
$fieldName = "host_template_id";
if(!$tempSource) {
header("Location: welcome.php");
}
$type = "hosttemplate";
$title = "Host Template";
}
else if(isset($_GET['host_id'])) {
$tempSource = NagiosHostPeer::retrieveByPK($_GET['host_id']);
$fieldName = "host_id";
$link = "hosts.php";
if(!$tempSource) {
header("Location: welcome.php");
}
$type = "host";
$title = "Host";
}
else if(isset($_GET['service_template_id'])) {
$tempSource = NagiosServiceTemplatePeer::retrieveByPK($_GET['service_template_id']);
$fieldName = "service_template_id";
$link = "service_template.php";
if(!$tempSource) {
header("Location: welcome.php");
}
$type = "servicetemplate";
$title = "Service Template";
}
else if(isset($_GET['service_id'])) {
$tempSource = NagiosServicePeer::retrieveByPK($_GET['service_id']);
$fieldName = "service_id";
$link = "service.php";
if(!$tempSource) {
header("Location: welcome.php");
}
$type = "service";
$title = ""; // This can be ignored later on.
}
else if(isset($_GET['hostgroup_id'])) {
$tempSource = NagiosHostgroupPeer::retrieveByPK($_GET['hostgroup_id']);
$fieldName = "hostgroup_id";
$link = "hostgroups.php";
if(!$tempSource) {
header("Location: welcome.php");
}
$type = "hostgroup";
$title = "Hostgroup";
}
if(isset($_POST['request'])) {
if($_POST['request'] == "add_dependency") {
// Error checking
if(trim($_POST['name']) == '') {
$error = "Dependency name cannot be blank.";
}
else {
// Creating dependency.
$dependency = new NagiosDependency();
switch($type) {
case 'host':
$dependency->setNagiosHost($tempSource);
break;
case 'service':
$dependency->setNagiosService($tempSource);
break;
case 'hostgroup':
$dependency->setNagiosHostgroup($tempSource);
break;
}
$dependency->setName($_POST['name']);
$dependency->save();
header("Location: dependency.php?id= " . $dependency->getId());
exit();
}
}
}
if($type == "service") {
$textTitle = $tempSource->getOwnerDescription() . " : " . $tempSource->getDescription();
}
else {
$textTitle = $tempSource->getName();
}
print_header("Add Dependency To " . $title . " " . $textTitle);
print_window_header("Add Dependency To " . $title . " " . $textTitle, "100%");
?>
<strong>Provide A Name for this Dependency</strong>
<form action="add_dependency.php?<?php echo $fieldName;?>=<?php echo $tempSource->getId();?>" method="post">
<input type="hidden" name="request" value="add_dependency" />
<input id="name" type="text" size="20" name="name" value="" /><br /><br />
<input class="btn btn-primary" type="submit" value="Create Dependency" />
<br />
<br /><a class="btn btn-default" href="<?php echo $link;?>?id=<?php echo $tempSource->getId();?>">Cancel And Return To <?php echo $title;?> <?php echo $textTitle;?></a>
</form>
<?php
print_window_footer();
?>