-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathjson.php
More file actions
executable file
·95 lines (88 loc) · 2.5 KB
/
json.php
File metadata and controls
executable file
·95 lines (88 loc) · 2.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
<?php
include 'config.php';
header("Content-type: application/json");
error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
ini_set('display_errors',1);
//Get Data
$data = file_get_contents('php://input');
if (!file_exists($storage)) {
mkdir($storage, 0777, true);
}
//Check for data
if(isset($data)) {
$contents = json_decode(str_replace(",,",",",$data),true);
if(!is_array($contents)) {error();die();}
if(!array_key_exists('SMSDirectoryData', $contents)) {error();die();}
if(!array_key_exists('instanceID', $contents['SMSDirectoryData'])) {error();die();}
if($contents['SMSDirectoryData']['instanceID']!=$authentication){error();die();}
//create a random string to avoid duplicate files being created.
$randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 10);
//Write xml file
$file = fopen($storage.time().$randomString.".json", "w") or die("Unable to open file!");
fwrite($file, $data);
fclose($file);
//Generate Response
$string = <<<JSON
{"SMSDirectoryData": {
"error": 0,
"result": "OK",
"service": "ADSync",
"version": 1.1,
"status": "Ready",
"options": {
"ics": false,
"students": {
"details": true,
"passwords": true,
"photos": false,
"groups": true,
"timetables": false,
"attendance": false,
"assessments": false,
"awards": false,
"pastoral": false,
"learningsupport": false,
"fields": {
"required": "uniqueid;firstname;lastname;email;username;password;yearlevel;startingdate;leavingdate;networkaccess"
}
},
"staff": {
"details": true,
"passwords": true,
"photos": false,
"timetables": false,
"fields": {
"required": "uniqueid;firstname;lastname;email;username;password"
}
},
"common": {
"subjects": false,
"notices": false,
"calendar": false,
"bookings": false
}
}
}
}
JSON;
//Display Response
echo $string;
} else {
error();
}
function error() {
//Generate Response
$string = <<<JSON
{"SMSDirectoryData": {
"error": 401,
"result": "Unauthorised",
"service": "ADSync",
"version": 1.0,
"status": "Ready"
}
}
JSON;
echo $string;
}
?>