-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.php
More file actions
317 lines (232 loc) · 10.5 KB
/
index.php
File metadata and controls
317 lines (232 loc) · 10.5 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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
session_start();
require 'libs/bombay/glue/glue.lib.php';
require 'libs/security.lib.php';
if (is_equal('http', URI_SCHEME)) exit_with_302_plain(secure_absolute_uri('/'));
handle_get('/', function ($req, $pipeline)
{
if (isset($_SESSION['global_salt']) and isset($_SESSION['rid']) and isset($_COOKIE['data']))
{
$_SESSION['authenticated'] = true;
}
else $_SESSION['authenticated'] = false;
return next_func($req, $pipeline);
}, afunc_returning(array('template'=>'home')));
function auth_filter($req, $pipeline)
{
if (isset($_SESSION['authenticated']) and is_equal($_SESSION['authenticated'], true))
{
return next_func($req, $pipeline);
}
else return array('template'=>'error', 'error_msg'=>"You don't seem to be logged in. Go back, login and try again.");
}
handle_post(array('/login', 'action'=>'login'), 'oboxapps_login');
function oboxapps_login($req)
{
$rid = $req['form']['rid'];
$password = $req['form']['password'];
$auth_params = "auth-userid=$rid&auth-password=$password";
$request = "https://test.httpapi.com/api/resellers/generate-token.json?$auth_params&ip=1.1.1.1";
$result = @file_get_contents($request);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Login Failed. Go back and try again.');
}
$global_salt = str_random_alphanum(128);
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$encrypted_data = symmetric_encrypt($password, $key);
$_SESSION['authenticated'] = true;
$_SESSION['global_salt'] = $global_salt;
$_SESSION['rid'] = $rid;
setcookie('data', $encrypted_data, time()+60*60, '/', '', true, true);
return _302_plain(absolute_uri('/'));
}
handle_get('/logout', 'oboxapps_logout');
function oboxapps_logout($req)
{
setcookie('data', '', time() - 3600, '/', '', true, true);
$_SESSION['authenticated'] = false;
unset($_SESSION['global_salt']);
unset($_SESSION['rid']);
return _302_plain(absolute_uri('/'));
}
handle_get('/apps/account_balance', 'auth_filter', 'account_balance');
function account_balance($req)
{
$rid = $_SESSION['rid'];
$global_salt = $_SESSION['global_salt'];
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$password = symmetric_decrypt($_COOKIE['data'], $key);
$auth_params = "auth-userid=$rid&auth-password=$password";
$request = "https://test.httpapi.com/api/billing/reseller-balance.json?$auth_params&reseller-id=$rid";
$result = file_get_contents($request);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch account balance. Go back and try again.');
}
return array('result'=>json_decode($result, true));
}
handle_get('/apps/expiring_domains', 'auth_filter', 'expiring_domains');
function expiring_domains($req)
{
$rid = $_SESSION['rid'];
$global_salt = $_SESSION['global_salt'];
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$password = symmetric_decrypt($_COOKIE['data'], $key);
$auth_params = "auth-userid=$rid&auth-password=$password";
$request = "https://test.httpapi.com/api/domains/search.json?$auth_params&no-of-records=10&page-no=1&status=Active&order-by=endtime%20asc";
$result = file_get_contents($request);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch expiring domains. Go back and try again.');
}
return array('result'=>json_decode($result, true));
}
handle_get('/apps/new_domains', 'auth_filter', 'new_domains');
function new_domains($req)
{
$rid = $_SESSION['rid'];
$global_salt = $_SESSION['global_salt'];
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$password = symmetric_decrypt($_COOKIE['data'], $key);
$auth_params = "auth-userid=$rid&auth-password=$password";
$request = "https://test.httpapi.com/api/domains/search.json?$auth_params&no-of-records=10&page-no=1&status=Active&order-by=creationtime%20desc";
$result = file_get_contents($request);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch new domains. Go back and try again.');
}
return array('result'=>json_decode($result, true));
}
handle_get('/apps/domain_details', 'auth_filter', 'domain_details');
function domain_details($req)
{
$rid = $_SESSION['rid'];
$global_salt = $_SESSION['global_salt'];
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$password = symmetric_decrypt($_COOKIE['data'], $key);
if (!isset($req['query']['orderid']))
{
return array('template'=>'error', 'error_msg'=>'No orderid found!');
}
$orderid = $req['query']['orderid'];
$auth_params = "auth-userid=$rid&auth-password=$password";
$request = "https://test.httpapi.com/api/domains/details.json?$auth_params&order-id=$orderid&options=All";
$result = file_get_contents($request);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch domain details. Go back and try again.');
}
$result = json_decode($result, true);
$customerid = $result['customerid'];
$request = "https://test.httpapi.com/api/customers/details-by-id.json?$auth_params&customer-id=$customerid";
$customer_details = file_get_contents($request);
if (is_equal(false, $customer_details))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch customer details. Go back and try again.');
}
$customer_details = json_decode($customer_details, true);
$result['customer_details'] = $customer_details;
return array('result'=>$result);
}
handle_get('/apps/renew_domain', 'auth_filter', afunc_returning(array('template'=>'renew_domain_form')));
handle_post(array('/apps/renew_domain', 'action'=>'renew_domain'), 'renew_domain');
function renew_domain($req)
{
$rid = $_SESSION['rid'];
$global_salt = $_SESSION['global_salt'];
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$password = symmetric_decrypt($_COOKIE['data'], $key);
$auth_params = "auth-userid=$rid&auth-password=$password";
$domain = $req['form']['domain'];
$get_orderid_url = "https://test.httpapi.com/api/domains/orderid.json?$auth_params&domain-name=$domain";
$result = file_get_contents($get_orderid_url);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch Order ID. Go back and try again.');
}
$orderid = $result;
$domain_details_url = "https://test.httpapi.com/api/domains/details.json?$auth_params&order-id=$orderid&options=OrderDetails";
$result = file_get_contents($domain_details_url);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch domain details. Go back and try again.');
}
$result = json_decode($result, true);
$exp_date = $result['endtime'];
$invoice_option = $req['form']['invoice_option'];
$years = $req['form']['years'];
$request = "https://test.httpapi.com/api/domains/renew.json?$auth_params&order-id=$orderid&years=$years&exp-date=$exp_date&invoice-option=$invoice_option";
$result = file_get_contents($request);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not perform action. Go back and try again.');
}
return array('result'=>'Action performed successfully.');
}
handle_get('/apps/gappsconf', 'auth_filter', afunc_returning(array('template'=>'gappsconf_form')));
handle_post(array('/apps/gappsconf', 'action'=>'configure_dns'), 'gappsconf');
function gappsconf($req)
{
/* The following DNS recrods are added:
MX 10 ASPMX.L.GOOGLE.COM
MX 20 ALT1.ASPMX.L.GOOGLE.COM
MX 20 ALT2.ASPMX.L.GOOGLE.COM
MX 30 ASPMX2.GOOGLEMAIL.COM
MX 30 ASPMX3.GOOGLEMAIL.COM
MX 30 ASPMX4.GOOGLEMAIL.COM
MX 30 ASPMX5.GOOGLEMAIL.COM
calendar CNAME ghs.google.com
docs CNAME ghs.google.com
mail CNAME ghs.google.com
sites CNAME ghs.google.com
*/
$domain = $req['form']['domain'];
$rid = $_SESSION['rid'];
$global_salt = $_SESSION['global_salt'];
$user_salt = sha1($rid);
$key = generate_key($user_salt, $global_salt);
$password = symmetric_decrypt($_COOKIE['data'], $key);
$auth_params = "auth-userid=$rid&auth-password=$password";
$get_orderid_url = "https://test.httpapi.com/api/domains/orderid.json?$auth_params&domain-name=$domain";
$result = file_get_contents($get_orderid_url);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>'Could not fetch Order ID. Go back and try again.');
}
$orderid = $result;
$activate_url = "https://test.httpapi.com/api/dns/activate.json?$auth_params";
$add_cname_url = "https://test.httpapi.com/api/dns/manage/add-cname-record.json?$auth_params&domain-name=$domain";
$add_mx_url = "https://test.httpapi.com/api/dns/manage/add-mx-record.json?$auth_params&domain-name=$domain";
$requests[] = array("$activate_url&order-id=$orderid", 'Activating DNS');
$requests[] = array("$add_cname_url&value=ghs.google.com&host=mail", "Adding CNAME for mail.$domain");
$requests[] = array("$add_cname_url&value=ghs.google.com&host=calendar", "Adding CNAME for calendar.$domain");
$requests[] = array("$add_cname_url&value=ghs.google.com&host=docs", "Adding CNAME for docs.$domain");
$requests[] = array("$add_cname_url&value=ghs.google.com&host=sites", "Adding CNAME for sites.$domain");
$requests[] = array("$add_mx_url&value=ASPMX.L.GOOGLE.COM&priority=10", "Adding MX: ASPMX.L.GOOGLE.COM");
$requests[] = array("$add_mx_url&value=ALT1.ASPMX.L.GOOGLE.COM&priority=20", "Adding MX: ALT1.ASPMX.L.GOOGLE.COM");
$requests[] = array("$add_mx_url&value=ALT2.ASPMX.L.GOOGLE.COM&priority=20", "Adding MX: ALT2.ASPMX.L.GOOGLE.COM");
$requests[] = array("$add_mx_url&value=ASPMX2.GOOGLEMAIL.COM&priority=30", "Adding MX: ASPMX2.GOOGLEMAIL.COM");
$requests[] = array("$add_mx_url&value=ASPMX3.GOOGLEMAIL.COM&priority=30", "Adding MX: ASPMX3.GOOGLEMAIL.COM");
$requests[] = array("$add_mx_url&value=ASPMX4.GOOGLEMAIL.COM&priority=30", "Adding MX: ASPMX4.GOOGLEMAIL.COM");
$requests[] = array("$add_mx_url&value=ASPMX5.GOOGLEMAIL.COM&priority=30", "Adding MX: ASPMX5.GOOGLEMAIL.COM");
$results = array();
foreach ($requests as $request)
{
$result = file_get_contents($request[0]);
if (is_equal(false, $result))
{
return array('template'=>'error', 'error_msg'=>"Error while adding {$request[1]}. Go back and try again.");
}
$results[] = array($request[1], json_decode($result, true));
}
return array('results'=>$results);
}
yield_to_glue();
?>