-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnoDb.php
More file actions
116 lines (116 loc) · 2.35 KB
/
noDb.php
File metadata and controls
116 lines (116 loc) · 2.35 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
const NODBROOT = "data/";
const NODBKEY = "noDbIsAwesome!";
const NODBIV = "1234567890123456";
function nodb_table_create($o){
if(!isset($o['table'])){
return false;
}
$table = $o['table'];
if(file_exists(NODBROOT.$table)){
return false;
}
return mkdir(NODBROOT.$table);
}
function nodb_table_get_all(){
if(!file_exists(NODBROOT)){
return false;
}
$all = scandir(NODBROOT);
$all = array_diff($all,['.','..']);
return $all;
}
function nodb_entry_add($o){
if(!isset($o['table'])){
return false;
}
if(!isset($o['name'])){
return false;
}
$table = $o['table'];
$name = $o['name'];
$data = "";
if(isset($o['data'])){
$data = json_encode($o['data']);
}
if(!file_exists(NODBROOT.$table)){
return false;
}
if(file_exists(NODBROOT.$table.'/'.$name)){
return false;
}
$fp = fopen(NODBROOT.$table.'/'.$name,'wb');
fwrite($fp,openssl_encrypt($data,'AES-256-CBC',NODBKEY,0,NODBIV));
fclose($fp);
return true;
}
function nodb_entry_get($o){
if(!isset($o['table'])){
return false;
}
if(!isset($o['name'])){
return false;
}
$table = $o['table'];
$name = $o['name'];
if(!file_exists(NODBROOT.$table)){
return false;
}
if(!file_exists(NODBROOT.$table.'/'.$name)){
return false;
}
$data = json_decode(openssl_decrypt(file_get_contents(NODBROOT.$table.'/'.$name),'AES-256-CBC',NODBKEY,0,NODBIV),true);
return $data;
}
function nodb_entry_remove($o){
if(!isset($o['table'])){
return false;
}
if(!isset($o['name'])){
return false;
}
$table = $o['table'];
$name = $o['name'];
if(!file_exists(NODBROOT.$table)){
return false;
}
if(!file_exists(NODBROOT.$table.'/'.$name)){
return false;
}
$rm = NODBROOT.$table.'/'.$name;
unlink($rm);
return true;
}
function nodb_entry_get_all($o){
if(!isset($o['table'])){
return false;
}
$table = $o['table'];
if(!file_exists(NODBROOT.$table)){
return false;
}
$all = scandir(NODBROOT.$table);
$all = array_diff($all,['.','..']);
return $all;
}
function nodb_entry_update($o){
if(!isset($o['table'])){
return false;
}
if(!isset($o['name'])){
return false;
}
if(!isset($o['data'])){
return false;
}
$table = $o['table'];
$name = $o['name'];
$data = $o['data'];
if(!nodb_entry_remove(['table'=>$table,'name'=>$name]) === true){
return false;
}
if(!nodb_entry_add(['table'=>$table,'name'=>$name,'data'=>$data]) === true){
return false;
}
return true;
}