Skip to content

Commit 90774c9

Browse files
author
Parag Padsumbiya
committedApr 6, 2021
WIP put identity.php and identitylib.php in public file
1 parent 7b67a72 commit 90774c9

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed
 

‎qpkg.cfg

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Name of the packaged application.
2-
QPKG_NAME="STORJ_LUMEN"
2+
QPKG_NAME="STORJ"
33
# Name of the display application.
44
QPKG_DISPLAY_NAME="Storj Storage Node"
55
# Version of the packaged application.
6-
QPKG_VER="0.0.1"
6+
QPKG_VER="1.1.2"
77
# Author or maintainer of the package
88
QPKG_AUTHOR="Utropicmedia"
99
# License for the packaged application
@@ -29,7 +29,7 @@ QPKG_REQUIRE="container-station >= 1.7.2041"
2929
# Location of file with running service's PID
3030
#QPKG_SERVICE_PIDFILE=""
3131
# Relative path to web interface
32-
QPKG_WEBUI="/STORJ_LUMEN/"
32+
QPKG_WEBUI="/STORJ/"
3333
# Port number for the web interface.
3434
#QPKG_WEB_PORT=""
3535
# Port number for the SSL web interface.

‎shared/STORJ.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
#!/bin/sh
22
CONF=/etc/config/qpkg.conf
3-
QPKG_NAME="STORJ_LUMEN"
3+
QPKG_NAME="STORJ"
44
LOGFILE=/var/log/${QPKG_NAME}
55
QPKG_ROOT=`/sbin/getcfg $QPKG_NAME Install_Path -f ${CONF}`
66
APACHE_ROOT=`/sbin/getcfg SHARE_DEF defWeb -d Qweb -f /etc/config/def_share.info`
77
export QNAP_QPKG=$QPKG_NAME
88

99
case "$1" in
1010
start)
11-
echo `date` " STORJ_LUMEN : Request to start ($@) " >> $LOGFILE
11+
echo `date` " STORJ : Request to start ($@) " >> $LOGFILE
1212
ENABLED=$(/sbin/getcfg $QPKG_NAME Enable -u -d FALSE -f $CONF)
1313
if [ "$ENABLED" != "TRUE" ]; then
1414
echo "$QPKG_NAME is disabled."
15-
echo `date` " STORJ_LUMEN : $PKG_NAME is disabled " >> $LOGFILE
15+
echo `date` " STORJ : $PKG_NAME is disabled " >> $LOGFILE
1616
exit 1
1717
fi
1818
: ADD START ACTIONS HERE
1919
echo `date` "Create $QPKG_ROOT/web/public folder link to STORJ folder " >> /tmp/runSTORJ.log
20-
ln -s $QPKG_ROOT/web/public /home/Qhttpd/Web/STORJ_LUMEN
21-
echo `date` " STORJ_LUMEN : Request to start ($@) completed " >> $LOGFILE
20+
ln -s $QPKG_ROOT/web/public /home/Qhttpd/Web/STORJ
21+
echo `date` " STORJ : Request to start ($@) completed " >> $LOGFILE
2222
;;
2323

2424
stop)
25-
echo `date` " STORJ_LUMEN : Request to stop ($@) " >> $LOGFILE
25+
echo `date` " STORJ : Request to stop ($@) " >> $LOGFILE
2626
: ADD STOP ACTIONS HERE
27-
rm /home/Qhttpd/Web/STORJ_LUMEN
27+
rm /home/Qhttpd/Web/STORJ
2828
;;
2929

3030
restart)
31-
echo `date` " STORJ_LUMEN : Request restart ($@) " >> $LOGFILE
31+
echo `date` " STORJ : Request restart ($@) " >> $LOGFILE
3232
$0 stop
3333
$0 start
3434
;;
3535

3636
*)
37-
echo `date` " STORJ_LUMEN : Request UNKNOWN ($@) " >> $LOGFILE
37+
echo `date` " STORJ : Request UNKNOWN ($@) " >> $LOGFILE
3838
echo "Usage: $0 {start|stop|restart}"
3939
exit 1
4040
esac

