From b6ecf4698e25b92b5b2c7bcf11d28e7ec9d64038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anton=20Luka=20=C5=A0ijanec?= Date: Sun, 15 May 2022 23:35:32 +0200 Subject: compiles, untested --- .gitignore | 1 + Makefile | 6 +- hp.html | 54 ++++++++++ lib.c | 73 +++++++++++++ prijave.c | 347 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- prijave.conf | 3 + 6 files changed, 464 insertions(+), 20 deletions(-) create mode 100644 hp.html create mode 100644 lib.c diff --git a/.gitignore b/.gitignore index 2623084..910f061 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ prijave core sqlite3 +.gdb_history diff --git a/Makefile b/Makefile index a49d1dc..2007c1b 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,11 @@ PROJ = prijave .NOTPARALLEL: default: $(CC) -L. $(cflags) $(CFLAGS) $(PROJ).c $(ldflags) $(LDFLAGS) -o$(PROJ) -install: - mkdir -p $(DESTDIR)/usr/bin $(DESTDIR)/etc + +install: default + mkdir -p $(DESTDIR)/usr/bin $(DESTDIR)/etc $(DESTDIR)/usr/share/$(PROJ) cp $(PROJ) $(DESTDIR)/usr/bin/ + cp *.html $(DESTDIR)/usr/share/$(PROJ)/ -[ ! -f $(DESTDIR)/etc/$(PROJ) ] && cp $(PROJ).conf $(DESTDIR)/etc/$(PROJ) distclean: clean diff --git a/hp.html b/hp.html new file mode 100644 index 0000000..5aefc61 --- /dev/null +++ b/hp.html @@ -0,0 +1,54 @@ + + + + + prijave :: glavna stran + + + +

+ prijave +

+
+ + +
+ + +
+ + +
+ +
+ +
+ + + gesla so shranjena kot golo besedilo + +
+

+ iskanje obstoječih obrazcev z geslom +

+
+ + +
+ +
+ + + diff --git a/lib.c b/lib.c new file mode 100644 index 0000000..2dea5a9 --- /dev/null +++ b/lib.c @@ -0,0 +1,73 @@ +#include +// functions from http://git.sijanec.eu/sijanec/sear.c +static int urlencode (char * o, const char * i /* o must have at least strlen(i)*3+1 bytes of memory allocated */) { + if (!o || !i) + return -2; + size_t written = 0; /* o CANNOT be equal to i, unlike in urldecode */ + for (; *i; i++) { + if (isalnum(*i) || *i == '.' || *i == '_' || *i == '-' || *i == '~') { + o[written++] = *i; + } else { + sprintf(o+written, "%%%02X", (unsigned char) *i); + written += 3; + } + } + o[written++] = '\0'; + return 1; +} +__attribute__((unused)) static int urldecode (char * o, const char * i /* o must have at least strlen(i)+1 bytes memory allocated */) { + if (!o || !i) + return -2; + size_t written = 0; /* o can be equal to i for decoding in-place */ + char buf[] = "00"; + for (; *i; i++) { + if (*i == '%') { + buf[0] = *++i; + buf[1] = *++i; + if (!buf[0] || !buf[1]) { /* malformed */ + o[written++] = '\0'; + return -1; + } + o[written++] = strtol(buf, NULL, 16); + } else { + o[written++] = *i; + } + } + o[written++] = '\0'; + return 1; +} +static char * htmlspecialchars (const char * i) { /* remember to free the output */ + if (!i) + return NULL; + size_t s = 128; + char * o = malloc(s); + if (!o) + return NULL; + size_t w = 0; + for (; *i; i++) { + if (s - w <= 10) { + char * old = o; + o = realloc(o, (s *= 1.5)); + if (!o) { + free(old); + return NULL; + } + } + switch (*i) { + case '<': + w += sprintf(o+w, "<"); + break; + case '"': + w += sprintf(o+w, """); + break; + case '\'': + w += sprintf(o+w, "'"); + break; + default: + o[w++] = *i; + break; + } + } + o[w++] = '\0'; + return o; +} diff --git a/prijave.c b/prijave.c index d16c8c6..b8cdac5 100644 --- a/prijave.c +++ b/prijave.c @@ -8,15 +8,25 @@ #include #include #include +#include +#include +#include +#include +#include #ifndef PR_PORT #define PR_PORT "7745" #endif #define STRA(x) #x #define STR(x) STRA(x) +#define HTML_START(page) "" page " :: prijave" +#define HTML_END "