Comparer les révisions

..

Pas de révisions en commun. "ece11442739b7dc9fbcccd8accb8f78aa253c925" et "24121a1618f9b3801af8e38b994fe16e9ae6d1ba" ont des historiques entièrement différents.

12 fichiers modifiés avec 32 ajouts et 767 suppressions

Fichier binaire non affiché.

Voir le fichier

@ -10,7 +10,6 @@ class SessionDao
virtual void save(const Session &session) = 0;
virtual std::optional<Session> find(std::string token) = 0;
virtual void deleteSession(std::string token) = 0;
virtual std::vector<Session> fetch() = 0;
virtual ~SessionDao()
{
}

63
database/sessiondaosqlite.cpp Fichier exécutable → Fichier normal
Voir le fichier

@ -50,29 +50,6 @@ void SessionDaoSqlite::deleteSession(std::string token)
}
}
void SessionDaoSqlite::fillSession(int userid, Session &sess)
{
if(userid > -1)
{
UserDaoSqlite userDao{this->db};
auto u = userDao.find(userid);
if(u)
{
sess.user = *u;
}
else
{
Logger::error() << "Session for non existent user";
throw DatabaseQueryException("Session for non existent user");
}
}
else
{
sess.user = User::Anonymous();
}
sess.loggedIn = userid != -1;
}
std::optional<Session> SessionDaoSqlite::find(std::string token)
{
Session result;
@ -85,7 +62,25 @@ std::optional<Session> SessionDaoSqlite::find(std::string token)
int userid;
q >> std::tie(userid, result.token, result.csrf_token, result.creation_time);
fillSession(userid, result);
if(userid > -1)
{
UserDaoSqlite userDao{this->db};
auto u = userDao.find(userid);
if(u)
{
result.user = *u;
}
else
{
Logger::error() << "Session for non existent user";
throw DatabaseQueryException("Session for non existent user");
}
}
else
{
result.user = User::Anonymous();
}
result.loggedIn = userid != -1;
}
catch(const sqlite::exceptions::no_rows &e)
{
@ -97,23 +92,3 @@ std::optional<Session> SessionDaoSqlite::find(std::string token)
}
return result;
}
std::vector<Session> SessionDaoSqlite::fetch()
{
std::vector<Session> result;
*db << "SELECT userid, token, csrf_token, strftime('%s', creationtime) FROM session" >>
[this, &result](int userid, std::string token, std::string csrf_token, time_t creationtime)
{
Session tmp;
tmp.csrf_token = csrf_token;
tmp.token = token;
tmp.creation_time = creationtime;
fillSession(userid, tmp);
result.push_back(tmp);
};
return result;
}

Voir le fichier

@ -6,15 +6,11 @@
class SessionDaoSqlite : public SessionDao, protected SqliteDao
{
private:
void fillSession(int userid, Session &sess);
public:
SessionDaoSqlite();
void save(const Session &session) override;
std::optional<Session> find(std::string token) override;
void deleteSession(std::string token) override;
std::vector<Session> fetch() override;
using SqliteDao::SqliteDao;
};

Voir le fichier

