2016-08-21 05:02:18 +00:00
|
|
|
#if defined(ENABLE_WWW)
|
|
|
|
|
|
|
|
#include <time.h>
|
|
|
|
#include <stdlib.h>
|
2018-10-13 14:28:56 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
#include "www_tree.h"
|
2016-08-21 05:02:18 +00:00
|
|
|
#include "bbs.h"
|
|
|
|
|
|
|
|
extern struct bbs_config conf;
|
|
|
|
|
|
|
|
char *www_last10() {
|
2018-10-13 14:28:56 +00:00
|
|
|
size_t n = 0;
|
2018-10-21 10:11:30 +00:00
|
|
|
//stralloc page = EMPTY_STRALLOC;
|
2016-08-21 05:02:18 +00:00
|
|
|
struct last10_callers callers[10];
|
2018-10-18 11:03:52 +00:00
|
|
|
char last10_path[PATH_MAX];
|
2018-10-21 10:11:30 +00:00
|
|
|
struct www_tag *page;
|
|
|
|
struct www_tag *cur_tag;
|
|
|
|
struct www_tag *child_tag;
|
|
|
|
struct www_tag *child_child_tag;
|
|
|
|
struct www_tag *child_child_child_tag;
|
|
|
|
|
2016-08-21 05:02:18 +00:00
|
|
|
|
2018-10-18 11:03:52 +00:00
|
|
|
snprintf(last10_path, PATH_MAX, "%s/last10v2.dat", conf.bbs_path);
|
|
|
|
|
|
|
|
FILE *fptr = fopen(last10_path, "rb");
|
2016-08-21 05:02:18 +00:00
|
|
|
if (fptr != NULL) {
|
2018-10-13 20:31:18 +00:00
|
|
|
for (; n < 10; ++n)
|
2018-10-14 00:46:52 +00:00
|
|
|
if (fread(&callers[n], sizeof(callers[n]), 1, fptr) != 1)
|
2016-08-21 05:02:18 +00:00
|
|
|
break;
|
|
|
|
fclose(fptr);
|
|
|
|
}
|
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
page = www_tag_new(NULL, "");
|
|
|
|
cur_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(cur_tag, "class", "content-header");
|
|
|
|
www_tag_add_child(page, cur_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_tag = www_tag_new("h2", NULL);
|
|
|
|
www_tag_add_child(cur_tag, child_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_tag = www_tag_new(NULL, "Last 10 Callers");
|
|
|
|
www_tag_add_child(child_tag, child_child_tag);
|
|
|
|
|
|
|
|
cur_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(cur_tag, "class", "div-table");
|
|
|
|
www_tag_add_child(page, cur_tag);
|
|
|
|
|
2018-10-13 14:28:56 +00:00
|
|
|
for (size_t i = 0; i < n; ++i) {
|
|
|
|
struct tm called;
|
|
|
|
char buffer[32];
|
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(child_tag, "class", "last10-row");
|
|
|
|
www_tag_add_child(cur_tag, child_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(child_child_tag, "class", "last10-name");
|
|
|
|
www_tag_add_child(child_tag, child_child_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_child_tag = www_tag_new(NULL, callers[i].name);
|
|
|
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
|
|
|
|
|
|
|
|
|
|
|
child_child_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(child_child_tag, "class", "last10-location");
|
|
|
|
www_tag_add_child(child_tag, child_child_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_child_tag = www_tag_new(NULL, callers[i].location);
|
|
|
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(child_child_tag, "class", "last10-date");
|
|
|
|
www_tag_add_child(child_tag, child_child_tag);
|
2018-10-13 14:28:56 +00:00
|
|
|
|
|
|
|
localtime_r(&callers[i].time, &called);
|
|
|
|
if (conf.date_style == 1)
|
|
|
|
strftime(buffer, sizeof buffer, "%H:%M %m-%d-%y", &called);
|
|
|
|
else
|
|
|
|
strftime(buffer, sizeof buffer, "%H:%M %d-%m-%y", &called);
|
2018-10-21 10:11:30 +00:00
|
|
|
|
|
|
|
child_child_child_tag = www_tag_new(NULL, buffer);
|
|
|
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
|
|
|
|
2018-10-13 14:28:56 +00:00
|
|
|
if (callers[i].calls == 1) {
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_tag = www_tag_new("div", NULL);
|
|
|
|
www_tag_add_attrib(child_child_tag, "class", "last10-new");
|
|
|
|
www_tag_add_child(child_tag, child_child_tag);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
stralloc url = EMPTY_STRALLOC;
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
stralloc_copys(&url, conf.www_url);
|
|
|
|
stralloc_cats(&url, "static/newuser.png");
|
|
|
|
stralloc_0(&url);
|
2018-10-30 22:32:01 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
child_child_child_tag = www_tag_new("img", NULL);
|
|
|
|
www_tag_add_attrib(child_child_child_tag, "src", url.s);
|
|
|
|
free(url.s);
|
|
|
|
www_tag_add_child(child_child_tag, child_child_child_tag);
|
2017-10-03 02:09:50 +00:00
|
|
|
}
|
2016-08-21 05:02:18 +00:00
|
|
|
}
|
2018-10-08 14:13:11 +00:00
|
|
|
|
2018-10-21 10:11:30 +00:00
|
|
|
return www_tag_unwravel(page);
|
2016-08-21 05:02:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|