Skip to content

Commit

Permalink
Authed reg web admin
Browse files Browse the repository at this point in the history
Also automated pillow getting instead of using absolute path
  • Loading branch information
coyotte508 committed Dec 17, 2013
1 parent 381e16f commit c3106e3
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -35,6 +35,7 @@ Makefile*
bin/core*
bin/StatsExtracter
bin/Registry
bin/BattleServer
bin/Chain Breeding
bin/MoveMachine
bin/BattleManager
Expand Down Expand Up @@ -69,3 +70,5 @@ bin/clientscripts
scripts/sprite
bin/usage_stats/raw
bin/serverdb
bin/test-*
pokemon-online*
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "lib/pillow"]
path = lib/pillow
url = https://github.com/acossette/pillow.git
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -10,4 +10,4 @@ install:
- sudo apt-get install libzip-dev qt4-dev-tools libqt4-declarative-shaders libqt4-dev libphonon-dev

script:
- qmake "CONFIG += po_all" && make && ./scripts/run-tests.sh
- qmake "CONFIG += po_all webconf" && make && ./scripts/run-tests.sh
5 changes: 4 additions & 1 deletion PokemonOnline.pro
Expand Up @@ -19,7 +19,7 @@
TEMPLATE = subdirs
CONFIG += ordered

CONFIG(po_all): CONFIG += po_client po_clientplugins po_server po_serverplugins po_relaystation test
CONFIG(po_all): CONFIG += po_client po_clientplugins po_server po_serverplugins po_relaystation po_registry test

!CONFIG(po_server):!CONFIG(po_serverplugins):!CONFIG(po_registry):!CONFIG(po_relaystation):CONFIG += po_client
CONFIG(po_serverplugins):CONFIG += po_server
Expand Down Expand Up @@ -73,6 +73,9 @@ CONFIG(po_serverplugins) {
}

CONFIG(po_registry) {
CONFIG(webconf) {
SUBDIRS += lib/pillow
}
SUBDIRS += src/Registry
}

Expand Down
1 change: 1 addition & 0 deletions lib/pillow
Submodule pillow added at 5ec925
4 changes: 2 additions & 2 deletions src/Registry/Registry.pro
Expand Up @@ -31,8 +31,8 @@ DEFINES = REGISTRY_SIDE
CONFIG(webconf) {
HEADERS += webinterface.h
SOURCES += webinterface.cpp
INCLUDEPATH += /home/lamperi/pillow/pillowcore
LIBS += /home/lamperi/pillow/lib/libpillowcore.a
INCLUDEPATH += ../../lib/pillow/pillowcore
LIBS += ../../lib/pillow/lib/libpillowcore.a
DEFINES += USE_WEBCONF
}

Expand Down
32 changes: 19 additions & 13 deletions src/Registry/webinterface.cpp
@@ -1,20 +1,26 @@
#include "../Utilities/functions.h"
#include "webinterface.h"
#include "registry.h"
#include "server.h"

RegistryWebInterface::RegistryWebInterface(Registry* reg) : QObject(reg), regptr(reg), server()
{
pass = QString::fromUtf8(getFileContent("registry_pass.txt").trimmed());
if (pass) {
pass.insert(0, '/');
}

if (server.listen(QHostAddress::Any, 4567))
{
qDebug() << "Listening to port 4567";
}
router.setUnmatchedRequestAction(Pillow::HttpHandlerSimpleRouter::Return4xxResponse);
router.addRoute("GET", "/index", this, SLOT(showServers(Pillow::HttpConnection*)));
router.addRoute("GET", "/servers", this, SLOT(showServers(Pillow::HttpConnection*)));
router.addRoute("GET", "/bans", this, SLOT(showBans(Pillow::HttpConnection*)));
router.addRoute("POST", "/updatebans", this, SLOT(updateBans(Pillow::HttpConnection*)));
router.addRoute("GET", "/announcement", this, SLOT(showAnnouncement(Pillow::HttpConnection*)));
router.addRoute("POST", "/updateannouncement", this, SLOT(updateAnnouncement(Pillow::HttpConnection*)));
router.addRoute("GET", pass + "/index", this, SLOT(showServers(Pillow::HttpConnection*)));
router.addRoute("GET", pass + "/servers", this, SLOT(showServers(Pillow::HttpConnection*)));
router.addRoute("GET", pass + "/bans", this, SLOT(showBans(Pillow::HttpConnection*)));
router.addRoute("POST", pass + "/updatebans", this, SLOT(updateBans(Pillow::HttpConnection*)));
router.addRoute("GET", pass + "/announcement", this, SLOT(showAnnouncement(Pillow::HttpConnection*)));
router.addRoute("POST", pass + "/updateannouncement", this, SLOT(updateAnnouncement(Pillow::HttpConnection*)));
QObject::connect(&server, SIGNAL(requestReady(Pillow::HttpConnection*)), &router, SLOT(handleRequest(Pillow::HttpConnection*)));
}

