Warning: session_start(): open(/var/lib/php/sessions/sess_v6ohs67r6l60mcq824ej84nch7, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
cmodule GazelleWebServer > DynPrintLogAndEnabled {
transient MyHTTPD server;
new Set authedCookies;
void start() ctex {
super.start();
if (!enabled) ret;
dm_useLocalMechListCopies();
server = new MyHTTPD(80);
server.serveFunction = func(S uri, SS parms) {
serve(uri, parms)
};
server.start();
print("HTTP server started on port " + server.getPort());
}
void cleanMeUp {
server.stop();
server = null;
}
O serve(S uri, SS params) {
new Matches m;
S cookie = serveHttp_cookieHandling();
bool authed = nempty(cookie) && syncContains(authedCookies, cookie);
print("Cookie: " + cookie + ", authed: " + authed);
S master = trim(loadTextFile(javaxSecretDir("gazelle-master-pw")));
S attempt = params.get('_pass);
if (nempty(attempt) && nempty(cookie) && nempty(master)) {
if (eq(attempt, master)) {
print("Login SUCCEEDED");
syncAdd(authedCookies, cookie);
change();
authed = true;
} else
print("Login FAILED");
}
if (eq(uri, "/favicon.ico"))
ret serveFile(loadLibrary(#1400189), faviconMimeType());
O[] bodyParams = litobjectarray(style := "font-family: Roboto Mono; " + (authed ? "background-color: #FFFF88" : ""));
if (eq(uri, "/login"))
ret hhtml_head_title_body("Login" + " | Gazelle",
hprelude() +
(nempty(master) ? hpostform(hpasswordfield('_pass)) : "No master PW"), bodyParams);
if (swic(uri, "/texts/", m)) {
S textID = m.rest();
if (!possibleMD5(textID)) ret serve404();
ret serveTextFileAsUTF8(javaxDataDir("Gazelle Texts/" + textID));
}
if (swic(uri, "/rule/", m)) {
S ruleID = assertGlobalID(m.rest());
PairS textAndComment = unnull(dm_textAndCommentForRule(ruleID));
L feedback = dm_gazelle_feedbackForRule(ruleID);
L applications = dm_gazelle_applicationsForRule(ruleID);
Map feedbackByContext = indexByFieldNotNull context(feedback);
S title = "Rule " + ruleID;
bool showStruct = eq("1", params.get('struct));
L list = cloneList(feedback);
for (O o : applications)
if (!containsKey(feedbackByContext, getString context(o)))
list.add(o);
// add comments
for (S applicationID, S text : subMapStartingWith_dropPrefix(params, "comment_")) {
continue if empty(text = trim(text));
if (!authed) text = "[anon] " + text;
O app = findByField(list, globalID := applicationID);
print("Processing comment for " + applicationID + " - " + app);
if (app == null) continue;
Set comments = asSet(tlft(getString comments(app)));
if (!contains(comments, text))
call(app, '_setField, comments := appendWithNewLine(getString comments(app), text));
}
// Serve Rule & Applications & Feedback
L