[go: up one dir, main page]

Menu

[r2]: / www / submit.php  Maximize  Restore  History

Download this file

250 lines (245 with data), 8.3 kB

  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
<?
/*
VMLMAT: VM Linux Management and Archival Tool.
Copyright (c) 2007, Ronnie Michael, BMC Software Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of the BMC Software Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* if they bookmark this throw them out if not already validated through auth.php */
#get session variable
session_start();
$user=$_SESSION['user'];
if (empty($user)) {
#issue error message
$_SESSION['errmsg']="autherr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
$umail=$_SESSION['umail'];
#if not cancel then proceed
if (isset($_REQUEST['cancel'])) {
#issue error message
$_SESSION['errmsg']="cancel";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#
# get parmfile variables needed
include '/var/clone/bkinc.php';
#
$email = $_REQUEST['email'] ;
if (empty($email)) {
#issue error message
$_SESSION['errmsg']="error";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#make sure they didn't put a white space the variable
$test=explode(" ",$email);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serror";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
# request codes 0 for restore, 1 for backup
# would be empty if from machine forms so assume up until otherwise tested
if (isset($_REQUEST['req'])) {
$reqc = $_REQUEST['req'] ;
}
else {
$reqc = "3";
}
#if called from machine forms then set request number
if (isset($_REQUEST['up'])) {$reqc = "3";}
if (isset($_REQUEST['down'])) {$reqc = "2";}
# check valid up code
if (isset($_REQUEST['upc'])) {
$upc = strtoupper($_REQUEST['upc']) ;
}
else {
$upc = "Y";
}
if (($upc != "Y") && ($upc != "N")) {
#issue error message
$_SESSION['errmsg']="uperror";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
# if no bring up code then set to default to bring up hostname
$oip = $_REQUEST['oip'] ;
if (empty($oip)) {$oip = "oip";}
$ohost = $_REQUEST['ohost'] ;
if (empty($ohost)) {$ohost = "ohost";}
#set process flags
if ($upc == "Y") {$flag = "0 0 0 " . $reqc; }
else { $flag = "0 1 0 " . $reqc; }
#obtain listing name if from sbkup.php
$message = $_REQUEST['comment'];
if (empty($message)) {$message = "comment";}
#make sure they didn't put a white space the variable
$test=explode(" ",$message);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serror";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#possible user on sbkup.php to be empty
$ruser = $_REQUEST['userid'] ;
if (empty($ruser)) {
#issue error message
$_SESSION['errmsg']="error";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#make sure they didn't put a white space the variable
$test=explode(" ",$ruser);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serror";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
$ruser=strtoupper($ruser);
#if not specified then set to Nt userid
if ($ruser == "DUMMY") {
$ruser=strtoupper($user);
}
$host = $_REQUEST['hostname'] ;
#make sure they didn't put a white space the variable
$test=explode(" ",$host);
if (!empty($test[1])) {
#issue error message
$_SESSION['errmsg']="serror";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
if ($case == "UPPER") $host = strtoupper($host);
else $host = strtolower($host) ;
#check to see that hostname exists.
$check=file_exists("zmachines/".$host.".php");
if (!$check) {
#issue error message
$_SESSION['errmsg']="snherr";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#
$tar = $_REQUEST['tarfile'] ;
# if doing a backup then force tarname so people can't step on each other
if ($reqc=="1") {
$tar=$host."_".time();
}
# stop the mischevious from wiping out your web/cpy server
$hhost=explode(".",$_SERVER['HTTP_HOST']);
if (strtoupper($host) == $hhost[0]) {
#issue error message
$_SESSION['errmsg']="unauth";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#begin auth check
$auth=false;
$filen = "archive/authfile";
#lets spin until we get file lock
while (file_exists($filen."_lock")) {}
touch($filen."_lock");
$fp = fopen($filen, 'r' );
$file_data = fread( $fp, filesize( $filen ) );
fclose( $fp );
unlink($filen."_lock");
$lines = explode ( "\n", $file_data );
foreach ( $lines as $line ) {
list( $hostn, $owner, $func ) = explode( ':', $line );
if (strtoupper($hostn) == strtoupper($host) && strtoupper($owner) == strtoupper($user)) {
if (strtoupper($func) == "ADMIN" ) $auth=true;
if (strtoupper($func) == "BACKUP" ) $auth=true;
if (strtoupper($func) == "UP" && $reqc == "2" ) $auth=true;
if (strtoupper($func) == "UP" && $reqc == "3" ) $auth=true;
}
if (strtoupper($hostn) == strtoupper($host) && strtoupper($owner) == "*") $auth=true;
if (strtoupper($hostn) == "ZADMIN" && strtoupper($owner) == strtoupper($user)) $auth=true;
if (strtoupper($hostn) == "ZBACKUP" && strtoupper($owner) == strtoupper($user)) $auth=true;
}
if (! $auth) {
#issue error message
$_SESSION['errmsg']="unauth";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#lookup ip
$ip = gethostbyname($host) ;
if (strtoupper($host) == strtoupper($ip)) {
#issue error message
$_SESSION['errmsg']="noip";
session_write_close();
header("Location: http://".$_SERVER['HTTP_HOST']."/errmsg.php");
exit;
}
#
# lets notify if needed
if ($notify == "YES") {
$filen="archive/profile";
#lets spin until we get file lock
while (file_exists($filen."_lock")) {}
touch($filen."_lock");
$fp = fopen($filen, 'r' );
$file_data = fread( $fp, filesize( $filen ) );
fclose( $fp );
unlink($filen."_lock");
$prlines = explode ( "\n", $file_data );
$cnt = count($lines) - 1;
for ( $i=0; $i < $cnt; $i++ ) {
$line=$lines[$i];
if ( $reqc == "0" ) { $msg = "14"; }
if ( $reqc == "1" ) { $msg = "15"; }
if ( $reqc == "2" ) { $msg = "16"; }
if ( $reqc == "3" ) { $msg = "17"; }
list( $hostn, $owner, $func ) = explode( ':', $line );
if (strtoupper($host) == strtoupper($hostn)) {
foreach ( $prlines as $prline ) {
list( $powner, $pomail, $onote ) = explode( ':', $prline );
if (strtoupper($owner) == strtoupper($powner) && strtoupper($onote) == "Y") {
system('/var/clone/bkmail ' . $host . ' ' . $pomail . ' ' . $msg . ' ' . $umail);
}
}
}
}
}
#store timestamp request file to queue
$rfile = "/mnt/request/reqfile." . time();
$fh = fopen($rfile, 'w');
$nl = "\n";
$strdata = $flag . ' ' . $host . ' '. $ip . ' ' . $tar . ' ' . $email . ' ' . $ruser . ' ' . $ohost . ' ' . $oip . ' ' . $message . ' '. $user . $nl;
fwrite($fh, $strdata);
fclose($fh);
#give user confirmation
header("Location: http://".$_SERVER['HTTP_HOST']."/message.php");
?>