This repository has been archived by the owner on Oct 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathairos_function.php
130 lines (94 loc) · 3.96 KB
/
airos_function.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
<?php
/*
Written by Jamie Murphy - jamiemurphyit@gmail.com
Released under GNU V3
Expected Input:
$inputarray['requestpage'] = '/brmacs.cgi?brmacs=y';
$inputarray['expectedpage'] = 'http://ipaddress:port/brmacs.cgi?brmacs=y';
$inputarray['loginurl'] = 'http://ipaddress:port/login.cgi';
$inputarray['username'] = 'ubnt';
$inputarray['password'] = 'ubnt';
$inputarray['cookiefile'] = '/location/of/cookies.txt';
$extrapages[0]['page-name'] = 'status';
$extrapages[0]['page-url'] = 'http://ipaddress:port/status.cgi?';
$extrapages[1]['page-name'] = 'stations';
$extrapages[1]['page-url'] = 'http://ipaddress:port/sta.cgi?';
Supports HTTPS and offset ports.
*/
function get_pages_from_ubnt_airos_device($inputarray, $extrapages= ''){
$sessioncreate = curl_init();
curl_setopt($sessioncreate, CURLOPT_URL, $inputarray['loginurl']);
curl_setopt($sessioncreate, CURLOPT_COOKIEFILE, $inputarray['cookiefile']);
curl_setopt($sessioncreate, CURLOPT_COOKIEJAR, $inputarray['cookiefile']);
curl_setopt($sessioncreate, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($sessioncreate, CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($sessioncreate, CURLOPT_TIMEOUT, 3); //timeout in seconds
curl_setopt($sessioncreate, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($sessioncreate, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($sessioncreate, CURLOPT_HTTPHEADER,array("Expect: "));
curl_setopt($sessioncreate, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($sessioncreate, CURLOPT_POST, 1);
$result = curl_exec($sessioncreate);
curl_close($sessioncreate);
$crl = curl_init();
curl_setopt($crl, CURLOPT_URL, $inputarray['loginurl']);
curl_setopt($crl, CURLOPT_COOKIEFILE, $inputarray['cookiefile']);
curl_setopt($crl, CURLOPT_COOKIEJAR, $inputarray['cookiefile']);
curl_setopt($crl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($crl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($crl, CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($crl, CURLOPT_TIMEOUT, 3); //timeout in seconds
curl_setopt($crl, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($crl, CURLOPT_HTTPHEADER,array("Expect: "));
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($crl, CURLOPT_POST, 1);
// This array will hold the field names and values for the post data
$postdata = array(
"username" => $inputarray['username'],
"password" => $inputarray['password'],
"redirect" => $inputarray['loginurl'],
"uri" => $inputarray['requestpage']
);
//Use tamper data or a similar addon to find the post parameters needed, you may need more or less than the example
//Tell curl we're going to send $postdata as the POST data
curl_setopt($crl, CURLOPT_POSTFIELDS, $postdata);
$result = curl_exec($crl);
$headers = curl_getinfo($crl);
curl_close($crl);
if ($headers['url'] == $inputarray['expectedpage']) {
$reply['auth'] = 'true';
$reply['url'] = $headers['url'];
$reply['page'] = $result;
//echo 'loggedin';
} else if ($headers['url'] == $inputarray['loginurl']) {
$reply['auth'] = 'false';
$reply['url'] = $headers['url'];
$reply['page'] = $result;
return $reply;
} else {
$reply['auth'] = 'debug';
$reply['url'] = $headers['url'];
$reply['page'] = $result;
return $reply;
}
if(!empty($extrapages)){
foreach($extrapages as $page){
$cfg = curl_init();
curl_setopt($cfg, CURLOPT_URL, $page['page-url']);
curl_setopt($cfg, CURLOPT_COOKIEFILE, $inputarray['cookiefile']);
curl_setopt($cfg, CURLOPT_COOKIEJAR, $inputarray['cookiefile']);
curl_setopt($cfg, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cfg, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($cfg, CURLOPT_CONNECTTIMEOUT ,3);
curl_setopt($cfg, CURLOPT_TIMEOUT, 3); //timeout in seconds
curl_setopt($cfg, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($cfg, CURLOPT_HTTPHEADER,array("Expect: "));
curl_setopt($cfg, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cfg, CURLOPT_POST, 1);
$pagename = 'page-'.$page['page-name'];
$reply[$pagename] = curl_exec($cfg);
curl_close($cfg);
}
}
return $reply;
}