#include <stdarg.h>
#include "webcit.h"
#include "child.h"
+#include "mime_parser.h"
int wc_session;
-char wc_host[256];
-char wc_port[256];
char wc_username[256];
char wc_password[256];
char wc_roomname[256];
int logged_in = 0;
int axlevel;
char *ExpressMessages = NULL;
+int noframes = 0;
struct webcontent *wlist = NULL;
struct webcontent *wlast = NULL;
static const char *defaulthost = DEFAULT_HOST;
static const char *defaultport = DEFAULT_PORT;
+int upload_length = 0;
+char *upload;
+
void unescape_input(char *buf)
{
return(len);
}
-void wDumpContent(void) {
+void wDumpContent(int print_standard_html_footer) {
struct webcontent *wptr;
+ if (print_standard_html_footer) {
+ if (noframes) {
+ wprintf("<BR>");
+ embed_main_menu();
+ }
+ wprintf("</BODY></HTML>\n");
+ }
+
printf("Content-type: text/html\n");
printf("Content-length: %d\n", wContentLength());
printf("\n");
/*
* Output all that important stuff that the browser will want to see
+ *
+ * If print_standard_html_head is nonzero, we also get some standard HTML
+ * headers. If it's set to 2, the session is considered to be closing.
*/
-void output_headers(int print_standard_html_head) {
+void output_headers(int print_standard_html_head, char *target) {
static char *unset = "; expires=28-May-1971 18:10:00 GMT";
+ char cookie[256];
printf("Server: %s\n", SERVER);
printf("Connection: close\n");
- printf("Set-cookie: wc_session=%d\n", wc_session);
-
- if (strlen(wc_host)>0) printf("Set-cookie: wc_host=%s\n", wc_host);
- else printf("Set-cookie: wc_host=%s\n", unset);
- if (strlen(wc_port)>0) printf("Set-cookie: wc_port=%s\n", wc_port);
- else printf("Set-cookie: wc_port=%s\n", unset);
+ if ( (strlen(target)>0) && (noframes == 0) ) {
+ printf("Window-target: %s\n", target);
+ }
- if (strlen(wc_username)>0) printf("Set-cookie: wc_username=%s\n",
- wc_username);
- else printf("Set-cookie: wc_username=%s\n", unset);
- if (strlen(wc_password)>0) printf("Set-cookie: wc_password=%s\n",
- wc_password);
- else printf("Set-cookie: wc_password=%s\n", unset);
+ if (print_standard_html_head > 0) {
+ printf("Pragma: no-cache\n");
+ printf("Cache-Control: no-store\n");
+ }
- if (strlen(wc_roomname)>0) printf("Set-cookie: wc_roomname=%s\n",
- wc_roomname);
- else printf("Set-cookie: wc_roomname=%s\n", unset);
+ stuff_to_cookie(cookie, wc_session, wc_username, wc_password,
+ wc_roomname, noframes);
+ if (print_standard_html_head==2) {
+ printf("X-WebCit-Session: close\n");
+ printf("Set-cookie: webcit=%s\n", unset);
+ }
+ else {
+ printf("Set-cookie: webcit=%s\n", cookie);
+ }
- if (print_standard_html_head) {
+ if (print_standard_html_head > 0) {
wprintf("<HTML><HEAD><TITLE>");
escputs("WebCit"); /* FIX -- add BBS name here */
wprintf("</TITLE></HEAD>");
fp = fopen(buf, "rb");
if (fp == NULL) {
printf("HTTP/1.0 404 %s\n", strerror(errno));
- output_headers(0);
+ output_headers(0, "");
printf("Content-Type: text/plain\n");
sprintf(buf, "%s: %s\n", what, strerror(errno));
printf("Content-length: %d\n", strlen(buf));
}
else {
printf("HTTP/1.0 200 OK\n");
- output_headers(0);
+ output_headers(0, "");
if (!strncasecmp(&what[strlen(what)-4], ".gif", 4))
printf("Content-type: image/gif\n");
if (buf[0]=='2') {
bytes = extract_long(&buf[4], 0);
printf("HTTP/1.0 200 OK\n");
- output_headers(0);
+ output_headers(0, "");
printf("Content-type: image/gif\n");
printf("Content-length: %ld\n", bytes);
printf("\n");
}
else {
printf("HTTP/1.0 404 %s\n", strerror(errno));
- output_headers(0);
+ output_headers(0, "");
printf("Content-Type: text/plain\n");
sprintf(buf, "Error retrieving image\n");
printf("Content-length: %d\n", strlen(buf));
/*
- * Convenience function to display a page containing only an error string
+ * Convenience functions to display a page containing only a string
*/
-void display_error(char *errormessage) {
+void convenience_page(char *titlebarcolor, char *titlebarmsg, char *messagetext) {
printf("HTTP/1.0 200 OK\n");
- output_headers(1);
- wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=770000><TR><TD>");
+ output_headers(1, "bottom");
+ wprintf("<TABLE WIDTH=100% BORDER=0 BGCOLOR=%s><TR><TD>", titlebarcolor);
wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
- wprintf("<B>Error</B>\n");
+ wprintf("<B>%s</B>\n", titlebarmsg);
wprintf("</FONT></TD></TR></TABLE><BR>\n");
- escputs(errormessage);
- wprintf("</BODY></HTML>\n");
- wDumpContent();
+ escputs(messagetext);
+
+ if (noframes) {
+ wprintf("<HR>\n");
+ embed_main_menu();
+ }
+
+ wDumpContent(1);
}
+void display_error(char *errormessage) {
+ convenience_page("770000", "Error", errormessage);
+ }
+
+void display_success(char *successmessage) {
+ convenience_page("007700", "OK", successmessage);
+ }
}
+void upload_handler(char *name, char *filename, char *encoding,
+ void *content, char *cbtype, size_t length) {
+
+ fprintf(stderr, "UPLOAD HANDLER CALLED\n");
+ fprintf(stderr, " name = %s\n", name);
+ fprintf(stderr, "filename = %s\n", filename);
+ fprintf(stderr, "encoding = %s\n", encoding);
+ fprintf(stderr, " type = %s\n", cbtype);
+ fprintf(stderr, " length = %d\n", length);
+
+ if (strlen(name)>0) {
+ upload = malloc(length);
+ if (upload != NULL) {
+ upload_length = length;
+ memcpy(upload, content, length);
+ }
+ }
+
+ }
+
+
void session_loop(void) {
char cmd[256];
char action[256];
char buf[256];
int a, b;
int ContentLength = 0;
+ char ContentType[512];
char *content;
-FILE *fp;
/* We stuff these with the values coming from the client cookies,
* so we can use them to reconnect a timed out session if we have to.
char c_username[256];
char c_password[256];
char c_roomname[256];
+ char cookie[256];
strcpy(c_host, defaulthost);
strcpy(c_port, defaultport);
strcpy(c_password, "");
strcpy(c_roomname, "");
+ upload_length = 0;
+ upload = NULL;
+
getz(cmd);
extract_action(action, cmd);
do {
getz(buf);
- if (!strncasecmp(buf, "Cookie: wc_host=", 16))
- strcpy(c_host, &buf[16]);
- if (!strncasecmp(buf, "Cookie: wc_port=", 16))
- strcpy(c_port, &buf[16]);
- if (!strncasecmp(buf, "Cookie: wc_username=", 20))
- strcpy(c_username, &buf[20]);
- if (!strncasecmp(buf, "Cookie: wc_password=", 20))
- strcpy(c_password, &buf[20]);
- if (!strncasecmp(buf, "Cookie: wc_roomname=", 20))
- strcpy(c_roomname, &buf[20]);
+ if (!strncasecmp(buf, "Cookie: webcit=", 15)) {
+ strcpy(cookie, &buf[15]);
+ cookie_to_stuff(cookie, NULL,
+ c_username, c_password, c_roomname,
+ &noframes);
+ }
if (!strncasecmp(buf, "Content-length: ", 16)) {
ContentLength = atoi(&buf[16]);
}
-
+ if (!strncasecmp(buf, "Content-type: ", 14)) {
+ strcpy(ContentType, &buf[14]);
+ }
} while(strlen(buf)>0);
++TransactionCount;
if (ContentLength > 0) {
content = malloc(ContentLength+1);
fread(content, ContentLength, 1, stdin);
-fp = fopen("content", "wb");
-fwrite(content, ContentLength, 1, fp);
-fclose(fp);
+
content[ContentLength] = 0;
- addurls(content);
+
+ if (!strncasecmp(ContentType,
+ "application/x-www-form-urlencoded", 33)) {
+ addurls(content);
+ }
+ else if (!strncasecmp(ContentType, "multipart", 9)) {
+ mime_parser(content, ContentLength, ContentType,
+ *upload_handler);
+ }
}
else {
content = NULL;
}
+ /* If there are variables in the URL, we must grab them now */
+ for (a=0; a<strlen(cmd); ++a) if ((cmd[a]=='?')||(cmd[a]=='&')) {
+ for (b=a; b<strlen(cmd); ++b) if (isspace(cmd[b])) cmd[b]=0;
+ addurls(&cmd[a+1]);
+ cmd[a] = 0;
+ }
+
/*
* If we're not connected to a Citadel server, try to hook up the
* connection now. Preference is given to the host and port specified
* by browser cookies, if cookies have been supplied.
*/
if (!connected) {
+ if (strlen(bstr("host"))>0) strcpy(c_host, bstr("host"));
+ if (strlen(bstr("port"))>0) strcpy(c_port, bstr("port"));
serv_sock = connectsock(c_host, c_port, "tcp");
connected = 1;
serv_gets(buf); /* get the server welcome message */
- strcpy(wc_host, c_host);
- strcpy(wc_port, c_port);
get_serv_info();
}
}
}
- /* If there are variables in the URL, we must grab them now */
- for (a=0; a<strlen(cmd); ++a) if ((cmd[a]=='?')||(cmd[a]=='&')) {
- for (b=a; b<strlen(cmd); ++b) if (isspace(cmd[b])) cmd[b]=0;
- addurls(&cmd[a+1]);
- cmd[a] = 0;
- }
-
if (!strcasecmp(action, "static")) {
strcpy(buf, &cmd[12]);
for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
validate();
}
+ else if (!strcasecmp(action, "display_editpic")) {
+ display_graphics_upload("your photo",
+ "UIMG 0|_userpic_",
+ "/editpic");
+ }
+
+ else if (!strcasecmp(action, "editpic")) {
+ do_graphics_upload("UIMG 1|_userpic_");
+ }
+
+ else if (!strcasecmp(action, "display_editroompic")) {
+ display_graphics_upload("the graphic for this room",
+ "UIMG 0|_roompic_",
+ "/editroompic");
+ }
+
+ else if (!strcasecmp(action, "editroompic")) {
+ do_graphics_upload("UIMG 1|_roompic_");
+ }
+
+ else if (!strcasecmp(action, "select_floor_to_edit_pic")) {
+ select_floor_to_edit_pic();
+ }
+
+ else if (!strcasecmp(action, "display_editfloorpic")) {
+ sprintf(buf, "UIMG 0|_floorpic_|%s",
+ bstr("which_floor"));
+ display_graphics_upload("the graphic for this floor",
+ buf,
+ "/editfloorpic");
+ }
+
+ else if (!strcasecmp(action, "editfloorpic")) {
+ sprintf(buf, "UIMG 1|_floorpic_|%s",
+ bstr("which_floor"));
+ do_graphics_upload(buf);
+ }
+
+ else if (!strcasecmp(action, "display_reg")) {
+ display_reg(0);
+ }
+
+ else if (!strcasecmp(action, "register")) {
+ register_user();
+ }
+
+ else if (!strcasecmp(action, "display_changepw")) {
+ display_changepw();
+ }
+
+ else if (!strcasecmp(action, "changepw")) {
+ changepw();
+ }
+
+ else if (!strcasecmp(action, "display_edit_node")) {
+ display_edit_node();
+ }
+
+ else if (!strcasecmp(action, "display_netconf")) {
+ display_netconf();
+ }
+
+ else if (!strcasecmp(action, "display_confirm_unshare")) {
+ display_confirm_unshare();
+ }
+
+ else if (!strcasecmp(action, "display_confirm_delete_node")) {
+ display_confirm_delete_node();
+ }
+
+ else if (!strcasecmp(action, "delete_node")) {
+ delete_node();
+ }
+
+ else if (!strcasecmp(action, "unshare")) {
+ unshare();
+ }
+
+ else if (!strcasecmp(action, "display_add_node")) {
+ display_add_node();
+ }
+
+ else if (!strcasecmp(action, "add_node")) {
+ add_node();
+ }
+
+ else if (!strcasecmp(action, "display_share")) {
+ display_share();
+ }
+
+ else if (!strcasecmp(action, "share")) {
+ share();
+ }
+
+ else if (!strcasecmp(action, "terminate_session")) {
+ terminate_session();
+ }
+
+ else if (!strcasecmp(action, "edit_me")) {
+ edit_me();
+ }
+
+ else if (!strcasecmp(action, "display_siteconfig")) {
+ display_siteconfig();
+ }
+
+ else if (!strcasecmp(action, "siteconfig")) {
+ siteconfig();
+ }
+
+ else if (!strcasecmp(action, "display_generic")) {
+ display_generic();
+ }
+
+ else if (!strcasecmp(action, "do_generic")) {
+ do_generic();
+ }
+
/* When all else fails... */
else {
printf("HTTP/1.0 200 OK\n");
- output_headers(1);
+ output_headers(1, "");
wprintf("TransactionCount is %d<BR>\n", TransactionCount);
wprintf("You're in session %d<HR>\n", wc_session);
wprintf("Variables: <BR><PRE>\n");
dump_vars();
wprintf("</PRE><HR>\n");
- wprintf("</BODY></HTML>\n");
- wDumpContent();
+ wDumpContent(1);
}
fflush(stdout);
content = NULL;
}
free_urls();
+ if (upload_length > 0) {
+ free(upload);
+ upload_length = 0;
+ }
}
int main(int argc, char *argv[]) {
defaultport = argv[3];
}
- strcpy(wc_host, "");
- strcpy(wc_port, "");
strcpy(wc_username, "");
strcpy(wc_password, "");
strcpy(wc_roomname, "");