/* * This is the sending side of the chat window. The form is designed to transmit asynchronously. */ void chat_send(void) { char send_this[SIZ]; char buf[SIZ]; begin_ajax_response(); if (havebstr("send_this")) { strcpy(send_this, bstr("send_this")); } else { strcpy(send_this, ""); } if (havebstr("exit_button")) { strcpy(send_this, "/quit"); } if (!IsEmptyStr(send_this)) { serv_puts("RCHT send"); serv_getln(buf, sizeof buf); if (buf[0] == '4') { text_to_server(send_this); serv_puts("000"); } } end_ajax_response(); }
/* * Attempt to attach an OpenID to an existing, logged-in account */ void openid_attach(void) { char buf[4096]; if (havebstr("attach_button")) { syslog(LOG_DEBUG, "Attempting to attach %s\n", bstr("openid_url")); snprintf(buf, sizeof buf, "OIDS %s|%s/finalize_openid_login?attach_existing=1|%s", bstr("openid_url"), ChrPtr(site_prefix), ChrPtr(site_prefix) ); serv_puts(buf); serv_getln(buf, sizeof buf); if (buf[0] == '2') { syslog(LOG_DEBUG, "OpenID server contacted; redirecting to %s\n", &buf[4]); http_redirect(&buf[4]); return; } else { syslog(LOG_DEBUG, "OpenID attach failed: %s\n", &buf[4]); } } /* If we get to this point then something failed. */ display_openids(); }
// upload the picture (icon, photo, whatever) associated with the current room void common_code_for_editroompic_and_editpic(char *servcmd) { if (havebstr("cancel_button")) { AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WC->upload_length == 0) { AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } serv_printf("%s %ld|%s", servcmd, (long)WC->upload_length, GuessMimeType(ChrPtr(WC->upload), WC->upload_length)); StrBuf *Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 0, 0) == 7) { serv_write(ChrPtr(WC->upload), WC->upload_length); display_success(ChrPtr(Line) + 4); } else { AppendImportantMessage((ChrPtr(Line) + 4), -1); display_main_menu(); } FreeStrBuf(&Line); }
void do_graphics_upload(char *filename) { StrBuf *Line; const char *MimeType; wcsession *WCC = WC; int bytes_remaining; int pos = 0; int thisblock; bytes_remaining = WCC->upload_length; if (havebstr("cancel_button")) { AppendImportantMessage(_("Graphics upload has been cancelled."), -1); display_main_menu(); return; } if (WCC->upload_length == 0) { AppendImportantMessage(_("You didn't upload a file."), -1); display_main_menu(); return; } MimeType = GuessMimeType(ChrPtr(WCC->upload), bytes_remaining); serv_printf("UIMG 1|%s|%s", MimeType, filename); Line = NewStrBuf(); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 2) != 2) { display_main_menu(); FreeStrBuf(&Line); return; } while (bytes_remaining) { thisblock = ((bytes_remaining > 4096) ? 4096 : bytes_remaining); serv_printf("WRIT %d", thisblock); StrBuf_ServGetln(Line); if (GetServerStatusMsg(Line, NULL, 1, 7) != 7) { serv_puts("UCLS 0"); StrBuf_ServGetln(Line); display_main_menu(); FreeStrBuf(&Line); return; } thisblock = extract_int(ChrPtr(Line) +4, 0); serv_write(&ChrPtr(WCC->upload)[pos], thisblock); pos += thisblock; bytes_remaining -= thisblock; } serv_puts("UCLS 1"); StrBuf_ServGetln(Line); if (*ChrPtr(Line) != 'x') { display_success(ChrPtr(Line) + 4); } FreeStrBuf(&Line); }
NodeConf *HttpGetNewNode(void) { NodeConf *Node; if (!havebstr("node") || !havebstr("secret")|| !havebstr("host")|| !havebstr("port")) return NULL; Node = (NodeConf *) malloc(sizeof(NodeConf)); Node->DeleteMe = 0; Node->NodeName = NewStrBufDup(sbstr("node")); Node->Secret = NewStrBufDup(sbstr("secret")); Node->Host = NewStrBufDup(sbstr("host")); Node->Port = NewStrBufDup(sbstr("port")); return Node; }
/* * Detach an OpenID from the currently logged-in account */ void openid_detach(void) { StrBuf *Line; if (havebstr("id_to_detach")) { serv_printf("OIDD %s", bstr("id_to_detach")); Line = NewStrBuf(); StrBuf_ServGetln(Line); GetServerStatusMsg(Line, NULL, 1, 2); FreeStrBuf(&Line); } display_openids(); }
/* * edit a network node */ void edit_node(void) { HashList *NodeConfig; const StrBuf *Index; NodeConf *NewNode; if (havebstr("ok_button")) { Index = sbstr("index"); NewNode = HttpGetNewNode(); if ((NewNode == NULL) || (Index == NULL)) { AppendImportantMessage(_("Invalid Parameter"), -1); url_do_template(); return; } NodeConfig = load_netconf(NULL, &NoCtx); Put(NodeConfig, ChrPtr(Index), StrLength(Index), NewNode, DeleteNodeConf); save_net_conf(NodeConfig); DeleteHash(&NodeConfig); } url_do_template(); }
/* * Display the appropriate landing page for this site. */ void display_default_landing_page(void) { wcsession *WCC = WC; if (WCC && WCC->serv_info && WCC->serv_info->serv_supports_guest) { /* default action */ if (havebstr("go")) { if (verbose) syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go")); smart_goto(sbstr("go")); } else if (default_landing_page) { http_redirect(default_landing_page); } else { StrBuf *teh_lobby = NewStrBufPlain(HKEY("_BASEROOM_")); smart_goto(teh_lobby); FreeStrBuf(&teh_lobby); } } else { display_login(); } }
/* * Entry point for WebCit transaction */ void session_loop(void) { int xhttp; StrBuf *Buf; /* * 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. */ wcsession *WCC; WCC= WC; WCC->upload_length = 0; WCC->upload = NULL; WCC->Hdr->nWildfireHeaders = 0; if (WCC->Hdr->HR.ContentLength > 0) { if (ReadPostData() < 0) { return; } } Buf = NewStrBuf(); WCC->trailing_javascript = NewStrBuf(); /* Convert base64-encoded URL's back to plain text */ if (!strncmp(ChrPtr(WCC->Hdr->this_page), "/B64", 4)) { StrBufCutLeft(WCC->Hdr->this_page, 4); StrBufDecodeBase64(WCC->Hdr->this_page); http_redirect(ChrPtr(WCC->Hdr->this_page)); goto SKIP_ALL_THIS_CRAP; } /* If there are variables in the URL, we must grab them now */ if (WCC->Hdr->PlainArgs != NULL) ParseURLParams(WCC->Hdr->PlainArgs); /* If the client sent a nonce that is incorrect, kill the request. */ if (havebstr("nonce")) { if (verbose) syslog(LOG_DEBUG, "Comparing supplied nonce %s to session nonce %d", bstr("nonce"), WCC->nonce ); if (ibstr("nonce") != WCC->nonce) { syslog(LOG_INFO, "Ignoring request with mismatched nonce."); hprintf("HTTP/1.1 404 Security check failed\r\n"); hprintf("Content-Type: text/plain\r\n"); begin_burst(); wc_printf("Security check failed.\r\n"); end_burst(); goto SKIP_ALL_THIS_CRAP; } } /* * If we're not connected to a Citadel server, try to hook up the connection now. */ if (!WCC->connected) { if (GetConnected()) { hprintf("HTTP/1.1 503 Service Unavailable\r\n"); hprintf("Content-Type: text/html\r\n"); begin_burst(); wc_printf("<html><head><title>503 Service Unavailable</title></head><body>\n"); wc_printf(_("This program was unable to connect or stay " "connected to the Citadel server. Please report " "this problem to your system administrator.") ); wc_printf("<br>"); wc_printf("<a href=\"http://www.citadel.org/doku.php/" "faq:generalquestions:webcit_unable_to_connect\">%s</a>", _("Read More...") ); wc_printf("</body></html>\n"); end_burst(); goto SKIP_ALL_THIS_CRAP; } } /* * If we're not logged in, but we have authentication data (either from * a cookie or from http-auth), try logging in to Citadel using that. */ if ( (!WCC->logged_in) && (StrLength(WCC->Hdr->c_username) > 0) && (StrLength(WCC->Hdr->c_password) > 0) ) { long Status; FlushStrBuf(Buf); serv_printf("USER %s", ChrPtr(WCC->Hdr->c_username)); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, &Status) == 3) { serv_printf("PASS %s", ChrPtr(WCC->Hdr->c_password)); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 2) { become_logged_in(WCC->Hdr->c_username, WCC->Hdr->c_password, Buf); } else { /* Should only display when password is wrong */ WCC->ImportantMsg = NewStrBufPlain(ChrPtr(Buf) + 4, StrLength(Buf) - 4); authorization_required(); FreeStrBuf(&Buf); goto SKIP_ALL_THIS_CRAP; } } else if (Status == 541) { WCC->logged_in = 1; } } xhttp = (WCC->Hdr->HR.eReqType != eGET) && (WCC->Hdr->HR.eReqType != ePOST) && (WCC->Hdr->HR.eReqType != eHEAD); /* * If a 'go' (or 'gotofirst') parameter has been specified, attempt to goto that room * prior to doing anything else. */ if (havebstr("go")) { int ret; if (verbose) syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("go")); ret = gotoroom(sbstr("go")); /* do quietly to avoid session output! */ if ((ret/100) != 2) { if (verbose) syslog(LOG_DEBUG, "Unable to change to [%s]; Reason: %d", bstr("go"), ret); } } else if (havebstr("gotofirst")) { int ret; if (verbose) syslog(LOG_DEBUG, "Explicit room selection: %s", bstr("gotofirst")); ret = gotoroom(sbstr("gotofirst")); /* do quietly to avoid session output! */ if ((ret/100) != 2) { syslog(LOG_INFO, "Unable to change to [%s]; Reason: %d", bstr("gotofirst"), ret); } } /* * If we aren't in any room yet, but we have cookie data telling us where we're * supposed to be, and 'go' was not specified, then go there. */ else if ( (StrLength(WCC->CurRoom.name) == 0) && ( (StrLength(WCC->Hdr->c_roomname) > 0) )) { int ret; if (verbose) syslog(LOG_DEBUG, "We are in '%s' but cookie indicates '%s', going there...", ChrPtr(WCC->CurRoom.name), ChrPtr(WCC->Hdr->c_roomname) ); ret = gotoroom(WCC->Hdr->c_roomname); /* do quietly to avoid session output! */ if ((ret/100) != 2) { if (verbose) syslog(LOG_DEBUG, "COOKIEGOTO: Unable to change to [%s]; Reason: %d", ChrPtr(WCC->Hdr->c_roomname), ret); } } if (WCC->Hdr->HR.Handler != NULL) { if ( (!WCC->logged_in) && ((WCC->Hdr->HR.Handler->Flags & ANONYMOUS) == 0) && (WCC->serv_info != NULL) && (WCC->serv_info->serv_supports_guest == 0) ) { display_login(); } else { if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) { begin_ajax_response(); } WCC->Hdr->HR.Handler->F(); if ((WCC->Hdr->HR.Handler->Flags & AJAX) != 0) { end_ajax_response(); } } } /* When all else fails, display the default landing page or a main menu. */ else { /* * ordinary browser users get a nice login screen, DAV etc. requsets * are given a 401 so they can handle it appropriate. */ if (!WCC->logged_in) { if (xhttp) { authorization_required(); } else { display_default_landing_page(); } } /* * Toplevel dav requests? or just a flat browser request? */ else { if (xhttp) { dav_main(); } else { display_main_menu(); } } } SKIP_ALL_THIS_CRAP: FreeStrBuf(&Buf); fflush(stdout); }
/* * Background ajax call to receive updates from the browser when a note is moved, resized, or updated. */ void ajax_update_note(void) { char buf[1024]; int msgnum; struct vnote *v = NULL; if (!havebstr("note_uid")) { begin_ajax_response(); wc_printf("Received ajax_update_note() request without a note UID."); end_ajax_response(); return; } serv_printf("EUID %s", bstr("note_uid")); serv_getln(buf, sizeof buf); if (buf[0] != '2') { begin_ajax_response(); wc_printf("Cannot find message containing vNote with the requested uid!"); end_ajax_response(); return; } msgnum = atol(&buf[4]); /* Was this request a delete operation? If so, nuke it... */ if (havebstr("deletenote")) { if (!strcasecmp(bstr("deletenote"), "yes")) { serv_printf("DELE %d", msgnum); serv_getln(buf, sizeof buf); begin_ajax_response(); wc_printf("%s", buf); end_ajax_response(); return; } } /* If we get to this point it's an update, not a delete */ v = vnote_new_from_msg(msgnum, 0); if (!v) { begin_ajax_response(); wc_printf("Cannot locate a vNote within message %d\n", msgnum); end_ajax_response(); return; } /* Make any requested changes */ if (havebstr("top")) { v->pos_top = atoi(bstr("top")); } if (havebstr("left")) { v->pos_left = atoi(bstr("left")); } if (havebstr("height")) { v->pos_height = atoi(bstr("height")); } if (havebstr("width")) { v->pos_width = atoi(bstr("width")); } if (havebstr("red")) { v->color_red = atoi(bstr("red")); } if (havebstr("green")) { v->color_green = atoi(bstr("green")); } if (havebstr("blue")) { v->color_blue = atoi(bstr("blue")); } if (havebstr("value")) { /* I would have preferred 'body' but InPlaceEditor hardcodes 'value' */ if (v->body) free(v->body); v->body = strdup(bstr("value")); } /* Serialize it and save it to the message base. Server will delete the old one. */ write_vnote_to_server(v); begin_ajax_response(); if (v->body) { escputs(v->body); } end_ajax_response(); vnote_free(v); }