Skip to content

Commit

Permalink
feat: Complete general template for the webpanel.
Browse files Browse the repository at this point in the history
feat: Add logout functionality.
fix: Update Last Access time on web tokens.
chore: Add copyrights where missing.
  • Loading branch information
Maxwell175 committed May 16, 2018
1 parent d3088b6 commit a12aca3
Show file tree
Hide file tree
Showing 24 changed files with 530 additions and 21 deletions.
8 changes: 8 additions & 0 deletions Common/common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#ifndef COMMON_H
#define COMMON_H

Expand Down
8 changes: 2 additions & 6 deletions SSNFS-client/fuseclient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2017 Maxwell Dreytser
* Copyright 2018 Maxwell Dreytser
*/

#include "fuseclient.h"
Expand Down Expand Up @@ -371,11 +371,7 @@ int FuseClient::initSocket()
if (serverHello.isNull()) {
if (socket->isOpen()) {
socket->close();
if (socket->waitForDisconnected(timeouts / 10) == false) {
retryCounter++;
QThread::currentThread()->sleep(retryDelay);
continue;
}
socket->waitForDisconnected(timeouts / 10);
}

retryCounter++;
Expand Down
2 changes: 1 addition & 1 deletion SSNFS-client/fuseclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2017 Maxwell Dreytser
* Copyright 2018 Maxwell Dreytser
*/

#ifndef FUSECLIENT_H
Expand Down
2 changes: 1 addition & 1 deletion SSNFS-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2017 Maxwell Dreytser
* Copyright 2018 Maxwell Dreytser
*/

#include <QCoreApplication>
Expand Down
2 changes: 1 addition & 1 deletion SSNFSd/PH7/ph7.c
Original file line number Diff line number Diff line change
Expand Up @@ -20651,7 +20651,7 @@ PH7_PRIVATE void * PH7_StreamOpenHandle(ph7_vm *pVm,const ph7_io_stream *pStream
SyBlobReset(&sWorker);
/* Check the next path */
}
SyBlobRelease(&sWorker);
SyBlobRelease(&sWorker);
}
if( rc == PH7_OK ){
if( bPushInclude ){
Expand Down
8 changes: 8 additions & 0 deletions SSNFSd/log.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#ifndef LOG_H
#define LOG_H

Expand Down
4 changes: 2 additions & 2 deletions SSNFSd/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2017 Maxwell Dreytser
* Copyright 2018 Maxwell Dreytser
*/

#include <QCoreApplication>
Expand Down Expand Up @@ -103,7 +103,7 @@ int main(int argc, char *argv[])

QByteArray shaPass = QCryptographicHash::hash(inputPass.toUtf8(), QCryptographicHash::Sha512);
qInfo() << Common::GetPasswordHash(shaPass.toHex().toLower(), manualSalt);
qInfo() << shaPass.toHex().toLower();
//qInfo() << shaPass.toHex().toLower();

willExit = true;
}
Expand Down
8 changes: 8 additions & 0 deletions SSNFSd/serversettings.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#include "serversettings.h"
#include <QSqlQuery>
#include <QSqlError>
Expand Down
8 changes: 8 additions & 0 deletions SSNFSd/serversettings.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#ifndef SERVERCONFIG_H
#define SERVERCONFIG_H

Expand Down
2 changes: 1 addition & 1 deletion SSNFSd/ssnfsserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2017 Maxwell Dreytser
* Copyright 2018 Maxwell Dreytser
*/

#ifndef SSNFSSERVER_H
Expand Down
66 changes: 66 additions & 0 deletions SSNFSd/ssnfswebworker.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#include "ssnfsworker.h"
#include <log.h>
#include <serversettings.h>
Expand All @@ -12,6 +20,9 @@ static int PH7Consumer(const void *pOutput, unsigned int nOutputLen, void *pUser
((SSNFSWorker*)pUserData)->httpResponse.append((const char*)pOutput, nOutputLen);
return PH7_OK;
}
static void PH7ErrorLogger(const char *zMessage, int iMsgType, const char *zDest, const char *zHeader) {
Log::warn(Log::Categories["Web Server"], "Error {0}: {1} - Dest {2}; Header {3}", iMsgType, zMessage, zDest, zHeader);
}
static int PH7SetHeader(ph7_context *pCtx,int argc,ph7_value **argv) {
SSNFSWorker *worker = (SSNFSWorker*)ph7_context_user_data(pCtx);
if (argc >= 1 && ph7_value_is_string(argv[0])) {
Expand Down Expand Up @@ -57,6 +68,11 @@ static int PH7CheckAuthCookie(ph7_context *pCtx,int argc,ph7_value **argv) {

if (argc == 1 && ph7_value_is_string(argv[0])) {
QString cookie(ph7_value_to_string(argv[0], 0));
if (cookie.isNull() || cookie.isEmpty()) {
ph7_result_bool(pCtx, false);

return PH7_OK;
}

QSqlQuery getUserKey(worker->configDB);
getUserKey.prepare(R"(
Expand All @@ -69,6 +85,14 @@ static int PH7CheckAuthCookie(ph7_context *pCtx,int argc,ph7_value **argv) {
worker->webUserKey = getUserKey.value(0).toLongLong();

ph7_result_bool(pCtx, true);

QSqlQuery updateTokenTmStmp(worker->configDB);
updateTokenTmStmp.prepare(R"(
UPDATE `Web_Tokens`
SET `LastAccess_TmStmp` = CURRENT_TIMESTAMP
WHERE `Token` = ?)");
updateTokenTmStmp.addBindValue(cookie);
updateTokenTmStmp.exec();
} else {
ph7_result_bool(pCtx, false);
}
Expand Down Expand Up @@ -139,6 +163,27 @@ static int PH7MakeAuthCookie(ph7_context *pCtx,int argc,ph7_value **argv) {
return PH7_OK;
}

static int PH7DelAuthCookie(ph7_context *pCtx,int argc,ph7_value **argv) {
SSNFSWorker *worker = (SSNFSWorker*)ph7_context_user_data(pCtx);

if (argc == 1 && ph7_value_is_string(argv[0])) {
QString cookie(ph7_value_to_string(argv[0], 0));
if (cookie.isNull() || cookie.isEmpty()) {
ph7_result_bool(pCtx, false);

return PH7_OK;
}

QSqlQuery delToken(worker->configDB);
delToken.prepare("DELETE FROM `Web_Tokens` WHERE `Token` = ?;");
delToken.addBindValue(cookie);
if (delToken.exec() == false) {
Log::error(Log::Categories["Web Server"], "Error removing token during logout: {0}", ToChr(delToken.lastError().text()));
ph7_context_throw_error(pCtx, PH7_CTX_WARNING, "An internal error occured while deleting the requested token.");
}
}
}

// TODO: Read this from file?
#define HTTP_500_RESPONSE "HTTP/1.1 500 Internal Server Error\r\n" \
"Connection: close\r\n\r\n" \
Expand Down Expand Up @@ -291,6 +336,15 @@ void SSNFSWorker::processHttpRequest(char firstChar)
Log::error(Log::Categories["Web Server"], "Error while installing the VM output consumer callback");
return;
}
rc = ph7_vm_config(pVm,
PH7_VM_CONFIG_ERR_LOG_HANDLER,
PH7ErrorLogger
);
if( rc != PH7_OK ){
socket->write(HTTP_500_RESPONSE);
Log::error(Log::Categories["Web Server"], "Error while installing the VM output consumer callback");
return;
}
rc = ph7_vm_config(pVm,
PH7_VM_CONFIG_HTTP_REQUEST,
Request.data(),
Expand All @@ -301,6 +355,8 @@ void SSNFSWorker::processHttpRequest(char firstChar)
Log::error(Log::Categories["Web Server"], "Error while transferring the HTTP request to PH7.");
return;
}
QString WebPanelPath = ServerSettings::get("WebPanelPath");
chdir(ToChr(WebPanelPath));

rc = ph7_create_function(
pVm,
Expand Down Expand Up @@ -342,6 +398,16 @@ void SSNFSWorker::processHttpRequest(char firstChar)
Log::error(Log::Categories["Web Server"], "Error while setting up make_auth_cookie() function in PH7.");
return;
}
rc = ph7_create_function(
pVm,
"del_auth_cookie",
PH7DelAuthCookie,
this);
if( rc != PH7_OK ) {
socket->write(HTTP_500_RESPONSE);
Log::error(Log::Categories["Web Server"], "Error while setting up del_auth_cookie() function in PH7.");
return;
}

/*
* And finally, execute our program.
Expand Down
8 changes: 8 additions & 0 deletions SSNFSd/ssnfsworker.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#include "ssnfsworker.h"
#include <ssnfsserver.h>
#include <log.h>
Expand Down
8 changes: 8 additions & 0 deletions SSNFSd/ssnfsworker.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* SSNFS Client v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*/

#ifndef SSNFSWORKER_H
#define SSNFSWORKER_H

Expand Down
15 changes: 15 additions & 0 deletions SSNFSd/webpanel/check-cookie.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/*
* SSNFS WebPanel v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*
*/
if (check_auth_cookie($_COOKIE['SSNFS_auth']) == FALSE) {
header("Set-Cookie: SSNFS_auth=; Secure; expires=Thu, 01 Jan 1970 00:00:00 GMT");
header("Location: /login.php");
http_response_code(303);
exit();
}
51 changes: 51 additions & 0 deletions SSNFSd/webpanel/computers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
* SSNFS WebPanel v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*
-->
<?php include_once("check-cookie.php"); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login - SSNFS</title>

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<style>
body {
padding-top: 20px;
padding-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">

<?php include_once("navbar.php"); ?>

<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs &raquo;</a>
</p>
</div>

</div> <!-- /container -->
</body>
</html>
51 changes: 51 additions & 0 deletions SSNFSd/webpanel/connected.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<!--
* SSNFS WebPanel v0.1
*
* Available under the license(s) specified at https://github.com/MDTech-us-MAN/SSNFS.
*
* Copyright 2018 Maxwell Dreytser
*
-->
<?php include_once("check-cookie.php"); ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Login - SSNFS</title>

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.13/css/all.css" integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp" crossorigin="anonymous">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js" integrity="sha384-tsQFqpEReu7ZLhBV2VZlAu7zcOV+rXbYlF2cqB8txI/8aZajjp4Bqd+V6D5IgvKT" crossorigin="anonymous"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

<style>
body {
padding-top: 20px;
padding-bottom: 20px;
}
</style>
</head>
<body>
<div class="container">

<?php include_once("navbar.php"); ?>

<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>Navbar example</h1>
<p>This example is a quick exercise to illustrate how the default, static navbar and fixed to top navbar work. It includes the responsive CSS and HTML, so it also adapts to your viewport and device.</p>
<p>
<a class="btn btn-lg btn-primary" href="../../components/#navbar" role="button">View navbar docs &raquo;</a>
</p>
</div>

</div> <!-- /container -->
</body>
</html>
Loading

1 comment on commit a12aca3

@Maxwell175
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#12

Please sign in to comment.