-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcampusnet.php
executable file
·160 lines (129 loc) · 4.51 KB
/
campusnet.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
<?php
/***************************************************************************\
This file is part of RoomAllocation.
RoomAllocation is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
RoomAllocation is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with RoomAllocation. If not, see <http://www.gnu.org/licenses/>.
\***************************************************************************/
?>
<?php
$campusnetLogin = "https://campusnet.jacobs-university.de/scripts/mgrqispi.dll";
function fullHeaders($referer) {
$headers = array(
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Accept-Encoding: gzip,deflate,sdch',
'Accept-Language: en-US,en;q=0.8',
'Cache-Control: max-age=0',
'Connection: keep-alive',
'Content-Type: application/x-www-form-urlencoded',
'Host: campusnet.jacobs-university.de',
'Referer: ' . $referer,
'Origin: https://campusnet.jacobs-university.de',
'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.1 (KHTML, like Gecko) Ubuntu/10.04 Chromium/14.0.835.202 Chrome/14.0.835.202 Safari/535.1',
);
return $headers;
}
function buildLink($base, $next) {
$baseurl = parse_url($base);
$result = $baseurl['scheme'] . '://' . $baseurl['host'] . $next;
return $result;
}
function parseResult($result) {
$url = null;
if (FALSE !== strpos($result, "HTTP/1.1 200 OK")) {
$rows = explode("\n", $result);
foreach ($rows as $row) {
$i = strpos($row, "URL");
if (FALSE !== $i) {
$url = substr($row, $i + 4);
break;
}
}
$url = trim($url);
if (strlen($url) >= 1 && $url[strlen($url) - 1] == ',') {
$url = substr($url, 0, strlen($url) - 1);
}
return $url;
} else {
return null;
}
}
function curlGet($page, $referer) {
$headers = fullHeaders($referer);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
function curlLoginPost($page, $referer, $args) {
$headers = fullHeaders($referer);
$fields = array(
'usrname' => $args['username'],
'pass' => $args['password'],
'APPNAME' => 'CampusNet',
'PRGNAME' => 'LOGINCHECK',
'ARGUMENTS' => urlencode('clino,usrname,pass,menuno,persno,browser,platform'),
'clino' => '000000000000001',
'menuno' => '000084',
'persno' => '00000000',
'browser' => '',
'platform' => '',
);
$fields_string = '';
foreach ($fields as $k => $v) {
$fields_string .= $k . '=' . $v . '&';
}
rtrim($fields_string, '&');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $page);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
/**
* Logs in to campusnet.
* @param $username the username
* @param $password the password
*/
function loginToCampusNet($username, $password) {
global $campusnetLogin;
$loginReferer = 'https://campusnet.jacobs-university.de/scripts/mgrqispi.dll?APPNAME=CampusNet&PRGNAME=ACTION&ARGUMENTS=-AH9.b5I.TrNDJ4TPD-1D8o4W9Dre9NnYpgktbwHUOEhxBbdGHojwHQGU52k6w39VDryBxwsL.cgqyOTahLUBgl2DsFAtze8d7sfSj371m4iUzGAckQzY-vQHS7vy=';
$credentials = array(
"username" => $username,
"password" => $password,
);
$result = curlLoginPost($campusnetLogin, $loginReferer, $credentials);
$nextpage = parseResult($result);
if (!is_null($nextpage)) {
$login = buildLink($campusnetLogin, $nextpage);
} else {
return null;
}
$result = curlGet($login, $campusnetLogin);
$nextpage = parseResult($result);
if (!is_null($nextpage)) {
$frontpage = buildLink($login, $nextpage);
} else {
return null;
}
$homepage = curlGet($frontpage, $login);
return $homepage;
}
?>