forked from brittohalloran/notestack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sn.php
92 lines (86 loc) · 2.72 KB
/
sn.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
<?php
include("version.php");
$action = $_POST['action'];
$email = $_POST['email'];
$pass = $_POST['password'];
$token = $_POST['token'];
$mark = $_POST['mark'];
$since = $_POST['since'];
$length = $_POST['length'];
$notekey = $_POST['notekey'];
$notebody = $_POST['notebody'];
$noteversion = $_POST['noteversion'];
function default_curl_settings(){
global $handle;
curl_setopt($handle, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handle, CURLOPT_HTTPHEADER, array("User-Agent: Notestack/".$version));
curl_setopt($handle, CURLOPT_HEADER, false);
};
if($action=='login'){
$data = base64_encode('email='.$email.'&password='.$pass); // encode data as base64
$url = 'https://simple-note.appspot.com/api/login'; // set URL
$handle = curl_init($url); // initiate CURL
curl_setopt($handle, CURLOPT_POST, true); // set as POST request
curl_setopt($handle, CURLOPT_POSTFIELDS, $data); // set POST data as encoded username/password
default_curl_settings();
$token = curl_exec($handle); // execute POST request, return $token
echo '{ "token": "'.$token.'" }'; // return data
exit();
}
elseif($action=='index'){
$data = 'email='.$email.'&auth='.$token.'&mark='.$mark.'&since='.$since.'&length='.$length;
$url = 'http://simple-note.appspot.com/api2/index?'.$data;
$handle = curl_init($url); // initiate CURL
default_curl_settings();
$index = curl_exec($handle);
$http_status = curl_getinfo($handle, CURLINFO_HTTP_CODE);
if($http_status=='401'){
echo '401';
}
else{
echo $index;
};
exit();
}
elseif($action=='tagIndex'){
$data = 'email='.$email.'&auth='.$token;
$url = 'http://simple-note.appspot.com/api2/tags?'.$data;
$handle = curl_init($url); // initiate CURL
default_curl_settings();
$index = curl_exec($handle);
echo $index;
exit();
}
elseif($action=='note'){
$data = '/'.$notekey.'?email='.$email.'&auth='.$token;
$url = 'http://simple-note.appspot.com/api2/data'.$data;
$handle = curl_init($url); // initiate CURL
default_curl_settings();
$note = curl_exec($handle);
echo $note;
exit();
}
elseif($action=='noteversion'){
$data = '/'.$notekey.'/'.$noteversion.'?email='.$email.'&auth='.$token;
$url = 'http://simple-note.appspot.com/api2/data'.$data;
$handle = curl_init($url); // initiate CURL
default_curl_settings();
$note = curl_exec($handle);
echo $note;
exit();
}
elseif($action=='sendnote'){
if($notekey!=""){
$data = '/'.$notekey;
};
$data = $data.'?email='.$email.'&auth='.$token;
$url = 'http://simple-note.appspot.com/api2/data'.$data;
$handle = curl_init($url); // initiate CURL
curl_setopt($handle, CURLOPT_POST, true); // set as POST request
curl_setopt($handle, CURLOPT_POSTFIELDS, $notebody);
default_curl_settings();
$note = curl_exec($handle); // execute POST request, return $token
echo $note;
exit();
};
?>