Expand All @@ -27,9 +33,9 @@ namespace {
"<title>Pokemon Online Registry</title>"
"</head>"
"<body>"
"<a href='/index'>Server listing</a> "
"| <a href='/announcement'>Announcement</a> "
"| <a href='/bans'> Registry bans</a>"
"<a href='./index'>Server listing</a> "
"| <a href='./announcement'>Announcement</a> "
"| <a href='./bans'> Registry bans</a>"
"<hr>").toUtf8();
QByteArray const footer = QString("</ul></body></html>").toUtf8();
}
Expand Down Expand Up @@ -68,7 +74,7 @@ void RegistryWebInterface::showBans(Pillow::HttpConnection *conn)
if (ip.size() > 0)
conn->writeContent(ipline.arg(ip).toUtf8());
}
conn->writeContent(QString("</ul><form method='POST' enctype='application/x-www-form-urlencoded' action='/updatebans'><h2>Modify bans</h2><br><label for='add'>Add IP ban</label><input type='text' name='add'><br><label for='remove'>Remove IP ban</label><input type='text' name='remove'><br><input type='submit'></form>").toUtf8());
conn->writeContent(QString("</ul><form method='POST' enctype='application/x-www-form-urlencoded' action='./updatebans'><h2>Modify bans</h2><br><label for='add'>Add IP ban</label><input type='text' name='add'><br><label for='remove'>Remove IP ban</label><input type='text' name='remove'><br><input type='submit'></form>").toUtf8());
conn->writeContent(footer);
conn->endContent();
}
Expand All @@ -81,14 +87,14 @@ void RegistryWebInterface::updateBans(Pillow::HttpConnection *conn)
regptr->bannedIPs.insert(post["add"]);

Pillow::HttpHeaderCollection headers;
headers.push_back(qMakePair(QByteArray("Location"), QByteArray("/bans?updated=true")));
headers.push_back(qMakePair(QByteArray("Location"), QByteArray("./bans?updated=true")));
conn->writeResponse(303, headers);
}
void RegistryWebInterface::showAnnouncement(Pillow::HttpConnection *conn)
{
conn->writeHeaders(200);
conn->writeContent(header);
conn->writeContent(QString("<h1>Registry announcement</h1><div style='border 2px coral solid' id='announcement'><center>%1</center></div><hr><form method='POST' action='/updateannouncement' enctype='application/x-www-form-urlencoded'><label for='announcement'>Update announcement:<br></label><textarea name='announcement'>%1</textarea><input type='submit'></form>").arg(regptr->registry_announcement).toUtf8());
conn->writeContent(QString("<h1>Registry announcement</h1><div style='border 2px coral solid' id='announcement'><center>%1</center></div><hr><form method='POST' action='./updateannouncement' enctype='application/x-www-form-urlencoded'><label for='announcement'>Update announcement:<br></label><textarea name='announcement'>%1</textarea><input type='submit'></form>").arg(regptr->registry_announcement).toUtf8());
conn->writeContent(footer);
conn->endContent();
}
Expand All @@ -106,7 +112,7 @@ void RegistryWebInterface::updateAnnouncement(Pillow::HttpConnection *conn)
}

Pillow::HttpHeaderCollection headers;
headers.push_back(qMakePair(QByteArray("Location"), QByteArray("/announcement?updated=true")));
headers.push_back(qMakePair(QByteArray("Location"), QByteArray("./announcement?updated=true")));
conn->writeResponse(303, headers);
}

Expand Down
1 change: 1 addition & 0 deletions src/Registry/webinterface.h
Expand Up @@ -36,6 +36,7 @@ private slots:
Pillow::HttpServer server;
Pillow::HttpHandlerSimpleRouter router;

QString pass;
};

#endif

0 comments on commit c3106e3

Please sign in to comment.