Repository navigation
Expand file tree
/
Copy pathfn.php
More file actions
190 lines (170 loc) · 4.65 KB
/
Copy pathfn.php
File metadata and controls
190 lines (170 loc) · 4.65 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
<?php
error_reporting(E_ALL ^ E_NOTICE);
$STATUS = array(
"APPROVAL" => array(
"stat" => "needs approval",
"button" => "Approve",
"title" => "Awaiting admin approval",
"css" => "app",
"abbr" => "Aprv",
),
"NEW" => array(
"stat" => "new",
"button" => "New",
"title" => "New server",
"css" => "new",
"abbr" => "New",
),
"UPDATED" => array(
"stat" => "updated",
"button" => "Updated",
"title" => "Changes have been made",
"css" => "updt",
"abbr" => "Updt",
),
"UPDT" => array( // Not a status, only used for buttons
"title" => "New or updated",
"abbr" => "Chg",
),
"PASS" => array(
"stat" => "normal",
"button" => "Pass",
"title" => "Passing",
"css" => "norm",
"abbr" => "Ok",
),
"FAIL" => array(
"stat" => "temp outage",
"button" => "Failed",
"title" => "Failed testing",
"css" => "fail",
"abbr" => "Fail",
),
"DOWN" => array(
"stat" => "down",
"button" => "Down",
"title" => "Server not responding",
"css" => "dwn",
"abbr" => "Down",
),
"OFFLINE" => array(
"stat" => "offline",
"button" => "Offline",
"title" => "Extended failure",
"css" => "off",
"abbr" => "Offln",
),
"ERR" => array( // Not a status, only used for buttons
"title" => "Errors detected",
"abbr" => "Err",
),
"DISABLED" => array(
"stat" => "disabled",
"button" => "Disabled",
"title" => "Temporarily shut down",
"css" => "dis",
"abbr" => "Dis",
),
"PENDING" => array(
"stat" => "pending deletion",
"button" => "Remove",
"title" => "Pending removal",
"css" => "rem",
"abbr" => "Rm",
),
"DELETED" => array(
"stat" => "deleted",
"button" => "Deleted",
"title" => "No longer listed",
"css" => "del",
"abbr" => "X",
),
);
/********** FUNCTIONS **********/
function logger($txt) {
global $logfile;
$ts = date("M d H:i:s");
$tld = ($TLD) ? "$TLD: " : "";
$txt = trim($txt, "\n") . "\n";
if ($txt) {
$fh = fopen($logfile, "a");
if (! $usr = $_SESSION['user']) $usr = $_SERVER['REMOTE_ADDR'];
fwrite($fh, "$ts [$usr] $txt");
fclose($fh);
}
}
function get_client_ip() {
$ipaddress = '';
if ($_SERVER['HTTP_CLIENT_IP'])
$ipaddress = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if($_SERVER['HTTP_X_FORWARDED'])
$ipaddress = $_SERVER['HTTP_X_FORWARDED'];
else if($_SERVER['HTTP_FORWARDED_FOR'])
$ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
else if($_SERVER['HTTP_FORWARDED'])
$ipaddress = $_SERVER['HTTP_FORWARDED'];
else if($_SERVER['REMOTE_ADDR'])
$ipaddress = $_SERVER['REMOTE_ADDR'];
else
$ipaddress = 'UNKNOWN';
return $ipaddress;
}
function getNS($region, $country, $tier=2) {
// Get the first available NS number for a given region/country
global $LDAP;
$dn = "o=servers,".$LDAP['base'];
$server_name = trim("$region.$country", ".");
//echo "$server_name\n";
if ($tier == 1) $filter = "(opennicserverrole=tier1)";
if ($tier == 2)
$filter = "(&(dc=*.$server_name.dns.opennic.glue)(opennicserverrole=tier2))";
$attr = array("dc");
$ldapbind = ldap_bind($LDAP['conn'], $LDAP['admin_dn'], $LDAP['admin_pass']);
$query = @ldap_search($LDAP['conn'], $dn, $filter, $attr);
$res = @ldap_get_entries($LDAP['conn'], $query);
//echo "<pre>"; print_r($res); die;
//echo "<pre>";
$lastNS = 0;
foreach((array)$res as $arr) {
if ($dc = $arr['dc'][0]) {
if ($tier == 1)
preg_match("/^ns([0-9]{1,3})(\.opennic.glue)/i", $dc, $match);
if ($tier == 2)
preg_match("/^ns([0-9]{1,3})(\.$server_name)/i", $dc, $match);
// echo "$dc($tier): <pre>"; print_r($match); echo "</pre>";
if (($match[2]) && ($match[1] > $lastNS)) $lastNS = $match[1];
}
}
$lastNS++;
$server_name = "ns$lastNS.$server_name";
return "ns$lastNS";
}
function diffdate($tm1, $tm2=0) {
if (! $tm2) $tm2 = time();
if (! $tm1) return array();
$diff = intval(abs($tm2 - $tm1) / 60); // difference in minutes
$dt['time1'] = $tm1;
$dt['time2'] = $tm2;
$dt['diff'] = $diff;
$dt['totalhours'] = intval($diff / 60);
$dt['totaldays'] = intval($diff / 1440);
$weeks = intval($diff / 10080); $diff -= $weeks * 10080;
$days = intval($diff / 1440); $diff -= $days * 1440;
$hours = intval($diff / 60); $diff -= $hours * 60;
$dt['weeks'] = $weeks;
$dt['days'] = $days;
$dt['hours'] = $hours;
$dt['minutes'] = $diff;
if ($weeks) $str .= "$weeks week".S($weeks).", ";
if ($days) $str .= "$days day".S($days).", ";
if (($hours) && (! $weeks)) $str .= "$hours hour".S($hours).", ";
if (! $str) $str = "$diff minute".S($diff);
$dt['string'] = trim($str, ", ");
return $dt;
}
function S($num) {
if ($num == 1) return "";
else return "s";
}