-
Notifications
You must be signed in to change notification settings - Fork 21
/
install.php
executable file
·249 lines (213 loc) · 7.04 KB
/
install.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/usr/bin/php
<?php
// Nagios V-Shell
// Copyright (c) 2010-2011 Nagios Enterprises, LLC.
// Install script written by Mike Guthrie <[email protected]>
//
// @TODO: modify this script to find and parse the main nagios.cfg file for all
// relevant information.
///////////////////////////// DO NOT EDIT THIS FILE ///////////////////////////
//
// Custom configuration options should be added to install-config.php
include(dirname(__FILE__).'/config.php');
$errors = 0;
$errorstring = '';
/////////////////////////////// Configure Apache //////////////////////////////
// Backup web directory if it already exists.
$output = system('/usr/bin/test -d '.escapeshellarg(TARGETDIR), $code);
if($code == 0)
{
echo "Backing up current web directory...\n";
$output = system('/bin/mv '.escapeshellarg(TARGETDIR).' '.escapeshellarg(TARGETDIR).'.'.date('Ymd\.His').'.bak', $code);
if($code > 0)
{
$errors++;
$errorstring .= "ERROR: Failed to backup existing ".TARGETDIR." directory \n$output\n";
}
}
// Copy web files to web directory
echo "Copying files...\n";
$output = system('/bin/cp -r ./www '.escapeshellarg(TARGETDIR), $code);
if($code > 0)
{
$errors++;
$errorstring .= "ERROR: Failed to copy files to ".TARGETDIR." directory \n$output\n";
}
// Create apache conf file for project
echo "Copying apache configuration file...\n";
$apache_conf_file = escapeshellarg(APACHECONFDIR).'/'.escapeshellarg(APACHECONFFILE);
$output = system('/bin/touch '.$apache_conf_file.' || /usr/bin/touch '.$apache_conf_file, $code);
if($code > 0){
$errors++;
$errorstring .= "ERROR: Failed to create apache configuration file in the ".APACHECONFDIR." directory \n$output\n";
}else{
// Try to create from template file, fall back on default file
ob_start();
include(dirname(__FILE__).'/config/vshell_apache.conf.template');
$apache_conf = ob_get_clean();
if( ! file_put_contents(APACHECONFDIR.'/'.APACHECONFFILE, $apache_conf) ){
$errors++;
$errorstring .= "ERROR: Failed to create apache config file from template.";
$errorstring .= "Installing default file instead. Manually check ".$apache_conf_file." values are correct\n";
$output = system('/bin/cp config/vshell_apache.conf '.$apache_conf_file, $code);
if($code > 0) {
$errors++;
$errorstring .= "ERROR: Failed to create apache configuration file from default file \n$output\n";
}
}
}
// Restart apache service
if( file_exists('/etc/init.d/httpd') ){ // RHEL
$action = 'service';
$service = 'httpd';
}elseif( file_exists('/etc/init.d/apache2') ){ // Debian
$action = 'invoke-rc.d';
$service = 'apache2';
}else{
$action = false;
$service = false;
}
if($service)
{
echo "Restarting apache...\n";
$output = system("{$action} {$service} restart", $code);
echo $output;
if($code > 0)
{
$errors++;
$errorstring .= "ERROR: Failed to restart apache, please restart apache manually \n$output\n";
}
}
else
{
$errors++;
$errorstring .= "ERROR: Failed to restart apache, could not find service name. Please restart apache manually \n$output\n";
}
///////////////////////////// Check file locations ////////////////////////////
echo "Checking for file locations...\n";
// Status file
if(file_exists( '/usr/local/nagios/var/status.dat'))
{
$statusfile = '/usr/local/nagios/var/status.dat'; //source installs
}
elseif(file_exists('/var/nagios/status.dat')) //yum installs
{
$statusfile = '/var/nagios/status.dat';
}
elseif(file_exists('/var/log/nagios/status.dat')) // centos 6.5 yum package install
{
$statusfile = '/var/log/nagios/status.dat';
}
elseif(file_exists('/var/cache/nagios3/status.dat')) //ubuntu debian nagios3 installs
{
$statusfile = '/var/cache/nagios3/status.dat';
}
else
{
$errors++;
$errorstring .= "NOTICE: status.dat file not found. Please specify the location of this file in your /etc/".ETC_CONF." file\n";
$statusfile = '';
}
define('STATUSFILE', $statusfile);
// Object cache file
if(file_exists('/usr/local/nagios/var/objects.cache'))
{
$objectfile = '/usr/local/nagios/var/objects.cache'; //source installs
}
elseif(file_exists('/var/nagios/objects.cache')) //yum installs
{
$objectfile = '/var/nagios/objects.cache';
}
elseif(file_exists('/var/log/nagios/objects.cache')) // centos 6.5 yum package install
{
$objectfile = '/var/log/nagios/objects.cache';
}
elseif(file_exists('/var/cache/nagios3/objects.cache')) //ubuntu debian nagios3 installs
{
$objectfile = '/var/cache/nagios3/objects.cache';
}
else
{
$errors++;
$errorstring .= "NOTICE: objects.cache file not found. Please specify the location of this file in your /etc/".ETC_CONF." file\n";
$objectfile = '';
}
define('OBJECTSFILE', $objectfile);
// cgi.cfg file
if(file_exists('/usr/local/nagios/etc/cgi.cfg'))
{
$cgifile = '/usr/local/nagios/etc/cgi.cfg'; //source installs
}
elseif(file_exists('/etc/nagios/cgi.cfg')) //yum installs
{
$cgifile = '/etc/nagios/cgi.cfg';
}
elseif(file_exists('/etc/nagios3/cgi.cfg')) //ubuntu/debian nagios3 installs
{
$cgifile = '/etc/nagios3/cgi.cfg';
}
else
{
$errors++;
$errorstring .= "NOTICE: cgi.cfg file not found. Please specify the location of this file in your /etc/".ETC_CONF." file\n";
$cgifile = '';
}
define('CGICFG', $cgifile);
// nagios.cmd file
//
// Check for directory instead of file. The file is actually a named
// pipe and its existence can be transient.
if(is_dir('/usr/local/nagios/var/rw'))
{
$nagcmd = '/usr/local/nagios/var/rw/nagios.cmd'; //source install
}
elseif(is_dir('/var/nagios/rw')) //yum install
{
$nagcmd = '/var/nagios/rw/nagios.cmd';
}
elseif(file_exists('/var/spool/nagios/cmd')) // centos 6.5 yum package install
{
$nagcmd = '/var/spool/nagios/cmd/nagios.cmd';
}
elseif(is_dir('/var/lib/nagios3/rw')) //ubuntu/debian nagios3
{
$nagcmd = '/var/lib/nagios3/rw/nagios.cmd';
}
else
{
$errors++;
$errorstring .= "NOTICE: nagios.cmd file not found. Please specify the location of this file in your /etc/".ETC_CONF." file\n";
$nagcmd = '';
}
define('NAGCMD', $nagcmd);
////////////////////////////// VShell conf file //////////////////////////////
echo "Creating vshell configuration file...\n";
$output = system('/bin/touch /etc/'.ETC_CONF, $code);
if($code > 0){
$errors++;
$errorstring .= "ERROR: Failed to create config/".ETC_CONF." file in /etc directory \n$output\n";
}else{
// Try to create from template file, fall back on default file
ob_start();
include(dirname(__FILE__).'/config/vshell.conf.template');
$conf = ob_get_clean();
if( ! file_put_contents('/etc/'.ETC_CONF, $conf) ){
$errors++;
$errorstring .= "ERROR: Failed to create config/".ETC_CONF." file from template.";
$errorstring .= "Installing default file instead. Manually check /etc/".ETC_CONF." values are correct\n";
$output = system('/bin/cp config/vshell.conf.default /etc/'.ETC_CONF, $code);
if($code > 0) {
$errors++;
$errorstring .= "ERROR: Failed to copy config/vshell.conf file to /etc directory \n$output\n";
}
}
}
////////////////////////////////// All done ///////////////////////////////////
echo "VShell Installation Script Complete!\n";
if( $errors > 0 ){
echo "\n";
echo "*** The following errors occured: \n";
echo $errorstring."\n";
}
exit($errors);
/* End of file install.php */