]>
Commit | Line | Data |
---|---|---|
5ec97892 MR |
1 | <?php |
2 | /* | |
3 | * rest_client.php | |
4 | * | |
5 | * Copyright 2015 Michael Rasmussen <mir@datanom.net> | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | * GNU General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
20 | * MA 02110-1301, USA. | |
21 | */ | |
0541127e | 22 | require_once 'config.php'; |
5ec97892 MR |
23 | require_once $CFG->root . 'lib/utils.inc.php'; |
24 | ||
c49d593f | 25 | session_start(); |
5ec97892 MR |
26 | $util = new Utils; |
27 | ||
89d8e7c2 MR |
28 | $ticket = $cookies = $data = null; |
29 | ||
30 | if (! isset($_SESSION['ticket'])) { | |
31 | $data = 'username=mir@miras.org&password=Clara0503'; | |
32 | $response = $util->RESTCall($CFG->wblistadm_url.'/ticket', $data, $cookiesIn = ''); | |
33 | if ($response['http_code'] >= 200 && $response['http_code'] <= 204) { | |
34 | $_SESSION['ticket'] = json_decode($response['content']); | |
431ebe4e | 35 | $_SESSION['CSRFPreventionToken'] = 'CSRFPreventionToken='.$ticket->data->CSRFPreventionToken; |
89d8e7c2 MR |
36 | $_SESSION['cookies'] = $response['cookies']; |
37 | } | |
38 | } else { | |
605ad9fa | 39 | $response = $util->RESTCall($CFG->wblistadm_url.'/show', $_SESSION['CSRFPreventionToken'], $cookiesIn = $_SESSION['cookies']); |
89d8e7c2 MR |
40 | if ($response['http_code'] >= 200 && $response['http_code'] <= 204) { |
41 | $data = json_decode($response['content']); | |
89d8e7c2 MR |
42 | $_SESSION['cookies'] = $response['cookies']; |
43 | } | |
c49d593f | 44 | } |
5ec97892 MR |
45 | |
46 | ?> | |
47 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | |
48 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | |
49 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
50 | ||
51 | <head> | |
52 | <title>untitled</title> | |
53 | <meta http-equiv="content-type" content="text/html;charset=utf-8" /> | |
54 | <meta name="generator" content="Geany 1.24.1" /> | |
55 | </head> | |
56 | ||
57 | <body> | |
c49d593f MR |
58 | <pre> |
59 | <?php | |
60 | print_r($response); | |
89d8e7c2 MR |
61 | print "Ticket: \n".var_export($_SESSION['ticket'],true)."\nCookies: ".$_SESSION['cookies']."\nToken: ".$_SESSION['CSRFPreventionToken']; |
62 | if (isset($data)) { | |
63 | print "\n"; | |
64 | print_r($data); | |
65 | } | |
c49d593f MR |
66 | ?> |
67 | </pre> | |
5ec97892 MR |
68 | </body> |
69 | ||
70 | </html> |