/* DBOX Module Copyright (C) 1994-2000 Daniel Kroening Purpose: */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "../online/userlog.h" #include "ostatus.h" #include "webtools.h" typedef struct _ext_table_entry { char *name; char *mime_type; char *mime_encoding; char *icon; } ext_table_entry; #include "mime_table.h" internetaddresst peer; void auth_err(const string &realm) { cout << "HTTP/1.0 401 Keep cool\r\n" "Server: DBOX-WWW Interface\r\n" "WWW-Authenticate: Basic realm=\"" << realm << "\"\r\n" "\r\n"; cout << "\n" "\n" "Access denied!\n" "\n"; cout << "

Access denied!

\n" "

\n"; showcopyright(); endpage(); return; } bool req_auth(httpt &http, const string &realm) { char password[TEXTLEN]; http.basic_auth(status.username, password, TEXTLEN-1); dnstring(status.username); if(status.username[0]==0) { auth_err(realm); return TRUE; } strmaxcpy(status.userprofile.name, status.username, TEXTLEN-1); if(status.userprofile.read()) { auth_err(realm); logf.printf("webonline", "Falscher Username \"%s\"", status.username); return TRUE; } snprintf(status.userlogfile, DIRLEN, "%slogfile", status.userprofile.getpath()); if(verifylogin(&status.userprofile, password)) { auth_err(realm); userlogprintf1(status, "webonline", "Falsches Passwort"); return TRUE; } userlogprintf1(status, "webonline", "Erfolgreiche Authentikation"); userpt up2; get_profiles(status.userprofile, up2, status.gruppe); if(!get_internalflag(status.userprofile, up2, status.gruppe, LOGIN_WEB)) { startpage("DBOX WWW-Interface"); cout << "

Access denied!

\n" "Sie haben keine Berechtigung, " "das Web-Interface zu benutzen!

\n"; userlogprintf1(status, "webonline", "access denied"); showcopyright(); endpage(); return TRUE; } return FALSE; } void makebutton(char *text, char *link, char *target) { char linktext[DIRLEN], *tptr, *tptr2, *tptr3; strmaxcpy(linktext, link, DIRLEN-1); tptr=strchr(linktext, '?'); if(tptr!=NULL) *(tptr++)=0; cout << "

\n"; if(tptr!=NULL) { schleife: tptr2=strchr(tptr, '&'); if(tptr2!=NULL) *(tptr2++)=0; tptr3=strchr(tptr, '='); if(tptr3!=NULL) { *(tptr3++)=0; cout << "\n"; if(tptr2!=NULL) { tptr=tptr2; goto schleife; } } } cout << "
\n"; } char *http_time(time_t t) { struct tm *gmt; time_t when; static char tbuf[128]; when = t ? t : time(NULL); gmt = gmtime(&when); strftime(tbuf, 128, "%a, %d %b %Y %H:%M:%S GMT", gmt); return tbuf; } void print_http_header(ostream &out) { time_t t; time(&t); out << "HTTP/1.0 200 Keep cool\r\n" "MIME-Version: 1.0\r\n" "Server: DBOX-WWW Interface\r\n" "Expires: " << http_time(t-60*60*24) << "\r\n"; out << "Last-modified: " << http_time(t) << "\r\n" "Content-Type: text/html\r\n" "Content-Encoding: binary\r\n" "\r\n"; } void startpage(ostream &out, const string &title) { print_http_header(out); out << "\n" "\n" "" << title << "\n" "\n"; } void startpage(const char *title) { startpage(cout, title); } void endpage(ostream &out) { out << "\n" "\n"; } void endpage() { endpage(cout); } void showcopyright(ostream &out) { out << "
DBOX-WWW Interface, © 1995-2001 " "" "Daniel Kröning

\n"; } void showcopyright() { showcopyright(cout); } void mkgifbutton(const char *gifname, const char *alt, const char *link) { printf("" "\n", link, gifname, alt); } const char *get_mime_type(const char *filename) { int i; const char *extention=strrchr(filename, '.'); if(extention==NULL) return NULL; extention++; for(i=0; i\n" "\n" "Redirection\n" "\n"; out << "click here\n"; endpage(out); }