-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions.php
126 lines (106 loc) · 2.8 KB
/
functions.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
<?php
function op($html) {
global $authHash;
if($authHash) {
$debugFile = PREFIX_PATH.DEBUG_PATH.$authHash.DEBUG_EXT;
if(file_exists($debugFile)) { $debug = file_get_contents($debugFile); } else { $debug = ""; }
$debug = $debug.NL.$html;
file_put_contents($debugFile, $debug);
}
}
function showfilebytes($bytes) {
return(number_format($bytes,0));
}
function showfilesize($bytes) {
$str = $bytes." B";
if($bytes >= 1024) {
$str = round($bytes / 1024 , 0)." KB";
}
if($bytes >= 1024*1024) {
$str = round($bytes / (1024*1024) , 1)." MB";
}
if($bytes >= 1024*1024*1024) {
$str = round($bytes / (1024*1024*1024) , 2)." GB";
}
if($bytes >= 1024*1024*1024*1024) {
$str = round($bytes / (1024*1024*1024*1024) , 3)." TB";
}
if($bytes >= 1024*1024*1024*1024*1024) {
$str = round($bytes / (1024*1024*1024*1024*1024) , 3)." PB";
}
return($str);
}
function zboxcmd($cmd, $params) {
global $network;
$zboxbinarypath = ZCN_PATH."/";
$zboxbinarycmd = "zbox";
$params = array_merge( array("--config", $network.".yaml", "--wallet", $network."_webserver.json"), $params);
$zcmd = $zboxbinarypath.$zboxbinarycmd." ".$cmd." ".implode(" ", $params);
$arr = array();
$dummy = exec($zcmd, $arr);
$cmdLogFile = PREFIX_PATH.CMDLOG_PATH.CMDLOG_NAME.LOG_EXT;
if(file_exists($cmdLogFile)) { $cmdLog = file_get_contents($cmdLogFile); } else { $cmdLog = ""; }
$cmdLog = "CMD ".$zcmd.NL.$cmdLog;
file_put_contents($cmdLogFile, $cmdLog);
$res = implode(NL,$arr);
if($res == "") {
$res = $dummy;
}
return($res);
}
function getAuth() {
if(isset($_GET['a'])) {
$a = $_GET['a'];
}
else
{
$a = FALSE;
}
return($a);
}
function getHash($h) {
return(md5($h));
}
function checkWallet() {
// CACHE AUTHTICKET BY ITS HASH
global $network;
if(!file_exists(ZCN_PATH.$network."_webserver.json")) {
$dummyRes = zboxcmd("register", array() );
}
return($dummyRes);
}
function getMetaRes($a) {
// CACHE AUTHTICKET BY ITS HASH
$authHash = getHash($a);
$metaFile = PREFIX_PATH.META_PATH.$authHash.HASH_EXT;
if(file_exists($metaFile)) {
$metaRes = file_get_contents($metaFile);
op("GETMETARES ".$a);
}
else
{
$metaRes = zboxcmd("meta", array("--authticket", $a, "--json" ) );
file_put_contents($metaFile, $metaRes);
op("NEWMETARES ".$a);
}
return($metaRes);
}
function getAlloRes($allocationid) {
// CACHE ALLOCATION BY ITS HASH
$alloHash = $allocationid;
if(!is_dir(PREFIX_PATH.ALLO_PATH)) {
mkdir(PREFIX_PATH.ALLO_PATH);
}
$alloFile = PREFIX_PATH.ALLO_PATH.$alloHash.HASH_EXT;
if(file_exists($alloFile)) {
$alloRes = file_get_contents($alloFile);
op("GETALLORES ".$allocationid);
}
else
{
$alloRes = zboxcmd("get", array("--allocation", $allocationid, "--json --silent" ) );
file_put_contents($alloFile, $alloRes);
op("NEWALLORES ".$allocationid);
}
return($alloRes);
}