Skip to content

Commit 7c94e34

Browse files
committed
alpha 1.0.1 : stable
1 parent 209d333 commit 7c94e34

File tree

7 files changed

+139
-60
lines changed

7 files changed

+139
-60
lines changed

res_html/index.html

+20
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,25 @@ <h4>FOOTER</h4>
367367
</div>
368368

369369

370+
<div id="resultDialog" class="w3-modal">
371+
<div class="w3-modal-content w3-card-4 w3-animate-zoom" style="max-width:600px">
372+
373+
<div class="w3-center"><br>
374+
<span onclick="document.getElementById('resultDialog').style.display='none'" class="w3-button w3-xlarge w3-transparent w3-display-topright" title="Close Modal">×</span>
375+
<img src="img_avatar4.png" alt="Avatar" style="width:30%" class="w3-circle w3-margin-top">
376+
</div>
377+
378+
<pre id="resultBox"></pre>
379+
380+
381+
</div>
382+
383+
<div class="w3-container w3-border-top w3-padding-16 w3-light-grey">
384+
<button onclick="document.getElementById('resultDialog').style.display='none'" type="button" class="w3-button w3-red">Close</button>
385+
386+
</div>
387+
388+
</div>
389+
370390
</body>
371391
</html>

res_html/main.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ function submitForm(event) {
3333
function (arg) {
3434
//console.log("DEBUG login response: " + arg)
3535
if (arg === true) {
36-
$('#loginError').hide()
36+
$('#loginError').hide();
3737
document.getElementById('loginDialog').style.display = 'none';
38-
window.scrollTo(0,document.getElementById("submodule-container").offsetTop); window.loggedin = true
38+
window.scrollTo(0,document.getElementById("submodule-container").offsetTop);
39+
window.loggedin = true;
40+
channel.objects.clientInteraction.request_token(function(targs) { localStorage.setItem("TOKEN", targs); });
3941
display_all_submodules();
4042
display_all_sites();
4143
} else {
@@ -156,6 +158,6 @@ function executeCommand() {
156158
for (u=0; u<params2.length; u++) {
157159
channel.objects.clientInteraction.set_parameter_value(params2[u].name, params2[u].checked);
158160
}
159-
channel.objects.clientInteraction.execute(function(args) { console.log(args); });
161+
channel.objects.clientInteraction.execute(function(args) { console.log(args); $("#resultBox").html(args); $("#resultDialog").show(); });
160162

161163
}

src_interfaces/clientinteraction.cpp

+41-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#include <QDir>
1818
ClientInteraction::ClientInteraction(QObject *parent, LoginController *i_login, FirewallController* i_firewall, DatabaseController *i_db) : QObject(parent), loginController(i_login), firewallController(i_firewall), db(i_db)
1919
{
20-
this->websiteController = new WebsiteController(this, db);
20+
this->websiteController = new WebsiteController(this, db);
2121
}
2222

2323
bool ClientInteraction::login(QString username, QString password)
@@ -39,6 +39,37 @@ bool ClientInteraction::login(QString username, QString password)
3939
return false;
4040
}
4141

42+
bool ClientInteraction::tokenLogin(QString token)
43+
{
44+
if (!firewallController->isBanned(this->remoteIP)) {
45+
46+
47+
if (loginController->loggedIn == false) {
48+
if (loginController->check_token(token) == true) {
49+
emit this->LoginSuccessful();
50+
return true;
51+
}
52+
} else {
53+
54+
return true;
55+
}
56+
}
57+
emit this->LoginFailed();
58+
return false;
59+
}
60+
61+
QVariant ClientInteraction::request_token()
62+
{
63+
if (!loginController->loggedIn) { emit this->requireLogin(); return QVariant::fromValue(QString("")); } else {
64+
if (this->loginController->loggedIn == true) {
65+
QString newToken = this->loginController->new_token(loginController->current_token);
66+
loginController->current_token = newToken;
67+
return QVariant::fromValue(newToken);
68+
}
69+
return QVariant::fromValue(QString("You must first login"));
70+
}
71+
}
72+
4273
QVariant ClientInteraction::allowedSubmodules()
4374
{
4475
if (!loginController->loggedIn) { emit this->requireLogin(); return QVariant::fromValue(QString("")); } else {
@@ -225,7 +256,7 @@ QVariant ClientInteraction::execute()
225256
QByteArray output;
226257
output.append(processLauncher->run_internal_script("wp", (QStringList() << QString("--path=%1").arg(websiteController->currentWebsite) << rv.split(" ", QString::SkipEmptyParts))));
227258

228-
qDebug() << output;
259+
qDebug() << output;
229260
return QVariant::fromValue(output);
230261

231262
//return QVariant::fromValue(rv);
@@ -272,18 +303,18 @@ QVariant ClientInteraction::websites()
272303

273304

274305

275-
i++;
276-
}
277-
main_array = QJsonArray::fromVariantList(rv);
306+
i++;
307+
}
308+
main_array = QJsonArray::fromVariantList(rv);
278309

279-
QJsonObject mainObject;
310+
QJsonObject mainObject;
280311

281312

282-
mainObject.insert("websites", QJsonValue::fromVariant(rv));
283-
doc.setObject(mainObject);
313+
mainObject.insert("websites", QJsonValue::fromVariant(rv));
314+
doc.setObject(mainObject);
284315

285-
return QVariant::fromValue(doc.toJson(QJsonDocument::Compact));
286-
}
316+
return QVariant::fromValue(doc.toJson(QJsonDocument::Compact));
317+
}
287318
}
288319

