From 8fff5722138d4b229832787fce07ce8c652b6121 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 18 Feb 2014 22:46:04 +0000 Subject: [PATCH] Remove old CGI --- ilohamail.cgi.c | 25 ---- l.cgi.c | 376 ------------------------------------------------ lists.cgi | 104 -------------- mail.cgi.c | 76 ---------- wishlist.cgi | 57 -------- woozle.mk | 3 +- 6 files changed, 1 insertion(+), 640 deletions(-) delete mode 100644 ilohamail.cgi.c delete mode 100644 l.cgi.c delete mode 100755 lists.cgi delete mode 100644 mail.cgi.c delete mode 100755 wishlist.cgi diff --git a/ilohamail.cgi.c b/ilohamail.cgi.c deleted file mode 100644 index 3c7924f..0000000 --- a/ilohamail.cgi.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include -#include -#include - -const char *basepath = "/usr/share/IlohaMail/source"; - -int -main(int argc, char *argv[]) -{ - char *pathinfo = getenv("PATH_INFO"); - char filename[512]; - - if ((! pathinfo) || - (! strcmp(pathinfo, "/")) || - (0 == strcmp(pathinfo, "/index.html"))) { - pathinfo = "/index.php"; - } - snprintf(filename, sizeof filename, "%s%s", basepath, pathinfo); - setenv("SCRIPT_FILENAME", filename, 1); - setenv("REDIRECT_STATUS", "fuck me", 1); - execl("/usr/bin/php-cgi", filename, NULL); - - return 0; -} diff --git a/l.cgi.c b/l.cgi.c deleted file mode 100644 index 05ffc88..0000000 --- a/l.cgi.c +++ /dev/null @@ -1,376 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -const char *BASE_DIR = "/tmp/clicko"; -const char *BASE_URL = "http://woozle.org/l.cgi"; - - -#define POST_MAX 1024 - -/* - * CGI - */ -static int is_cgi = 0; -static char **argv = NULL; - -static int -read_char_argv() -{ - static int arg = 0; - static char *p; - - if (NULL == argv) { - return EOF; - } - - if (0 == arg) { - arg = 1; - p = argv[1]; - } - - if (! p) { - return EOF; - } else if (! *p) { - arg += 1; - p = argv[arg]; - return '&'; - } - - return *(p++); -} - -static int -read_char_stdin() -{ - static int inlen = -1; - - if (-1 == inlen) { - char *p = getenv("CONTENT_LENGTH"); - if (p) { - inlen = atoi(p); - if (inlen > POST_MAX) { - inlen = POST_MAX; - } - if (inlen < 0) { - inlen = 0; - } - } else { - inlen = 0; - } - } - - if (inlen) { - inlen -= 1; - return getchar(); - } - return EOF; -} - -static int -read_char_query_string() -{ - static char *p = (char *)-1; - - if ((char *)-1 == p) { - p = getenv("QUERY_STRING"); - } - - if (! p) { - return EOF; - } else if (! *p) { - return EOF; - } else { - return *(p++); - } -} - -static int (* read_char)() = read_char_argv; - -int -cgi_init(char *global_argv[]) -{ - char *rm = getenv("REQUEST_METHOD"); - - if (! rm) { - read_char = read_char_argv; - argv = global_argv; - } else if (0 == strcmp(rm, "POST")) { - read_char = read_char_stdin; - is_cgi = 1; - } else if (0 == strcmp(rm, "GET")) { - read_char = read_char_query_string; - is_cgi = 1; - } else { - printf(("405 Method not allowed\r\n" - "Allow: GET, POST\r\n" - "Content-type: text/plain\r\n" - "\r\n" - "%s is not allowed.\n"), - rm); - return -1; - } - - return 0; -} - -static char -tonum(int c) -{ - if ((c >= '0') && (c <= '9')) { - return c - '0'; - } - if ((c >= 'a') && (c <= 'f')) { - return 10 + c - 'a'; - } - if ((c >= 'A') && (c <= 'F')) { - return 10 + c - 'A'; - } - return 0; -} - -static char -read_hex() -{ - int a = read_char(); - int b = read_char(); - - return tonum(a)*16 + tonum(b); -} - -/* Read a key or a value. Since & and = aren't supposed to appear - outside of boundaries, we can use the same function for both. -*/ -size_t -cgi_item(char *str, size_t maxlen) -{ - int c; - size_t pos = 0; - - while (1) { - c = read_char(); - switch (c) { - case EOF: - case '=': - case '&': - str[pos] = '\0'; - return pos; - case '%': - c = read_hex(); - break; - case '+': - c = ' '; - break; - } - if (pos < maxlen - 1) { - str[pos] = c; - pos += 1; - } - } -} - -void -cgi_head(char *title) -{ - if (is_cgi) { - printf("Content-type: text/html\r\n\r\n"); - } - printf(("\n" - "\n" - " %s\n" - " \n" - "

