/* * 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(); }
/* * Go to the URL saved by push_destination() */ void pop_destination(void) { wcsession *WCC = WC; /* * If we are in the middle of a new user signup, the server may request that * we first pass through a registration screen. */ if ((WCC) && (WCC->need_regi)) { if ((WCC->PushedDestination != NULL) && (StrLength(WCC->PushedDestination) > 0)) { /* Registering will take us to the My Citadel Config room, so save our place */ StrBufAppendBufPlain(WCC->PushedDestination, HKEY("?go="), 0); StrBufUrlescAppend(WCC->PushedDestination, WCC->CurRoom.name, NULL); } WCC->need_regi = 0; display_reg(1); return; } /* * Do something reasonable if we somehow ended up requesting a pop without * having first done a push. */ if ( (!WCC) || (WCC->PushedDestination == NULL) || (StrLength(WCC->PushedDestination) == 0) ) { do_welcome(); return; } /* * All righty then! We have a destination saved, so go there now. */ if (verbose) syslog(LOG_DEBUG, "Pop: %s", ChrPtr(WCC->PushedDestination)); http_redirect(ChrPtr(WCC->PushedDestination)); }
static void screenshot_response_task(void *task) { response_t *r = task; hts_mutex_lock(&screenshot_mutex); if(screenshot_connection == NULL) { hts_mutex_unlock(&screenshot_mutex); } else { http_connection_t *hc = screenshot_connection; screenshot_connection = NULL; hts_mutex_unlock(&screenshot_mutex); if(r->url != NULL) { http_redirect(hc, r->url); } else { const char *msg = r->errmsg; if(msg == NULL) msg = "Error not specified"; htsbuf_queue_t out; htsbuf_queue_init(&out, 0); htsbuf_append(&out, msg, strlen(msg)); htsbuf_append_byte(&out, '\n'); http_send_reply(hc, 500, "text/plain", NULL, NULL, 0, &out); } } free(r->url); free(r->errmsg); free(r); }
int tstat_http_set_data(void) { http_post_data((void*)&tstat_setup, sizeof tstat_setup); EEPROM_WRITE(eeprom_tstat_setup, tstat_setup, sizeof eeprom_tstat_setup); tstat_restart(); http_redirect("/logic.html"); return 0; }
int logic_http_set_data(void) { http_post_data((void*)&logic_setup, sizeof logic_setup); EEPROM_WRITE(eeprom_logic_setup, logic_setup, sizeof eeprom_logic_setup); logic_restart(); http_redirect("/logic.html"); return 0; }
unsigned io_http_set_data(void) { http_post_data((void*)&io_setup, sizeof io_setup); EEPROM_WRITE(&eeprom_io_setup, io_setup, sizeof io_setup); io_restart(); http_redirect("/io.html"); ////////////// proj-dependant return 0; }
int ir_http_set_data(void) { // format: data=CCNNPPLLLLLL..LL // CC - 1 byte command, 0x01 = start rec, 0x02 = play rec, 0x03 - save record // NN - 1 byte ir command (record) number, 0xff = play captured from buffer (for Save and Play commands) // PP - 1 byte lablel length in bytes (for Save command) // LL - win1251 chars of command label (for Save command) struct { unsigned char opcode; unsigned char rec_n; unsigned char label_len; } cmd; char label[32]; unsigned postlen; if(http.post_content_length - HTTP_POST_HDR_SIZE < (3<<1) ) return 0; // at least 3 hex byte must be posted http_post_data_part(req + HTTP_POST_HDR_SIZE, (void*)&cmd, sizeof cmd); switch(cmd.opcode) { case 0x01: ir_start_capture(); http_reply(200,"ok"); break; case 0x02: if(cmd.rec_n != 0xff && cmd.rec_n >= IR_COMMANDS_N) break; // validate cmd number ir_play_record(cmd.rec_n); http_reply(200,"ok"); break; case 0x03: if(cmd.rec_n >= IR_COMMANDS_N) break; // validate cmd number postlen = (sizeof cmd + cmd.label_len)<<1; if(http.post_content_length != HTTP_POST_HDR_SIZE + postlen) break; // check POST data length util_fill((void*)label, sizeof label, 0); // LBS 27.02.2012 - it was wrong function args sequence !!! if(cmd.label_len > 31) cmd.label_len = 31; // limit label length http_post_data_part(req + HTTP_POST_HDR_SIZE + sizeof cmd * 2, label, cmd.label_len); // read label ir_save_record(cmd.rec_n, label); http_redirect("/ir.html"); break; default: http_redirect("/ir.html"); break; } return 0; }
int logic_pinger_http_set_data(void) { http_post_data((void*)&logic_pinger_setup, sizeof logic_pinger_setup); #ifdef DNS_MODULE struct logic_pinger_setup_s *ep = eeprom_logic_pinger_setup; struct logic_pinger_setup_s *p = logic_pinger_setup; for(int i=0; i<LOGIC_MAX_PINGER; ++i, ++ep, ++p) dns_resolve(ep->hostname, p->hostname); #endif EEPROM_WRITE(eeprom_logic_pinger_setup, logic_pinger_setup, sizeof eeprom_logic_pinger_setup); logic_pinger_restart(); http_redirect("/logic.html"); return 0; }
int resp_defined_error_page( header_out_t* header_out , int err_code ) { switch ( err_code ) { case 404: if ( page_is_defined( servG->http_404_page ) == 0 )return 0; http_redirect( header_out->req , servG->http_404_page ); break; case 500: case 501: case 502: case 503: case 504: case 505: if ( page_is_defined( servG->http_50x_page ) == 0 )return 0; http_redirect( header_out->req , servG->http_50x_page ); break; default: return 0; } return 1; }
int wiki_GetParamsGetServerCall(SharedMessageStatus *Stat, void **ViewSpecific, long oper, char *cmd, long len, char *filter, long flen) { if (oper == do_search) display_wiki_pagelist(); else http_redirect("wiki?page=home"); return 300; }
unsigned io_http_set_data(void) { unsigned ch; switch(http.page->name[2]) // '/cNio_set.cgi' { case '1': ch = 0; break; case '9': ch = 8; break; default: return 0; } const unsigned half_setup_size = (char*)&io_setup[7] - (char*)&io_setup[0] + sizeof io_setup[7]; // alignment-wise http_post_data((void*)&io_setup[ch], half_setup_size); EEPROM_WRITE(&eeprom_io_setup[ch], &io_setup[ch], half_setup_size); io_restart(); http_redirect(ch==0 ? "/cio.html?ch=1" : "/cio.html?ch=9"); return 0; }
static int hc_open(http_connection_t *hc, const char *remain, void *opaque, http_cmd_t method) { htsbuf_queue_t out; const char *url = http_arg_get_req(hc, "url"); if(url != NULL) { event_dispatch(event_create_openurl(url, NULL, NULL, NULL, NULL, NULL)); return http_redirect(hc, "/showtime/open"); } htsbuf_queue_init(&out, 0); htsbuf_append(&out, openpage, strlen(openpage)); return http_send_reply(hc, 0, "text/html", NULL, NULL, 0, &out); }
static int hc_root_old(http_connection_t *hc) { htsbuf_queue_t out; const char *url = http_arg_get_req(hc, "url"); if(url != NULL) { event_dispatch(event_create_openurl(url, NULL, NULL, NULL, NULL, NULL)); return http_redirect(hc, "/"); } htsbuf_queue_init(&out, 0); htsbuf_qprintf(&out, "<html><body>" "<h2>%s</h2><p>Version %s" , gconf.system_name, htsversion_full); htsbuf_qprintf(&out, "<form name=\"input\" method=\"get\">" "Open URL in Showtime: " "<input type=\"text\" name=\"url\" style=\"width:500px\"/>" "<input type=\"submit\" value=\"Open\" />" "</form>"); htsbuf_qprintf(&out, "<h3>Diagnostics</h3>"); diag_html(hc, &out); htsbuf_qprintf(&out, "<p><a href=\"/showtime/translation\">Upload and test new translation (.lang) file</a></p>"); htsbuf_qprintf(&out, "</body></html>"); return http_send_reply(hc, 0, "text/html", NULL, NULL, 0, &out); }
/* * 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(); } }
static void work_http( connection* conn ) { int i; virtual_host * host; //check if the connection cannot work. if( conn->state != C_READY ) return; conn->state = C_REQUESTING; http_request( conn ); if( conn->state != C_REQUESTING ) return; //response conn->code = 200; conn->state = C_RESPONSING; /* Check Host and then set root directory. */ host = loop_search( &conn->server->loop_vhost, conn->host, vhost_searcher ); if( !host ){ host = loop_search( &conn->server->loop_vhost, "*", vhost_searcher ); } if( host ){ //read root conn->root_dir = host->root_dir; if( !loop_is_empty( &host->loop_rewrite ) ) loop_search( &host->loop_rewrite, (void*)conn, loop_rewrite_match ); http_parse_uri( conn ); DBG("[%s]%s%s", conn->client->ip_string, conn->host, conn->uri ); _RESPONSE: http_parse_path( conn ); conn->document_type = http_doctype( conn->server, conn->extension ); if( !conn->document_type ){ http_error( conn, 404, "<h1>File not found.</h1>" ); }else if( conn->extension[0] && strstr( conn->server->asp_exts, conn->extension ) ) { //php do ... exec_asp( conn ); }else if( host->proxy && ( !host->proxy_exts[0] || strstr( host->proxy_exts, conn->extension ) ) ) { // uses proxy server proxy_request( conn, host->proxy_ip, host->proxy_port ); }else if( access(conn->full_path, 0)==0 ){ if( is_dir(conn->full_path) ){ char* tmp; NEW( tmp, PATH_LEN+32 ); if( conn->script_name[strlen(conn->script_name)-1] != '/' ){ //Are you sure that script starts with '/'? sprintf( tmp, "http://%s%s/", conn->host, conn->script_name ); http_redirect( conn, tmp ); }else{ if( tmp ){ for( i = 0; i<10; i++ ) { if( !conn->server->default_pages[i][0] ) { i=10; break; } sprintf( tmp, "%s/%s", conn->full_path, conn->server->default_pages[i] ); if( access( tmp, 0 ) == 0 ) { //091004 by Huang Guan. sprintf( conn->script_name, "%s%s", conn->script_name, conn->server->default_pages[i] ); DEL( tmp ); goto _RESPONSE; } } } if( i == 10 ){ // List Directory if( host->list ){ int ret; NEW( conn->data_send, MAX_DATASEND+4 ); strcpy( conn->extension, "html" ); conn->document_type = http_doctype( conn->server, conn->extension ); ret = listdir( conn->data_send, MAX_DATASEND, conn->full_path, conn->script_name ); conn->data_size = ret; }else{ http_error( conn, 403, "<h1>Forbidden</h1>" ); } } } DEL( tmp ); }else{ http_sendfile( conn, conn->full_path ); } }else if( strncmp(conn->current_dir, "/system", 7)==0 && conn->root_dir==host->root_dir ){ strcpy(conn->script_name, conn->script_name+7); conn->root_dir = conn->client->server->root_dir; goto _RESPONSE; }else{ http_error( conn, 404, "<h1>File not found.</h1>" ); } }else{ http_error( conn, 403, "<h1>Unknown host name.</h1>" ); } if( conn->state == C_RESPONSING ) http_response( conn ); conn->requests ++; if( conn->form_data ) DEL( conn->form_data ); if( conn->data_send ) DEL( conn->data_send ); if( conn->session ) conn->session->reference --; conn->session = NULL; //next request if( conn->keep_alive ){ conn->state = C_READY; }else{ conn->state = C_END; } }
/* * 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); }
void save_pushemail(void) { folder Room; int Done = 0; StrBuf *Buf; char buf[SIZ]; int msgnum = 0; char *pushsetting = bstr("pushsetting"); char *sms = NULL; if (strncasecmp(pushsetting, "textmessage", 11) == 0) { sms = bstr("user_sms_number"); } Buf = NewStrBuf(); memset(&Room, 0, sizeof(folder)); if (goto_config_room(Buf, &Room) != 0) { FreeStrBuf(&Buf); FlushFolder(&Room); return; /* oh well. */ } FlushFolder(&Room); serv_puts("MSGS ALL|0|1"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 8) { serv_puts("subj|__ Push email settings __"); serv_puts("000"); } else { printf("Junk in save_pushemail buffer!: %s\n", buf); FreeStrBuf(&Buf); return; } while (!Done && StrBuf_ServGetln(Buf) >= 0) { if ( (StrLength(Buf)==3) && !strcmp(ChrPtr(Buf), "000")) { Done = 1; break; } msgnum = StrTol(Buf); } if (msgnum > 0L) { serv_printf("DELE %d", msgnum); StrBuf_ServGetln(Buf); GetServerStatus(Buf, NULL); } serv_printf("ENT0 1||0|1|__ Push email settings __|"); StrBuf_ServGetln(Buf); if (GetServerStatus(Buf, NULL) == 4) { serv_puts(pushsetting); if (sms != NULL) { serv_puts(sms); } serv_puts(""); serv_puts("000"); } /** Go back to the room we're supposed to be in */ serv_printf("GOTO %s", ChrPtr(WC->CurRoom.name)); StrBuf_ServGetln(Buf); GetServerStatus(Buf, NULL); http_redirect("display_pushemail"); FreeStrBuf(&Buf); }