289320
void ClientInteraction::set_parameter_value(int paramidx, QVariant val)

src_interfaces/clientinteraction.h

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class ClientInteraction : public QObject
2222
FirewallController* firewallController;
2323
DatabaseController* db;
2424
Q_INVOKABLE bool login(QString username, QString password);
25+
Q_INVOKABLE bool tokenLogin(QString token);
26+
Q_INVOKABLE QVariant request_token();
2527
QString remoteIP;
2628
Q_INVOKABLE QVariant allowedSubmodules();
2729
Q_INVOKABLE QVariant set_current_submodule(QString i_module);

src_interfaces/databasecontroller.cpp

+4-16
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,27 @@ void DatabaseController::load_database(QString filepath)
7777
<< "cap"
7878
<< "cli"
7979
<< "comment"
80-
<< "config"
8180
<< "core"
8281
<< "cron"
8382
<< "db"
8483
<< "embed"
85-
<< "eval"
86-
<< "eval-file"
8784
<< "export"
88-
<< "help"
8985
<< "import"
9086
<< "language"
9187
<< "media"
9288
<< "menu"
9389
<< "network"
9490
<< "option"
95-
<< "package"
9691
<< "plugin"
9792
<< "post"
9893
<< "post-type"
9994
<< "rewrite"
10095
<< "role"
10196
<< "scaffold"
10297
<< "search-replace"
103-
<< "server"
104-
<< "shell"
10598
<< "sidebar"
10699
<< "site"
107100
<< "super-admin"
108-
<< "taxonomy"
109101
<< "term"
110102
<< "theme"
111103
<< "transient"
@@ -122,35 +114,27 @@ void DatabaseController::load_database(QString filepath)
122114
<< "Adds, removes, and lists capabilities of a user role."
123115
<< "Review current WP-CLI info, check for updates, or see defined aliases."
124116
<< "Creates, updates, deletes, and moderates comments."
125-
<< "Generates and reads the wp-config.php file."
126117
<< "Downloads, installs, updates, and manages a WordPress installation."
127118
<< "Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules."
128119
<< "Performs basic database operations using credentials stored in wp-config.php."
129120
<< "Inspects oEmbed providers, clears embed cache, and more."
130-
<< "Executes arbitrary PHP code."
131-
<< "Loads and executes a PHP file."
132121
<< "Exports WordPress content to a WXR file."
133-
<< "Get help on WP-CLI, or on a specific command."
134122
<< "Imports content from a given WXR file."
135123
<< "Installs, activates, and manages language packs."
136124
<< "Imports files as attachments, regenerates thumbnails, or lists registered image sizes."
137125
<< "Lists, creates, assigns, and deletes the active theme's navigation menus."
138126
<< "Perform network-wide operations."
139127
<< "Retrieves and sets site options, including plugin and WordPress settings."
140-
<< "Lists, installs, and removes WP-CLI packages."
141128
<< "Manages plugins, including installs, activations, and updates."
142129
<< "Manages posts, content, and meta."
143130
<< "Retrieves details on the site's registered post types."
144131
<< "Lists or flushes the site's rewrite rules, updates the permalink structure."
145132
<< "Manages user roles, including creating new roles and resetting to defaults."
146133
<< "Generates code for post types, taxonomies, plugins, child themes, etc."
147134
<< "Searches/replaces strings in the database."
148-
<< "Launches PHP's built-in web server for a specific WordPress installation."
149-
<< "Opens an interactive PHP console for running and testing PHP code."
150135
<< "Lists registered sidebars."
151136
<< "Creates, deletes, empties, moderates, and lists one or more sites on a multisite installation."
152137
<< "Lists, adds, or removes super admin users on a multisite installation."
153-
<< "Retrieves information about registered taxonomies."
154138
<< "Manages taxonomy terms and term meta, with create, delete, and list commands."
155139
<< "Manages themes, including installs, activations, and updates."
156140
<< "Adds, gets, and deletes entries in the WordPress Transient Cache."
@@ -176,6 +160,10 @@ void DatabaseController::load_database(QString filepath)
176160
if (!db.tables().contains("WEBSITES")) {
177161
db.exec("CREATE table WEBSITES (ID int primary key, NAME text, PATH text)");
178162
}
163+
if (!db.tables().contains("SESSIONS")) {
164+
db.exec("CREATE table SESSIONS (ID int primary key, UID text, TOKEN text, SESSIONDATA text)");
165+
}
166+
179167
}
180168
// // qDebug() << executeSelectQuery("PERMSTATES", (QStringList() << "NAME" << "DESCRIPTION"), QString(""));
181169
}