%s

\n"), - title, title); -} - -void -cgi_foot() -{ - printf("\n" - " \n" - "\n"); -} - -void -cgi_result(int code, char *desc, char *fmt, ...) -{ - va_list ap; - - if (is_cgi) { - printf("%d %s\r\n", code, desc); - } - cgi_head(desc); - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); - cgi_foot(); - exit(0); -} - -void -cgi_page(char *title, char *fmt, ...) -{ - va_list ap; - - cgi_head(title); - va_start(ap, fmt); - vprintf(fmt, ap); - va_end(ap); - cgi_foot(); - exit(0); -} - -void -cgi_error(char *text) -{ - cgi_result(500, "Internal error", "

%s

", text); -} - - -static FILE * -open_file(char *shorty, char *mode) -{ - char fn[256]; - FILE *f; - - snprintf(fn, sizeof fn, "%s/%s.url", BASE_DIR, shorty); - - f = fopen(fn, mode); - if (! f) { - cgi_error("Unable to open database"); - } - - return f; -} - -void -shorten_url() -{ - char u[4096]; - size_t ulen; - char shorty[16]; - - ulen = cgi_item(u, sizeof u); - if (ulen == 0) { - cgi_error("No URL specified"); - } - - snprintf(shorty, sizeof shorty, "%08x.%04x", (unsigned int)time(NULL), getpid()); - - /* Put the URL into a file */ - { - FILE *f = open_file(shorty, "w"); - fprintf(f, "%s", u); - fclose(f); - } - - /* Report back */ - printf("Content-type: text/plain\r\n\r\n"); - printf("%s/%s\n", BASE_URL, shorty); -} - - -void -redirect(char *pi) -{ - int i; - - if (! pi) { - cgi_error("No short URL provided"); - } - - if (pi[0] != '/') { - cgi_error("Invalid PATH_INFO"); - } - pi += 1; - - for (i = 0; pi[i]; i += 1) { - if ((! isalnum(pi[i])) && - (pi[i] != '.')) { - cgi_error("Bad short URL"); - } - } - - /* Open file */ - { - char u[4096]; - FILE *f = open_file(pi, "r"); - - fgets(u, sizeof u, f); - fclose(f); - - printf("Location: %s\r\n", u); - } -} - - -void -list_links() -{ - char g[256]; - glob_t globbuf; - int i; - - snprintf(g, sizeof g, "%s/*.url", BASE_DIR); - - glob(g, 0, NULL, &globbuf); - - cgi_head("Clicko history"); - printf("
    \n"); - for (i = globbuf.gl_pathc - 1; i >= 0; i -= 1) { - FILE *f = fopen(globbuf.gl_pathv[i], "r"); - char url[4096]; - - fgets(url, sizeof url, f); - fclose(f); - - printf("
  • %s
  • \n", url, url); - } - printf("
\n"); - cgi_foot(); -} - -int -main(int argc, char *argv[]) -{ - if (-1 == cgi_init(argv)) { - fprintf(stderr, "Unable to initialize CGI.\n"); - return -1; - } - - while (1) { - char key[12]; - size_t klen; - - klen = cgi_item(key, sizeof key); - if (klen == 0) { - break; - } - switch (key[0]) { - case 'u': - shorten_url(); - return 0; - } - } - - { - char *pi = getenv("PATH_INFO"); - - if (pi) { - redirect(pi); - } - } - - list_links(); - - return 0; -} diff --git a/lists.cgi b/lists.cgi deleted file mode 100755 index 0cac0df..0000000 --- a/lists.cgi +++ /dev/null @@ -1,104 +0,0 @@ -#! /usr/bin/python - -import cgitb; cgitb.enable() -import cgi -import os -import sys -import glob -import re -import smtplib - -f = cgi.FieldStorage() - -l = f.getfirst('l') -if not l: - l = os.environ.get('PATH_INFO', '/')[1:] - -desc_re = re.compile(r'List-Id: "?([^<]*)"? <') -def getdesc(d): - fn = '%s/control/customheaders' % d - try: - hdrs = file(fn).read() - except IOError: - return '(none)' - ret = desc_re.search(hdrs) - if ret: - return cgi.escape(ret.group(1)).replace('#', '') - else: - return '(none)' - -listdir = '/var/spool/mlmmj/%s' % l -if l and os.path.isdir(os.path.join(listdir, 'control')): - title = '%s membership' % l - a = f.getfirst('a') - addr = f.getfirst('addr') - - if ((a == 'subscribe') or (a == 'unsubscribe')) and addr: - server = smtplib.SMTP('localhost') - faddr = addr - taddr = '%s-%s@woozle.org' % (l, a) - try: - server.sendmail(faddr, - [taddr], - 'From: %s\nTo: %s\n\n' % (faddr, taddr)) - content = '

I have sent a confirmation message to %s. ' % addr - content += 'It should be in your mailbox shortly.

' - except Exception, err: - content = "

Uh oh. That didn't work.

" - content += "
%s
" % cgi.escape(str(err)) - else: - content = '

%s@woozle.org' % l - content += ": %s" % getdesc(listdir) - content += '

' - content += '

To subscribe to or unsubscribe from the %s list,' % l - content += ' just enter your email address in this handy dandy form!

' - content += '
' - content += ' ' % l - content += ' Email address: ' - content += ' ' - content += ' ' - content += '
' - if os.path.exists(os.path.join(listdir, 'control', 'archive')): - content += "

Message archive

" % l -else: - title = 'Email lists' - - content = '

Public email lists on this host

' - content += '' - content += ' ' - content += ' ' - content += ' ' - content += ' ' - content += ' ' - content += ' ' - content += ' ' - content += ' ' - - for d in sorted(glob.glob('/var/spool/mlmmj/*')): - if os.path.islink(d): - continue - if os.path.exists('%s/control/private' % d): - continue - - l = os.path.basename(d) - content += '' % (l, l) - content += '' % getdesc(d) - content += '\n' - - content += ' ' - content += '
listdescriptionactions
%s%s
' - content += ' ' - content += '
' % l - content += ' ' - content += ' ' - content += '
' - if os.path.exists('%s/control/archive' % d): - content += 'view archive' % l - content += '
' - -print 'Content-type: text/html' -print -sys.stdout.flush() -p = os.popen('m4 -DTITLE="%s" template.html.m4 -' % title, 'w') -p.write(content) -p.close() diff --git a/mail.cgi.c b/mail.cgi.c deleted file mode 100644 index 292cf11..0000000 --- a/mail.cgi.c +++ /dev/null @@ -1,76 +0,0 @@ -#include -#include -#include -#include - -const char *baseurl = "https://woozle.org/mail.cgi/"; -const char *basepath = "/opt/roundcubemail"; -//const char *basepath = "/usr/share/IlohaMail/source"; - -int -main(int argc, char *argv[]) -{ - char *pathinfo = getenv("PATH_INFO"); - char *remaddr = getenv("REMOTE_ADDR"); - size_t pathlen = pathinfo?strlen(pathinfo):0; - char filename[512]; - char *ext; - - if ((! pathinfo) || (! remaddr) || (! getenv("HTTPS"))) { - printf("Location: %s\n", baseurl); - return 0; - } else if (0 == strcmp(pathinfo, "/index.html")) { - snprintf(filename, sizeof filename, "%s/index.php", basepath); - } else if (pathinfo[pathlen-1] == '/') { - snprintf(filename, sizeof filename, "%s%sindex.php", basepath, pathinfo); - } else { - snprintf(filename, sizeof filename, "%s%s", basepath, pathinfo); - } - - ext = strrchr(filename, '.'); - if (! ext) { - ext = ""; - } - - if (0 == strcmp(ext, ".php")) { - setenv("SCRIPT_FILENAME", filename, 1); - setenv("REDIRECT_STATUS", "fuck me", 1); - execl("/usr/bin/php-cgi", filename, NULL); - } else if (strstr(filename, "/config/") || - strstr(filename, "/logs/") || - strstr(filename, "/temp/")) { - printf("Content-type: text/plain\n\n[MESSAGE REDACTED]\n"); - } else { - FILE *f = fopen(filename, "r"); - char *ct = "application/octet-stream"; - - if (0 == strcmp(ext, ".css")) { - ct = "text/css"; - } else if (0 == strcmp(ext, ".html")) { - ct = "text/html"; - } else if (0 == strcmp(ext, ".js")) { - ct = "application/javascript"; - } else if (0 == strcmp(ext, ".png")) { - ct = "image/png"; - } else if (0 == strcmp(ext, ".jpg")) { - ct = "image/jpeg"; - } else if (0 == strcmp(ext, ".gif")) { - ct = "image/gif"; - } - - printf("Content-type: %s\n\n", ct); - - while (! feof(f)) { - char buf[4096]; - size_t len; - - - len = fread(buf, 1, sizeof buf, f); - if (len) { - fwrite(buf, 1, len, stdout); - } - } - } - - return 0; -} diff --git a/wishlist.cgi b/wishlist.cgi deleted file mode 100755 index b984314..0000000 --- a/wishlist.cgi +++ /dev/null @@ -1,57 +0,0 @@ -#! /usr/bin/python - -import cgitb; cgitb.enable() -import cgi -import glob -import os -import sys -import markdown - -BASE = '/var/lib/wishlists' - -f = cgi.FieldStorage() - -title = 'Wishlists' -content = [] - -u = f.getfirst('u') -p = f.getfirst('p') - -if u: - if p: - if p.lower() not in ('dingo', 'jada'): - content.append("

I'm sorry but that is not the right answer.

") - else: - txt = f.getfirst('txt') - open(os.path.join(BASE, u), 'w').write(txt) - content.append('

Okay, thanks!

') - content.append('

Back to wishlists

') - else: - title = "%s's Wishlist" % cgi.escape(u) - txt = open(os.path.join(BASE, u)).read() - content.append('
') - content.append('' % u) - content.append('' % cgi.escape(txt)) - content.append('
') - content.append('What is the name of Amy and Neale\'s dog?') - content.append('') - content.append('') - content.append('
') - content.append('

Formatting overview:

') - content.append('
* Item')
-        content.append('* Second item')
-        content.append('* Item with [a link](http://example.com/)')
-        content.append('* <del>A spoken-for item</del>
') -else: - for fn in sorted(glob.glob(os.path.join(BASE, '*'))): - u = os.path.basename(fn) - content.append("

%s

" % cgi.escape(u)) - content.append(markdown.markdown(open(fn).read())) - content.append('

edit

' % u) - -print 'Content-type: text/html' -print -sys.stdout.flush() -p = os.popen('m4 -DTITLE="%s" template.html.m4 -' % title, 'w') -p.write('\n'.join(content)) -p.close() diff --git a/woozle.mk b/woozle.mk index 4fa2930..737015a 100644 --- a/woozle.mk +++ b/woozle.mk @@ -1,6 +1,5 @@ PLAIN += . -COPY += icon.png style.css style-black.css lists.cgi wishlist.cgi set.cgi $(TEMPLATE) -COPY += mail.cgi ilohamail.cgi l.cgi +COPY += icon.png style.css style-black.css set.cgi $(TEMPLATE) COPY += google7f698b9893809122.html HTML += people.html COPY += robots.txt