@ -7,8 +7,8 @@ class Logger
private:
class LogEntry
{
bool headerSent = false;
std::ostream *out = nullptr;
bool headerSent;
std::ostream *out;
std::string prefix;
public:

Voir le fichier

@ -31,8 +31,8 @@ SOFTWARE.
#include "handlers/handlerfactory.h"
#include "database/databasefactory.h"
#include "config.h"
#include "session.h"
#include "template.h"
#include "session.h"
#include "logger.h"
#include "urlprovider.h"
#include "requestworker.h"
@ -74,33 +74,6 @@ std::unique_ptr<ICache> createCache(const ConfigVariableResolver &resolver)
return std::make_unique<FsCache>(path);
}
std::thread background_worker;
void start_background_worker(Database &database, Config &config)
{
background_worker = std::thread(
[&database, &config]()
{
while(true)
{
Logger::log() << "Executing background worker";
auto sessionDao = database.createSessionDao();
auto sessionList = sessionDao->fetch();
time_t now = time(NULL);
for(Session &sess : sessionList)
{
if(now - sess.creation_time > config.session_max_lifetime)
{
sessionDao->deleteSession(sess.token);
}
}
std::this_thread::sleep_for(std::chrono::hours(1));
}
});
}
int main(int argc, char **argv)
{
@ -163,7 +136,6 @@ int main(int argc, char **argv)
Logger::setStream(&logstream);
auto database = createDatabase(config);
std::string socketPath = config.configVarResolver.getConfig("socketpath");
CLIHandler cliHandler(config, *database);
@ -186,8 +158,6 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
start_background_worker(*database.get(), config);
CLIServer cliServer{cliHandler};
if(!cliServer.detachServer(socketPath))
{

Voir le fichier

@ -42,7 +42,6 @@ std::string RevisionRenderer::renderContent(std::string content)
{
dynamicVarsMap["pagetitle"] = parser.extractCommand("pagetitle", content);
dynamicVarsMap["createdon"] = utils::toISODate(time(NULL));
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(time(NULL));
std::string resolvedContent = parser.parseDynamics(content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));
@ -61,7 +60,6 @@ std::string RevisionRenderer::renderContent(const Revision &r, std::string_view
dynamicVarsMap["createdon"] = utils::toISODate(firstRevision.value().timestamp);
dynamicVarsMap["pagetitle"] = customTitle;
dynamicVarsMap["modifydatetime"] = utils::toISODateTime(r.timestamp);
std::string resolvedContent = parser.parseDynamics(r.content, std::bind(&RevisionRenderer::dynamicCallback, this, std::placeholders::_1, std::placeholders::_2));

Voir le fichier

@ -4,5 +4,8 @@
<li style="font-size: 10pt">Powered by qswiki</li>
</ul>
</footer>
<script>
{qswiki:include:js_session_refresh}
</script>
</body>
</html>
</html>

Voir le fichier

@ -0,0 +1,5 @@
function refreshSession()
{
fetch(new Request("{qswiki:config:refreshsessionurl}"));
}
setInterval(refreshSession, 60*2*1000);

Voir le fichier

@ -7,6 +7,7 @@
</footer>
<script src="{qswiki:config:highlightjspath}"></script>
<script>
{qswiki:include:js_session_refresh}
hljs.highlightAll();
</script>
</body>

Voir le fichier

@ -1,446 +0,0 @@
body
{
padding: 0;
margin: 0;
font-family: Verdana;
background-color: white;
display: grid;
min-height: 100vh;
grid-template-rows: auto 1fr auto;
grid-template-areas: "nav nav"
"main side"
"footer footer";
grid-template-columns: 1fr auto;
}
header
{
margin: 0;
paddin: 0;
}
h1, h2, h3
{
margin: 0;
padding: 0;
display: inline;
}
nav
{
padding: 0px;
margin: 0px;
display: flex;
background-color: #062463;
justify-content: space-between;
flex-wrap: wrap;
grid-area: nav;
}
nav ul
{
background-color: #062463;
color: white;
margin: 0;
padding: 0;
list-style-type: none;
display: flex;
align-items: center;
flex-wrap: wrap;
}
nav li
{
margin: 0;
padding: 0;
}
nav a, nav a:visited
{
padding: 10px;
text-decoration: none;
color: white;
display: block;
font-weight: bold;
text-align: center;
line-height: 100%;
}
nav a:hover, nav a:focus
{
padding: 10px;
text-decoration: none;
background-color: white;
color: #062463;
display: block;
font-weight: bold;
}
a, a:visited
{
color: #062463;;
}
a:hover
{
background-color: #062463;
color: white;
}
#content
{
padding: 15px;
font-family: monospace;
font-size: 14pt;
flex: 1;
grid-area: main
}
#sidebar
{
grid-area: side;
}
#sidebar ul
{
list-style-type: none;
}
#sidebar a, a:visited
{
color: #062463;
}
#sidebar a:hover
{
background-color: #062463;
color: white;
}
#content a, a:visited
{
color: #062463;
}
#content a:hover
{
background-color: #062463;
color: white;
}
footer
{
width: 100%;
display: block;
color: white;
background-color: #062463;
font-weight: bold;
grid-area: footer;
}
footer ul
{
background-color: #062463;
margin: 0px;
padding: 0px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-items: center;
}
footer li
{
margin: 0;
padding: 0;
display: inline-block;
line-height: 45px;
color: white;
font-weight: bold;
//flex: 1 1 0;
text-align: center;
}
footer a, a:visited
{
text-decoration: none;
color: white;
display: inline-block;
}
footer a:hover, ul#nav a:focus
{
text-decoration: none;
color: #062463;
background-color: white;
display: inline-block;
}
#cats
{
background-color: #062463;
}
.letter_search_result
{
text-decoration: underline;
font-weight: bold;
}
ol
{
counter-reset: item;
}
.indexlink
{
display: block;
}
.notexists
{
color: red !important;
font-weight: bold;
}
body
{
padding: 0;
margin: 0;
font-family: Verdana;
background-color: white;
display: grid;
min-height: 100vh;
grid-template-rows: auto 1fr auto;
grid-template-areas: "nav nav"
"main side"
"footer footer";
grid-template-columns: 1fr auto;
}
header
{
margin: 0;
paddin: 0;
}
h1, h2, h3
{
margin: 0;
padding: 0;
display: inline;
}
nav
{
padding: 0px;
margin: 0px;
display: flex;
background-color: #062463;
justify-content: space-between;
flex-wrap: wrap;
grid-area: nav;
}
nav ul
{
background-color: #062463;
color: white;
margin: 0;
padding: 0;
list-style-type: none;
display: flex;
align-items: center;
flex-wrap: wrap;
}
nav li
{
margin: 0;
padding: 0;
}
nav a, nav a:visited
{
padding: 10px;
text-decoration: none;
color: white;
display: block;
font-weight: bold;
text-align: center;
line-height: 100%;
}
nav a:hover, nav a:focus
{
padding: 10px;
text-decoration: none;
background-color: white;
color: #062463;
display: block;
font-weight: bold;
}
a, a:visited
{
color: #062463;;
}
a:hover
{
background-color: #062463;
color: white;
}
#content
{
padding: 15px;
font-family: monospace;
font-size: 14pt;
flex: 1;
grid-area: main
}
#sidebar
{
grid-area: side;
}
#sidebar ul
{
list-style-type: none;
}
#sidebar a, a:visited
{
color: #062463;
}
#sidebar a:hover
{
background-color: #062463;
color: white;
}
#content a, a:visited
{
color: #062463;
}
#content a:hover
{
background-color: #062463;
color: white;
}
footer
{
width: 100%;
display: block;
color: white;
background-color: #062463;
font-weight: bold;
grid-area: footer;
}
footer ul
{
background-color: #062463;
margin: 0px;
padding: 0px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-items: center;
}
footer li
{
margin: 0;
padding: 0;
display: inline-block;
line-height: 45px;
color: white;
font-weight: bold;
//flex: 1 1 0;
text-align: center;
}
footer a, a:visited
{
text-decoration: none;
color: white;
display: inline-block;
}
footer a:hover, ul#nav a:focus
{
text-decoration: none;
color: #062463;
background-color: white;
display: inline-block;
}
#cats
{
background-color: #062463;
}
.letter_search_result
{
text-decoration: underline;
font-weight: bold;
}
ol
{
counter-reset: item;
}
.indexlink
{
display: block;
}
.notexists
{
color: red !important;
font-weight: bold;
}
@media screen and (max-width: 768px)
{
#sidebar
{
display: none;
}
#footer li:nth-child(-n+2)
{
display: none;
}
#footer li:nth-of-type(3)
{
text-align: center;
width: 100%;
}
}

Voir le fichier

@ -1,236 +0,0 @@
body
{
padding: 0;
margin: 0;
font-family: Verdana;
background-color: white;
display: grid;
min-height: 100vh;
grid-template-rows: auto 1fr auto;
grid-template-areas: "nav nav"
"main side"
"footer footer";
grid-template-columns: 1fr auto;
}
header
{
margin: 0;
paddin: 0;
}
h1, h2, h3
{
margin: 0;
padding: 0;
display: inline;
}
nav
{
padding: 0px;
margin: 0px;
display: flex;
background-color: #062463;
justify-content: space-between;
flex-wrap: wrap;
grid-area: nav;
}
nav ul
{
background-color: #062463;
color: white;
margin: 0;
padding: 0;
list-style-type: none;
display: flex;
align-items: center;
flex-wrap: wrap;
}
nav li
{
margin: 0;
padding: 0;
}
nav a, nav a:visited
{
padding: 10px;
text-decoration: none;
color: white;
display: block;
font-weight: bold;
text-align: center;
line-height: 100%;
}
nav a:hover, nav a:focus
{
padding: 10px;
text-decoration: none;
background-color: white;
color: #062463;
display: block;
font-weight: bold;
}
a, a:visited
{
color: #062463;;
}
a:hover
{
background-color: #062463;
color: white;
}
#content
{
padding: 15px;
font-family: monospace;
font-size: 14pt;
flex: 1;
grid-area: main
}
#sidebar
{
grid-area: side;
}
#sidebar ul
{
list-style-type: none;
}
#sidebar a, a:visited
{
color: #062463;
}
#sidebar a:hover
{
background-color: #062463;
color: white;
}
#content a, a:visited
{
color: #062463;
}
#content a:hover
{
background-color: #062463;
color: white;
}
footer
{
width: 100%;
display: block;
color: white;
background-color: #062463;
font-weight: bold;
grid-area: footer;
}
footer ul
{
background-color: #062463;
margin: 0px;
padding: 0px;
display: flex;
justify-content: space-between;
flex-wrap: wrap;
align-items: center;
}
footer li
{
margin: 0;
padding: 0;
display: inline-block;
line-height: 45px;
color: white;
font-weight: bold;
text-align: center;
}
footer a, a:visited
{
text-decoration: none;
color: white;
display: inline-block;
}
footer a:hover, ul#nav a:focus
{
text-decoration: none;
color: #062463;
background-color: white;
display: inline-block;
}
#cats
{
background-color: #062463;
}
.letter_search_result
{
text-decoration: underline;
font-weight: bold;
}
ol
{
counter-reset: item;
}
.indexlink
{
display: block;
}
.notexists
{
color: red !important;
font-weight: bold;
}
#searchlink
{
display: none;
}
@media screen and (orientation: portrait)
{
#sidebar
{
display: none;
}
#footer li:nth-child(-n+2)
{
display: none;
}
#footer li:nth-of-type(3)
{
text-align: center;
width: 100%;
}
#searchlink {
display: inline;
}
#searchbar {
display: none;
}
}