src_interfaces/logincontroller.cpp

+62-30
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,77 @@
33
#include <QVector>
44
#include <QtDebug>
55
#include <QVectorIterator>
6+
#include <QSqlQuery>
7+
#include <QSqlDatabase>
8+
#include <QVariant>
69
LoginController::LoginController(QObject *parent, DatabaseController* i_db) : QObject(parent), m_db(i_db)
710
{
8-
this->hello_str = "hello, world!";
9-
loggedIn = false;
11+
this->hello_str = "hello, world!";
12+
loggedIn = false;
1013
}
1114

1215
bool LoginController::check_login(QString username, QString password)
1316
{
1417

1518

16-
if (m_db->executeSelectQuery("USERS", (QStringList() << "USERNAME" << "PASSWORD"), QString("where USERNAME like '%1' and PASSWORD like '%2'").arg(m_db->toHex(username)).arg(m_db->toHex(m_db->sha512(password)))).count() > 0) {
17-
loggedIn = true;
18-
19-
20-
//populate permissions, descriptions, etc on a per user basis
21-
// this will allow for future extending of the code if the need
22-
// arises to have language support etc then the descriptions can
23-
// be populated based on the selected language or the descriptions
24-
// can be more specific for administrators than for operators etc
25-
// it wastes about 2kb of total memory to store and is only requested
26-
// once on login so i think its okay to keep
27-
28-
QVector<QVector<QString> > rv(m_db->executeSelectQuery("USERS", (QStringList() << "USERS.ID" << "USERNAME" << "ASSIGNMENTS.PERMISSION" << "ASSIGNMENTS.ASSIGNED" << "PERMSTATES.DESCRIPTION" << "PERMSTATES.NAME"), "inner join ASSIGNMENTS ON UID=USERS.ID inner join PERMSTATES on ASSIGNMENTS.PERMISSION=PERMSTATES.PERMISSION"));
29-
QVectorIterator<QVector<QString > > i(rv);
30-
while (i.hasNext()) {
31-
QVector<QString> rowData(i.next());
32-
this->assignments[rowData.at(2).toInt()] = static_cast<bool>(rowData.at(3).toInt());
33-
this->assignment_names[rowData.at(2).toInt()] = rowData.at(5);
34-
this->assignment_id_names[rowData.at(5)] = rowData.at(2).toInt();
35-
this->assignment_descriptions[rowData.at(2).toInt()] = rowData.at(4);
36-
this->m_uid = rowData.at(0).toInt();
37-
this->m_username = m_db->fromHex(rowData.at(1));
38-
}
39-
//end of permission assignment population
40-
// qDebug() << "Successful Login";
41-
return true;
19+
if (m_db->executeSelectQuery("USERS", (QStringList() << "USERNAME" << "PASSWORD"), QString("where USERNAME like '%1' and PASSWORD like '%2'").arg(m_db->toHex(username)).arg(m_db->toHex(m_db->sha512(password)))).count() > 0) {
20+
loggedIn = true;
21+
22+
23+
//populate permissions, descriptions, etc on a per user basis
24+
// this will allow for future extending of the code if the need
25+
// arises to have language support etc then the descriptions can
26+
// be populated based on the selected language or the descriptions
27+
// can be more specific for administrators than for operators etc
28+
// it wastes about 2kb of total memory to store and is only requested
29+
// once on login so i think its okay to keep
30+
31+
QVector<QVector<QString> > rv(m_db->executeSelectQuery("USERS", (QStringList() << "USERS.ID" << "USERNAME" << "ASSIGNMENTS.PERMISSION" << "ASSIGNMENTS.ASSIGNED" << "PERMSTATES.DESCRIPTION" << "PERMSTATES.NAME"), "inner join ASSIGNMENTS ON UID=USERS.ID inner join PERMSTATES on ASSIGNMENTS.PERMISSION=PERMSTATES.PERMISSION"));
32+
QVectorIterator<QVector<QString > > i(rv);
33+
while (i.hasNext()) {
34+
QVector<QString> rowData(i.next());
35+
this->assignments[rowData.at(2).toInt()] = static_cast<bool>(rowData.at(3).toInt());
36+
this->assignment_names[rowData.at(2).toInt()] = rowData.at(5);
37+
this->assignment_id_names[rowData.at(5)] = rowData.at(2).toInt();
38+
this->assignment_descriptions[rowData.at(2).toInt()] = rowData.at(4);
39+
this->m_uid = rowData.at(0).toInt();
40+
this->m_username = m_db->fromHex(rowData.at(1));
41+
}
42+
//end of permission assignment population
43+
// qDebug() << "Successful Login";
44+
return true;
45+
}
46+
loggedIn = false;
47+
return false;
48+
}
49+
50+
bool LoginController::check_token(QString token)
51+
{
52+
if (m_db->executeSelectQuery("SESSIONS", (QStringList() << "UID" << "TOKEN"), QString("where TOKEN like '%1'").arg(m_db->toHex(token))).count() > 0) {
53+
loggedIn = true;
54+
QSqlQuery query = m_db->db.exec(QString("delete from SESSIONS where TOKEN like '%1'").arg(m_db->toHex(token)));
55+
query.finish();
56+
57+
} else {
58+
loggedIn = false;
4259
}
43-
loggedIn = false;
44-
return false;
60+
return loggedIn;
61+
}
62+
63+
QString LoginController::new_token(QString oldToken)
64+
{
65+
QSqlQuery query = m_db->db.exec(QString("delete from SESSIONS where TOKEN like '%1'").arg(m_db->toHex(oldToken)));
66+
query.finish();
67+
QVariantList v;
68+
QUuid newTokenUUid;
69+
QString newToken = newTokenUUid.createUuid().toString();
70+
int newid = m_db->executeSelectQuery("SESSIONS", (QStringList() << "UID" << "TOKEN"), QString("")).count();
71+
v.append(QVariant::fromValue(newid));
72+
v.append(QVariant::fromValue(m_uid));
73+
v.append(QVariant::fromValue(newToken));
74+
75+
m_db->executeInsert("SESSIONS", v);
76+
return newToken;
4577
}
4678

4779
void LoginController::hello()

src_interfaces/logincontroller.h

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ class LoginController : public QObject
2222
QHash<QString, int> assignment_id_names;
2323
int m_uid;
2424
QString m_username;
25+
QString current_token;
26+
bool check_token(QString token);
27+
QString new_token(QString oldToken);
2528
signals:
2629

2730
public slots:
2831

32+
2933
private:
3034
QString hello_str;
3135
private slots:
3236
void hello();
3337

3438
};
3539

36-
#endif // LOGINCONTROLLER_H
40+
#endif // LOGINCONTROLLER_H

0 commit comments

Comments
 (0)