‎shared/web/app/Helpers/IdentityHelper.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function killIdentityProcess($identityPidFile) {
4444
public function checkIdentityFileExistence($data) {
4545
// Checking file if exist or not.
4646
$identityFilePath = $data["Identity"] . "/storagenode/identity.key";
47-
if (validateExistence($data)) {
47+
if ($this->validateExistence($data)) {
4848
$this->logMessage("(file_exist) File $identityFilePath and others already exist !");
4949
echo "0"; # NORMAL
5050
} else {
@@ -109,13 +109,13 @@ public function storeConfig($data, $filePath) {
109109
}
110110

111111
public function updateConfig($dataNew, $filePath) {
112-
$data = loadConfig($filePath);
112+
$data = $this->loadConfig($filePath);
113113
$data = array_merge($data, $dataNew);
114114
$this->storeConfig($data, $filePath);
115115
}
116116

117117
public function updateConfigKey($key, $value, $filePath) {
118-
$data = loadConfig($filePath);
118+
$data = $this->loadConfig($filePath);
119119
$data[$key] = $value;
120120
$this->storeConfig($data, $filePath);
121121
}

‎shared/web/app/Http/Controllers/IdentityController.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,17 @@ public function __construct(IdentityHelper $identityHelper) {
2323
*
2424
*/
2525
public function index(Request $request) {
26-
// Set variables
26+
27+
$platformBase = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT');
28+
$moduleBase = $platformBase . dirname(filter_input(INPUT_SERVER, 'PHP_SELF'));
2729
$configBase = env('CONFIG_DIR', "/share/Public/storagenode.conf");
28-
$scriptsBase = base_path('public/scripts');
30+
$scriptsBase = $moduleBase . '/scripts';
2931
$identityGenBinary = env('IDENTITY_GEN_BINARY', "/share/Public/identity.bin/identity");
3032
$logFile = env('IDENTITY_LOG', "share/Public/identity/logs/storj_identity.log");
3133

32-
3334
$data = $this->identityHelper->loadConfig("${configBase}/config.json");
34-
// Update config json file if updates provided
35-
$inputs = $request->all();
35+
# Update config json file if updates provided
36+
$inputs = $this->identityHelper->loadConfig("php://input");
3637
if (isset($inputs['authkey']) || isset($inputs['identity'])) {
3738
// Saving Identity Path and Auth Key in JSON file.
3839
if (isset($inputs["authkey"])) {
@@ -41,22 +42,22 @@ public function index(Request $request) {
4142
if (isset($inputs["identity"])) {
4243
$data['Identity'] = $inputs["identity"];
4344
}
44-
$this->identityHelper->storeConfig($data, "${configBase}/config.json");
45+
$this->identityHelper->storeConfig($data, "config.json");
4546
}
4647

4748
$identityGenScriptPath = $scriptsBase . DIRECTORY_SEPARATOR . 'generateIdentity.sh';
4849
$Path = $data["Identity"] . "/storagenode";
4950
$identityFilePath = "${Path}/identity.key";
50-
$urlToFetch = env('IDENTITY_URL', "https://github.com/storj/storj/releases/latest/download/identity_linux_amd64.zip");
51-
$identitypidFile = url('identity.pid');
52-
51+
$urlToFetch = "https://github.com/storj/storj/releases/latest/download/identity_linux_amd64.zip";
52+
$identitypidFile = $moduleBase . DIRECTORY_SEPARATOR . 'identity.pid';
5353

54+
# ------------------------------------------------------------------------
5455

5556
$date = Date('Y-m-d H:i:s');
5657
$output = "";
57-
$configFile = "${configBase}/config.json";
58+
$configFile = "config.json";
5859

59-
$inputs = $request->all();
60+
$inputs = $this->identityHelper->loadConfig("php://input");
6061

6162

6263
$this->identityHelper->logMessage("================== identity.php invoked ================== ");
@@ -112,12 +113,12 @@ public function index(Request $request) {
112113

113114
$this->identityHelper->logMessage("Invoked identity generation program ($identityGenScriptPath) ");
114115
echo $lastline;
115-
} else if (isset($inputs['status'])) {
116+
} else if (filter_input(INPUT_POST, 'status') || isset($inputs['status'])) {
116117
$this->identityHelper->logMessage("Identity php called for fetching STATUS!");
117-
$data['LogFilePath'] = $logFile;
118-
$data['idGenStartTime'] = $date;
118+
119119
$file = $data['LogFilePath'];
120-
$pid = file_get_contents("identity.pid");
120+
121+
$pid = file_get_contents($identitypidFile);
121122
$prgStartTime = $data['idGenStartTime'];
122123
$file = escapeshellarg($file);
123124
$lastline = `tail -c160 $file | sed -e 's#\\r#\\n#g' | tail -1 `;
@@ -131,11 +132,10 @@ public function index(Request $request) {
131132
$this->identityHelper->logMessage("identity available at ${identityFilePath}");
132133
echo "identity available at ${identityFilePath}";
133134
} else {
134-
$data = $this->identityHelper->loadConfig($configFile);
135-
$data['idGenStartTime'] = $date;
135+
$data = $this->identityHelper->loadConfig("/share/Public/storagenode.conf/config.json");
136136
$lastline = preg_replace('/\n$/', '', $lastline);
137137
$this->identityHelper->logMessage("STATUS: Identity generation in progress (LOG: $lastline)");
138-
echo "Identity generation STATUS($date):<BR> " .
138+
echo "Identity generation STATUS a($date):<BR> " .
139139
"Process ID: $pid , " .
140140
"Started at: " . $data['idGenStartTime'] . "<BR>" . $lastline;
141141
?><div style="text-align: center"><img src="img/spinner.gif"></div><?php

‎shared/web/public/js/config.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jQuery(function () {
105105
success: (result) => {
106106
var str1 = result;
107107
var str2 = "identity available";
108-
if(str1.indexOf(str2) != -1) {
108+
if (result === "identity available at /root/.local/share/storj/identity") {
109109
$("#identity_status").html("<b>" + result + "</b>");
110110
identitydataval = 1;
111111
} else {
@@ -168,6 +168,8 @@ jQuery(function () {
168168
createVal = 1;
169169
} else {
170170
$("#identity_status").html("Identity files exist.");
171+
$("#create_identity").attr("disabled", true);
172+
$("#create_identity").css("cursor", "not-allowed");
171173
createVal = 0;
172174
}
173175
},
@@ -183,8 +185,7 @@ jQuery(function () {
183185
} else {
184186
readidentitystatus();
185187

186-
$("#create_identity").attr("disabled", true);
187-
$("#create_identity").css("cursor", "not-allowed");
188+
188189
$("#stop_identity").removeAttr("disabled");
189190
$("#stop_identity").css("cursor", "pointer");
190191
}

0 commit comments

Comments
 (0)
Please sign in to comment.