forked from Encrypt-S/navpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.php
executable file
·257 lines (220 loc) · 7.52 KB
/
header.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
<?php
#ini_set("display_errors", false);
require("libs/config.php");
require("jsonRPCClient.php");
require("printarray.php");
require("/home/stakebox/UI/currency.php");
# include("/home/stakebox/UI/email.php");
include("diskusage.php");
//hard set currency to usd
$currency='usd';
$longCurrency='US Dollar';
$symbol='$';
session_start();
if (isset($_GET['currentWallet']) && !empty($_GET['currentWallet']))
$_SESSION['currentWallet'] = $_GET['currentWallet'];
if (isset($_SESSION['currentWallet']) && !empty($_SESSION['currentWallet']))
$currentWallet = $_SESSION['currentWallet'];
else {
$keys = array_keys($wallets);
$currentWallet = $keys[0];
$_SESSION['currentWallet'] = $currentWallet;
}
$coinu = $wallets[$currentWallet];
$coin = new jsonRPCClient("{$coinu['protocol']}://{$coinu['user']}:{$coinu['pass']}@{$coinu['host']}:{$coinu['port']}", true);
$ticker = $coinu['ticker'];
$pair = "$ticker"."-btc";
// fetch price in BTC price of current coin
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.coinmarketcap.com/v1/ticker/nav-coin/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData = curl_exec($curl);
$data = json_decode($rawData);
$priceBtc = $data[0]->price_btc;
$priceUsd = $data[0]->price_usd;
// echo "<pre>";
// print_r($data);
// echo "</pre>";
//
// echo "<pre>";
// print_r($data[0]);
// echo "</pre>";
//
// echo "<pre>";
// print_r([$priceBtc, $priceUsd]);
// echo "</pre>";
/*
// fetch fiat value of BTC
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://api.cryptocoincharts.info/tradingPair/btc_".$currency);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData1 = curl_exec($curl);
curl_close($curl);
$data1 = json_decode($rawData1);
$fiatBTC = $data1->price;
$lastRunLog = '/home/stakebox/UI/lastrun';
$versionLocation = '/home/stakebox/UI/version.php';
if(!file_exists("$lastRunLog")){
$file = fopen("$lastRunLog","w");
fwrite($file,"");
fclose($file);
}
if(!file_exists("$versionLocation")){
$file = fopen("$versionLocation","w");
fwrite($file,"");
fclose($file);
}
if (file_exists($lastRunLog)) {
$lastRun = file_get_contents($lastRunLog);
if (time() - $lastRun >= 86400) {
// fetch github info
$curl = curl_init();
curl_setopt($curl, CURLOPT_HTTPHEADER,array('User-Agent: StakeBox'));
curl_setopt($curl, CURLOPT_URL, "https://api.github.com/repos/stakebox/webui/tags");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$rawData2 = curl_exec($curl);
curl_close($curl);
$data2 = json_decode($rawData2);
$current = $data2[0]->name;
//update lastrun.log with current time
file_put_contents($lastRunLog, time());
//update version.php with current version
$fp = fopen($versionLocation, "w");
fwrite($fp, "<?php\n\$newestVersion='$current';\n?>");
fclose($fp);
}
}
*/
$lockStateLocation = "/home/stakebox/UI/".$currentWallet."lockstate.php";
function changeLockState(){
global $lockStateLocation;
global $newLockState;
if(!file_exists("$lockStateLocation")){
$file = fopen("$lockStateLocation","w");
fwrite($file,"");
fclose($file);
}
if (is_readable($lockStateLocation) == FALSE)
die ("The lock state file must be writable.") ;
// Open the file and erase the contents if any
$fp = fopen($lockStateLocation, "w");
// Write the data to the file
// CODE INJECTION WARNING!
fwrite($fp, "<?php\n\$lockState='$newLockState';\n?>");
// Close the file
fclose($fp);
}
include("/home/stakebox/UI/version.php");
include("/home/stakebox/UI/primary".$currentWallet."address.php");
try {
$coinGetInfo = $coin->getinfo();
} catch(Exception $e) {
$newLockState = "Locked";
changeLockState();
$coinGetInfo = false;
}
if($coinGetInfo) {
if (!isset($coinGetInfo['unlocked_until'])) {
$lockState = "Not Encrypted";
$newLockState = "Not Encrypted";
changeLockState();
}
if ($coinGetInfo['unlocked_until'] && (int) $coinGetInfo['unlocked_until'] > 0) {
$address = $coin->getaddressesbyaccount("")[0];
try {
$signed = $coin->signmessage($address, "test message");
$newLockState = "Unlocked For Sending";
changeLockState();
} catch (Exception $e) {
$newLockState = "Unlocked For Staking";
changeLockState();
}
}
if ($coinGetInfo['unlocked_until'] && (int) $coinGetInfo['unlocked_until'] === 0) {
$newLockState = "Locked";
changeLockState();
}
}
include("/home/stakebox/UI/".$currentWallet."lockstate.php");
?>
<html><head><title><?php echo $price; echo " BTC/"; echo $ticker;?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href='css/slate.css' rel='stylesheet' >
<link href="css/main.css" rel="stylesheet" >
<link rel="icon" type="image/png" href="favicon.png">
<script src='libs/jquery.js'></script>
<script src='libs/bootstrap.js'></script>
<script>
$(function(){
$('#selectwallet a').click(function(){
window.location.href="./?currentWallet="+$(this).text();
return false;
});
});
var pair = <?php echo json_encode($pair); ?>;
var ticker = <?php echo json_encode($ticker); ?>;
var data_from_ajax;
var refreshRate=setInterval(function(){fetchPrice()},180000);
function fetchPrice() {
$.get('price.php?pair='+pair, function(data) {
data_from_ajax = data;
document.title = data_from_ajax+" BTC/"+ticker;
document.getElementById("price").innerHTML = data_from_ajax;
});
}
</script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top navbar-custom" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="./"><img src="navcoin-logo.png" height="100%"></a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="last20transactions">Transactions</a></li>
<li><a href="sendcoins">Send Coins</a></li>
<li><a href="control">Control</a></li>
<li><a href="help">Help</a></li>
</ul>
<div class="navbar-right">
<p class="navbar-text"><?php echo "Current price is <b id='price'>{$priceBtc}</b> BTC"; ?></p>
<!--
<p class="navbar-text">Select Wallet:</p>
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><?php echo $currentWallet;?> <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu" id="selectwallet">
<?php
foreach ($wallets as $walletName => $walletData)
echo '<li><a href="#">'.$walletName.'</a></li>';
?>
</ul>
</li>
</ul>
-->
</div>
</div>
</div>
</nav>
<div class="container-fluid">
<div class='content'>
<div class="well">
<?php
try {
$coininfo = $coin->getinfo();
} catch(exception $e) {
echo "<!-- $e -->";
echo "<br><p class='bg-danger'><b>Error: Your wallet server is not running. Please restart your StakeBox via the power option in the server section on the control page. If you have just restarted it, or powered it on, please allow it up to several minutes before attempting to restart it again.</b></p>";
}
if($dp>97){
echo "<br><p class='bg-danger'><b>NOTICE: Your disk is nearing capacity, it is currently ".$dp."% full, with ".$df." free space remaining!</b></p>";
}
?>