int main(int argc, char **argv) { static char *callback = NULL, *user; int i; extern int headers_initialized; if (argc < 2) { /* normal operation as a CGI application */ cgi_init(); atexit(cgi_end); cgi_process_form(); printf("Content-type: application/javascript; charset=utf-8\r\n\r\n"); } else interactive = 1; /* interactive mode for debugging */ wfdbquiet(); /* suppress WFDB library error messages */ atexit(cleanup); /* release allocated memory before exiting */ /* Define data sources to be accessed via this server. */ setrepos(); /* function defined in "setrepos.c" */ if (!(action = get_param("action"))) { print_file(LWDIR "/doc/about.txt"); exit(0); } if (!interactive && (callback = get_param("callback"))) { printf("%s(", callback); /* JSONP: "wrap" output in callback */ atexit(jsonp_end); /* close the output with ")" before exiting */ } if (strcmp(action, "dblist") == 0) dblist(); else if ((db = get_param("db")) == NULL) lwfail("Your request did not specify a database"); else if (strcmp(action, "rlist") == 0) rlist(); else if (strcmp(action, "alist") == 0) alist(); else if ((record = get_param("record")) == NULL) lwfail("Your request did not specify a record"); else if (strcmp(action, "info") == 0) info(); else if (strcmp(action, "fetch") == 0) fetch(); else lwfail("Your request did not specify a valid action"); exit(0); }
int main(void) { cgi_init(); cgi_session_start(); cgi_process_form(); // Is to destroy the session? if (cgi_param("confirm") && !strcmp(cgi_param("confirm"), "yes")) { cgi_session_destroy(); cgi_end(); cgi_redirect("session.cgi"); return 0; } cgi_init_headers(); puts("" "<html>" "<head><title>LibCGI session examples - Destroy session</title>" "</head>" "<body>" ""); cgi_include("session_ex1_desc.html"); puts("" "<table width='70%%' align='center'>" "<tr>" "<td>" ""); if (!cgi_session_var_exists("logged")) { puts("<font face='arial, verdana' size='2'>You are not logged yet</font>"); } else { puts("" "<font face='arial, verdana' size='2'>If you are sure to unregister the session, " "<a href='destroy.cgi?confirm=yes'>click here</a></font>" ""); } puts("</td></tr>"); cgi_include("topbar.htm"); puts("" "</table>" "</body>" "</html>" ""); cgi_end(); return 0; }
int main(int argc, char **argv, char **envp) { CGI *cgi = NULL; NEOERR *err; mdb_conn *conn = NULL; char *s, *u, *p, *r, *jcbk; mtc_init("test"); mconfig_parse_file(SITE_CONFIG, &g_cfg); if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) { mtc_err("init db error %s", mdb_get_errmsg(conn)); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); return 1; } err = cgi_init(&cgi, NULL); if (err != STATUS_OK) { mtc_err("init cgi error"); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("初始化错误"); return 1; } err = cgi_parse(cgi); if (err != STATUS_OK) { mtc_err("parse cgi error"); hdf_set_value(cgi->hdf, PRE_OUTPUT".errmsg", "初始化出错"); goto finish; } u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL); s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL); if (s && u) { if (user_has_login(conn, u, s)) { hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser"); hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey"); hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "1"); goto finish; } } hdf_set_value(cgi->hdf, PRE_OUTPUT".rcode", "2"); finish: cgi_display(cgi, F_TPL_TEST); cgi_destroy(&cgi); mdb_destroy(conn); return 0; }
CGI::CGI(bool process_body) : _GET(_request_queries) , _POST(_request_posts) , _COOKIE(_request_cookies) , _SERVER(_server_variables) , _REQUEST(_request_all) , _FILES(_uploaded_files) , BODY(this) , _request_handled(false) , _header_sent(false) , _body_sent(false) , _buffered(true) , _status(200) , _cgi_handle(NULL) { void **cgiptr = &_cgi_handle; ::CGI * &cgi = *reinterpret_cast< ::CGI **>(cgiptr); NEOERR *err; TranslateEnvvars(&_server_variables); err = cgi_init(&cgi, NULL); ThrowIfNeoError(err); TranslateHDF(cgi, "Cookie", &_request_cookies); TranslateHDF(cgi, "Query", &_request_queries); if (!process_body) { return; } err = cgi_register_parse_cb(cgi, "POST", "*", this, Parser::Parse); ThrowIfNeoError(err); // Purge Query subtree so GET values are gone. err = hdf_remove_tree(cgi->hdf, "Query"); ThrowIfNeoError(err); err = cgi_parse(cgi); ThrowIfNeoError(err); if (_SERVER["REQUEST_METHOD"].compare("POST") == 0) { TranslatePost(cgi, &_request_posts, &_uploaded_files); } else if (_SERVER["REQUEST_METHOD"].compare("PUT") == 0) { TranslatePut(cgi, &_uploaded_files); } // Now we have both GET and POST data, POST overwrites GET. _request_all = _request_queries; _request_all.Merge(_request_posts, true); }
int main(void) { cgi_init(); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); cgi_init_headers(); header("sidebar_download"); menu(); sidebar(); //Beta ! std::cout << "<p class=\"wrn\">Phase de beta !<br />" "Le jeu est en phase de beta, ce qui signifie qu'il " "est fortement possible que des bugs soit présent.<br />" "Le téléchargement d'Okzoniom::Patcher permet de garder le jeu à jour " "par rapport aux dernières modifications mise en ligne." "</p>"; std::cout << "<p class=\"wrn\">" "En cas de problème, vous pouvez me faire parvenir par e-mail " "le fichier Log_Patcher.txt ou Log.txt dans le cas d'un plantage !</p>"; std::cout << "<div class=\"body\"><div class=\"main\">" "<h1>" << __tr("download") << "</h1>" "<div class=\"hr\"></div>" << std::endl; std::map<std::string, std::string> title_file; title_file["Windows"] = "Patcher_Win.exe"; title_file["Linux"] = "Patcher_Linux.tar"; for(auto it = title_file.begin(); it != title_file.end(); ++it) { std::string file = it->second; std::cout << "<h2>" << it->first << "</h2>" "<p>" "<a href=\"download/" << file << "\">" "<strong>> " << file <<" <</strong></a><br />" << infoFile(file) << "</p>" << std::endl; } std::cout << "</div></div>" << std::endl; footer(); return 0; }
int main() { HDF *hdf = NULL; hdf_init(&hdf); cgi_init(&cgi, hdf); sem_init(&cmd_sem, 0, 0); AmbaPMPage_get_params (); sem_wait(&cmd_sem); cgi_display(cgi, "../html/pm.html"); return 0; }
int main(int argc, char *argv[]) { cgi_init(); cgi_session_start(); cgi_process_form(); cgi_init_headers(); sqlite3 *db; char *err = 0; char *sql = NULL; char **result=NULL; int row=0,col=0; int ret = 0; ret = sqlite3_open(DATEBASE,&db); if(ret != SQLITE_OK) { fputs(sqlite3_errmsg(db),stderr); fputs("\n",stderr); exit(1); } sql = sqlite3_mprintf("select U_prim from UserInfo where U_id='%s' and U_pwd='%s'", cgi_param("user"),cgi_param("password")); ret = sqlite3_get_table(db,sql,&result,&row,&col,&err); if(ret != SQLITE_OK) { fputs(err,stderr); fputs("\n",stderr); sqlite3_close(db); exit(1); } if(col == 0 && row == 0) { /* 修改路径 */ printf("bad input"); printf("%s ",cgi_param("user")); cgi_include ("../htdocs/login.html"); } else { cgi_session_register_var("logged",result[1]); /* 修改系统用户跳转页面地址 */ cgi_include("../htdocs/main.html"); } sqlite3_free_table(result); sqlite3_close(db); cgi_end(); return 0; }
int main(void) { cgi_init(); cgi_session_start(); cgi_init_headers(); puts("<html><body>"); cgi_include("session_ex1_desc.html"); puts("" "<table width='70%%' align='center'>" "<tr>" "<td align='center'>" "<font face='arial, verdana' size='4' color='orange'>Main page" ""); // The user is logged? if (cgi_session_var_exists("logged")) puts(" - logged"); else puts(" - not logged yet"); puts("" "</font>" "</td>" "</tr>" " " "<tr>" "<td><font face='arial, verdana' size='2' color='#0000ff'>" "This is the main page of LibCGI session suport test. Please choose one of the options" "in the navigation bar.</font>" "</td>" "</tr>" ""); // include the navigation bar cgi_include("topbar.htm"); puts("" "</table>" "</body>" "</html>" ""); cgi_end(); return 0; }
SCM scgi_session_start() { cgi_init (); // init libcgi if (cgi_session_start ()) { fflush (stdout); return SCM_BOOL_T; } else { fflush (stdout); return SCM_BOOL_F; } }
int main() { char *str, *delim, **e; unsigned int total, i; cgi_init(); cgi_process_form(); cgi_init_headers(); // The form was submited?? if (cgi_param("action")) { str = cgi_param("str"); delim = cgi_param("delim"); e = explode(str, delim, &total); if (total < 1) puts("explode() returned 0 items."); else { for (i = 0; i < total; i++) printf("Item offset [%d]: %s<br>", i, e[i]); } free(str); free(delim); } else { printf("" "<html><head><title>LibCGI examples - explode()</title></head>" "<body>" "%s<br><br>" "<form action='explode.cgi' method='post'>" "String: <input type='text' name='str' value='this,is,a,test'><br>" "Delimitator: <input type='text' name='delim' value=',' maxlength='1' size='2'><br>" "<input type='submit' value='explode() the string!!!' name='action'>" "</form>" "</body>" "</html>" "", example_description()); } cgi_end(); return 0; }
void ewf_request_init(ewf_request_t *request) { NEOERR *err = NULL; /* fill cgi struct */ err = cgi_init(&cgi, NULL); if (err != NULL) { #ifdef DEBUG cgi_neo_error(cgi, err); #endif nerr_log_error(err); nerr_ignore(&err); } request->type = ewf_request_type(); request->uri = hdf_get_value(cgi->hdf, "CGI.RequestURI", "/"); }
int main2(void) { // variable declaration and fixed memory allocation char data[MAXLEN]; memset(data,MAXLEN,0); char textinput[DATALEN]; memset(textinput,DATALEN,0); char radiobutton[DATALEN]; memset(radiobutton,DATALEN,0); char checkbox[DATALEN]; memset(checkbox,DATALEN,0); char textarea[DATALEN]; memset(textarea,DATALEN,0); char select[DATALEN]; memset(select,DATALEN,0); char fileupload[DATALEN]; memset(fileupload,DATALEN,0); // get data get_data(get_length(), &data[0]); // initialize cgi cgi_init(); start_html("ME4_Group2"); // print data to screen debug_to_screen(get_length(), &data[0]); // get value of each element get_element(&data[0],"textinput1", &textinput[0]); printf(" <br>textinput1=\"%s\"\n", textinput); get_element(&data[0],"radiobutton1", &radiobutton[0]); printf(" <br>radiobutton1=\"%s\"\n", radiobutton); get_element(&data[0],"checkbox1", &checkbox[0]); printf(" <br>checkbox1=\"%s\"\n", checkbox); get_element(&data[0],"textarea1", &textarea[0]); printf(" <br>textarea1=\"%s\"\n", textarea); get_element(&data[0],"select1", &select[0]); printf(" <br>select1=\"%s\"\n", select); int status = save_upload(&data[0],"fileupload1", &fileupload[0]); printf(" <br>fileupload1=\"%s\"\n", fileupload); if(status == 0) { printf(" <br>\"%s\" saved to cgi-bin\n", fileupload); } // end cgi end_html(); return 0; }
int main() { int bad = 0; for (struct test_spec* spec = specs; spec->input; ++spec) { setenv("QUERY_STRING", spec->input, 1); struct cgi* cgi = cgi_init(); for (int var = 0; var < spec->n_vars; ++var) { struct var_spec expected_var = spec->vars[var]; struct cgi_var* cgi_var = cgi_get_var(cgi, expected_var.var); if (!cgi_var) { printf("Query string %s: missing var %s\n", spec->input, expected_var.var); bad ++; } else if (strcmp(cgi_var->var, expected_var.var)) { printf("Query string %s: misnamed var %s (got %s)\n", spec->input, expected_var.var, cgi_var->var); bad++; } else if (cgi_var->n_values != expected_var.n_values) { printf("Query string %s: wrong number of values var %s (%d for %d)\n", spec->input, expected_var.var, cgi_var->n_values, expected_var.n_values); bad++; } else { for (int val = 0; val < expected_var.n_values; ++val) { if (strcmp(cgi_var->values[val], expected_var.values[val])) { printf("Query string %s: wrong values var %s (%s for %s)\n", spec->input, expected_var.var, cgi_var->values[val], expected_var.values[val]); bad++; } } } } } if (bad) { printf ("Found %d errors\n", bad); } return bad; }
int ex_init() { int i = -1; static char pool[2048]; static ex_mpool mpool; ex_mpool_init(&mpool, pool, sizeof(pool)); ex_hash_init(&ExContext.mimeMap, &mpool, 97); ex_hash_init(&ExContext.pageMap, &mpool, 97); ExContext.pageMap.hashcmp = (void *) ex_hashcasecmp_str; ExContext.mimeMap.hashcmp = (void *) ex_hashcasecmp_str; /* add MIME type map */ while (mmt[++i].ext != NULL) { ex_hash_add(&ExContext.mimeMap, mmt[i].ext, mmt[i].type); } ExContext.quitFlag = 0; ExContext.threadCnt = 0; cgi_init(); return start_thread((void *) ex_http_start, NULL); }
int main() { HDF *hdf = NULL; char* stream = NULL; hdf_init(&hdf); cgi_init(&cgi, hdf); cgi_parse(cgi); sem_init(&cmd_sem, 0, 0); stream = hdf_get_value(cgi->hdf,"Query.stream",NULL); if(strstr(stream, "1")) { urlid = 0; } else if (strstr(stream, "2")) { urlid = 1; } else if (strstr(stream, "3")) { urlid = 2; } else if (strstr(stream, "4")) { urlid = 3; }/* else if (strstr(stream, "stream=5")) { urlid = 4; } else if (strstr(stream, "stream=6")) { urlid = 5; } else if (strstr(stream, "stream=7")) { urlid = 6; } else if (strstr(stream, "stream=8")) { urlid = 7; }*/ AmbaEncPage_get_params (); sem_wait(&cmd_sem); if(camtype == WARP_MODE) { cgi_display(cgi, "../html/dwp_enc.html"); } else { cgi_display(cgi, "../html/enc.html"); } return 0; }
INPUT* CGI_INIT() { cgi = cgi_init(); setup(cgi); load_variables(cgi); struct cgi_var *var; INPUT *tmp, *head = NULL; for (var = cgi->variables; var; var = var->next) { tmp = (INPUT*)__ax_malloc(sizeof(INPUT)); strcpy(tmp->name, var->name); strcpy(tmp->val, var->value); tmp->next = head; head = tmp; } tmp = head; destroy(cgi); return head; }
int main(void) { cgi_init(); mysqlpp::Connection c(false); if (!c.connect("okzoniom", "localhost", "okzoniom", getDBIdent().c_str())) { cgi_redirect("./error.okz?state=err_db"); return 0; } else { //Set UTF8 mysqlpp::Query q = c.query("SET NAMES utf8"); q.exec(); } initializeFaction(c); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); cgi_init_headers(); __tr("your_army"); header("your_army"); menu(); sidebar(); if (cgi_session_var("login") == NULL) { std::cout << "<div class=\"err\">" << __tr("profil_mustlogin") << "</div>"; } else { displayState(); show(cgi_session_var("login"), c); } footer(); return 0; }
int main(int argc, char *argv[]) { struct cgi_state *cgi; extern char *optarg; extern int optind; int opt; int use_cgi = 0; int i; while ((opt = getopt(argc, argv, "ch")) != -1) { switch (opt) { case 'c': use_cgi = 1; break; case 'h': usage(); exit(1); } } argv += optind; argc -= optind; cgi = cgi_init(); if (use_cgi) { cgi->setup(cgi); cgi->load_variables(cgi); } for (i=0; i<argc; i++) { cgi->tmpl->process(cgi->tmpl, argv[i], 1); } return 0; }
int main(int argc,char **agrs,char **env) { char *realcgi; char *realcgi_path; FILE *fp_read; char *buffer; char *page = NULL; char *action = NULL; CGI *cgi = NULL; HDF *hdf = NULL; hdf_init(&hdf); cgi_init(&cgi, hdf); page = hdf_get_value(cgi->hdf,"Query.page",NULL); action = hdf_get_value(cgi->hdf,"Query.action","query"); buffer = (char *)malloc(BUFFERLENTH); realcgi = get_realcgi(page,action,CONFPATH); if (realcgi == NULL){ printf("Content-type: text/html\n\n"); printf("CGI Not Found\n"); return 1; } realcgi_path = parse_absulute_path(realcgi); fp_read=popen(realcgi_path,"r"); while(fgets(buffer,BUFFERLENTH,fp_read)){ printf("%s",buffer); } free(buffer); pclose(fp_read); return 0; }
int main(void) { //Redirect before initializing headers mysqlpp::Connection c(false); if (!c.connect("okzoniom", "localhost", "okzoniom", getDBIdent().c_str())) { cgi_redirect("./error.okz?state=err_db"); return 0; } else { //Set UTF8 mysqlpp::Query q = c.query("SET NAMES utf8"); q.exec(); } cgi_init(); cgi_session_save_path("sessions/"); cgi_session_start(); cgi_process_form(); std::string login = getParam("n"); cgi_init_headers(); header("sidebar_profil", ", "+login); menu(); sidebar(); std::cout << "<div class=\"body\"><div class=\"main\">"; initializeFaction(c); int id,faction, xp, level; mysqlpp::Query query = c.query("SELECT id,faction,xp,level FROM game_account where login = %0Q;"); query.parse(); mysqlpp::StoreQueryResult r = query.store(login); if (r && r.num_rows() > 0) { //Should only be one account with that name id = r[0]["id"]; //Will be used to get the number of units faction = r[0]["faction"]; xp = r[0]["xp"]; level = r[0]["level"]; std::cout << "<p>" << __tr("account") << ": <strong>" << login << "</strong><br />" << __tr("xp") << ": <strong>" << xp << "</strong><br />" << __tr("level") << ": <strong>" << level << "</strong><br />" << __tr("faction") << ": <strong>" << __tr(factionName[faction]) << "</strong>" "<div class=\"hr\"></div>" "<center><p><strong>" << __tr("army_composition") << ":</strong></p>"; //Now we have the account, get its units and their number query.reset(); query << "select unit_name,unit_number from game_unit_available where id_account = %0;"; query.parse(); mysqlpp::StoreQueryResult u = query.store(id); if (u && u.num_rows() > 0) { std::cout << "<table class=\"army\"><tr>" << "<td><strong>" << __tr("unit") << "</strong></td>" << "<td><strong>" << __tr("number") << "</strong></td></tr>"; for (size_t i = 0; i < u.num_rows(); ++i) { int num = u[i]["unit_number"]; if( num > 0) { std::string name; u[i]["unit_name"].to_string(name); std::cout << "<tr><td><strong>" << __tr(name) << "</strong></td>" << "<td><strong>" << num << "</strong></td></tr>"; } } std::cout << "</table></center>"; } else { std::cout << "<center><em>" << __tr("army_empty") << "</em></center>"; } std::cout << "</p>" << std::endl; } else { std::cout << "<p>" << __tr("player_notfound") << "</p>" << std::endl; } std::cout << "</div></div>"; footer(); return 0; }
int main (int argc, char **argv) { char *username; //CGI process cgi_init(); cgi_process_form(); username = cgi_param("uid"); cgi_init_headers(); //HTML printf("\r\n"); printf("<html>\n"); printf("<!-- Arquivo para o projeto NeuralTB -->\n"); printf("<!-- Universidade Federal do Rio de Janeiro\n"); printf(" Escola Politecnica\n"); printf(" Departamento de Engenharia Eletronica e de Computacao\n"); printf(" \n"); printf(" Laboratorio de Processamento de Sinais\n"); printf(" \n"); printf(" Autor: Luiz Evora\n"); printf(" Atualizacao: Laura de Oliveira Fernandes Moraes\n"); printf(" Ultima atualizacao: 29/07/2008 -->\n"); printf("\n"); printf(" <head>\n"); printf("\n"); printf(" <meta http-equiv=content-type content=\"text/html; charset=UTF-8\">\n"); printf("\n"); printf(" <title>.:. Neural TB .:. Busca de pacientes</title>\n"); printf("\n"); printf(" <link rel=\"stylesheet\" type=\"text/css\" href=\"../css/standart.css\"/>\n"); printf("\n"); printf(" <script language=\"javascript\" src=\"../js/xml.js\"></script>\n"); printf(" <script language=\"javascript\" src=\"../js/busca.js\"></script>\n"); printf("\n"); printf("<script>\n"); printf("\n"); printf(" var linha=0;\n"); printf("\n"); printf(" function contaLinhas()\n"); printf("\n"); printf(" {\n"); printf("\n"); printf(" linha+=1;\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" </script>\n"); printf("\n"); printf("\n"); printf("\n"); printf(" </head>\n"); printf("\n"); printf("\n"); printf("\n"); printf("<!-- <body onLoad=\"displayResult('xml','../xml/pacientes.xml','../xml/nomes.xsl');\" class=\"style1\">-->\n"); printf("\n"); printf("<body class=\"style1\">\n"); printf("\n"); printf(" <table height=\"120\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" id= \"d\">\n"); printf("\n"); printf(" <tr bgcolor=\"#CCCCCC\">\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" <td><b><u><font size=\"5\">Menu</font></u></b></td>\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" </tr>\n"); printf("\n"); printf(" <tr bgcolor=\"#CCCCCC\">\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" <td width=\"100%%\">\n"); printf("\n"); printf(" <a href=\"formulario.cgi?uid=%s\">Adicionar Paciente</a> \n", username); printf("\n"); printf(" <a href=\"busca.cgi?uid=%s\"> Buscar/Editar/Remover</a> \n", username); printf("\n"); printf(" <a href=\"backup.cgi\"> Back-up</a> \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" \n"); printf("\n"); printf(" <a href=\"principal.cgi?uid=%s\">Página principal</a>\n", username); printf("\n"); printf(" </td>\n"); printf("\n"); printf(" <td></td>\n"); printf("\n"); printf(" </tr>\n"); printf("\n"); printf(" <tr bgcolor=\"#CCCCCC\">\n"); printf("\n"); printf(" <td> </td>\n"); printf("\n"); printf(" <td>\n"); printf("\n"); printf(" <a href=\"exibirPacientes.cgi?uid=%s\">Exibir questionários</a> \n", username); printf("\n"); printf(" <a href=\"exibirRecusa.cgi?uid=%s\">Exibir recusas</a>\n", username); printf("\n"); printf(" </td>\n"); printf("\n"); printf(" <td></td>\n"); printf("\n"); printf(" </tr>\n"); printf("\n"); printf(" </table>\n"); printf("\n"); printf(" <a id=\"xml1\" href=\"\"></a>\n"); printf(" \n"); printf(" <form action=\"searchPatient.cgi?uid=%s\" method=\"post\" name=\"check\" id=\"searchForm\" onSubmit=\"return validarBusca(this);\" />\n", username); printf("<input type=\"HIDDEN\" name=\"uid\" value=\"%s\">\n",username); printf(" <table width=\"70%%%%\" border=\"0\" cellpadding=\"1\" cellspacing=\"2\" bordercolor=\"#999999\" id=\"tabela\" align=center>\n"); printf(" <tr class=\"styleBusca1\">\n"); printf(" <td width=\"30%%%%\" title=\"Atributo através do qual será realizada a busca\">\n"); printf(" <div class=\"styleBusca2\"> Busca por</div>\n"); printf(" </td>\n"); printf(" <td width=\"20%%%%\" id=\"operador_0\"> </td>\n"); printf(" <td id=\"VALORES_TITULO\" width=\"40%%%%\">\n"); printf(" <div class=\"styleBusca2\"> </div>\n"); printf(" </td>\n"); /*printf(" <td id=\"ORDENA_TITULO\" width=\"10%%%%\" title=\"Ordena os pacientes buscados de acordo com o atributo selecionado\">\n"); printf(" <div class=\"styleBusca2\"> Ordenar por</div>\n"); printf(" </td>\n");*/ printf(" </tr>\n"); printf(" <tr class=\"fundoTabela\">\n"); printf(" <td title=\"Atributo através do qual será realizada a busca\">\n"); printf(" <div align=\"center\"><strong><font color=\"#003399\" size=\"2\" face=\"Arial, Helvetica, sans-serif\">\n"); printf(" <!-- select da celula [1][0] -->\n"); printf(" <select name=\"select\" onChange=\"_options(this);\" onKeyUp=\"_options(this.form);\">\n"); printf(" <option value=\"1\" selected> Selecione</option>\n"); printf(" <option value=\"2.nome\">Nome</option>\n"); //Opcao 2 para nomes printf(" <option value=\"3.diaNasc\">Data de nascimento</option>\n"); //Opcao 3 para datas printf(" <option value=\"4.cidade\">Cidade de estudo</option>\n"); //Opcao 4 para escolhas restritas (com opcoes) printf(" <option value=\"3.diaEntr\">Data da entrevista</option>\n"); //Opcao 3 para datas printf(" </select>\n"); printf(" </font></strong></div>\n"); printf(" </td>\n"); printf(" <td id=\"operadores\"> </td>\n"); printf(" <td id=\"valores\"> </td>\n"); /*printf(" <td id=\"ordena\" title=\"Ordena os pacientes buscados de acordo com o atributo selecionado\">\n"); printf(" <!-- select da celula [1][3] -->\n"); printf(" <select name=\"selectOrdena\">\n"); printf(" <option value=\"id\" selected>Nº de identificação</option>\n"); printf(" <option value=\"nome\">Nome</option>\n"); printf(" <option value=\"diaNasc\">Data de Nascimento</option>\n"); printf(" <option value=\"cidade\">Cidade de estudo</option>\n"); printf(" </select>\n"); printf(" </td> \n");*/ printf(" </tr>\n"); printf(" </table>\n"); printf("<p align=center> <input type=\"submit\" name=\"Submit\" value=\"Pesquisar\"> </p>\n"); printf("</form>\n"); printf("\n"); printf("<div align=center><h3> Pacientes Inseridos</h3></div>\n"); printf("\n"); printf("<div id=\"xml\">\n"); printf("\n"); printf("</div>\n"); printf("\n"); printf("<table width=\"600\" align=\"center\" cellspacing=\"1\" cellpadding=\"0\" id=\"xml1\">\n"); printf("<tr class=\"nome\" align=\"center\">\n"); printf("<td><h4>Número</h4></td>"); printf("<td><h4>Nome</h4></td>"); printf("<td><h4>Data de nascimento</h4></td>"); printf("<td><h4>Data da entrevista</h4></td>"); printf("<td><h4>Remover</h4></td>"); printf("<td><h4> Editar </h4></td></tr>"); printf("\n"); printf(" <script>\n"); printf("\n"); printf("\n"); printf("\n"); printf(" var xmlDoc=null;\n"); printf("\n"); printf(" if (window.ActiveXObject)\n"); printf("\n"); printf(" {// code for IE\n"); printf("\n"); printf(" xmlDoc=new ActiveXObject(\"Microsoft.XMLDOM\");\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" else if (document.implementation.createDocument)\n"); printf("\n"); printf(" {// code for Mozilla, Firefox, Opera, etc.\n"); printf("\n"); printf(" xmlDoc=document.implementation.createDocument(\"\",\"\",null);\n"); /*printf(" document.write(\"<td></td>\");"); printf(" document.write(\"<td><h4>Número</h4></td>\");"); printf(" document.write(\"<td><h4>Nome</h4></td>\");"); printf(" document.write(\"<td><h4>Data de nascimento</h4></td>\");"); printf(" document.write(\"<td><h4>Remover</h4></td>\");"); printf(" document.write(\"<td><h4> Editar </h4></td>\");");*/ printf("\n"); printf(" }\n"); printf("\n"); printf(" else\n"); printf("\n"); printf(" {\n"); printf("\n"); printf(" alert('Your browser cannot handle this script');\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" if (xmlDoc!=null)\n"); printf("\n"); printf(" {\n"); printf("\n"); printf(" xmlDoc.async=false;\n"); printf("\n"); printf(" xmlDoc.load(\"../xml/pacientes.xml\");\n"); printf(" var fname = 0;\n"); printf("\n"); printf("\n"); printf("\n"); printf(" var x=xmlDoc.getElementsByTagName(\"paciente\");\n"); //printf("document.write('</tr>');"); printf("\n"); printf(" for (i=0;i<x.length;i++)\n"); printf("\n"); printf(" { \n"); printf("\n"); printf(" contaLinhas();\n"); printf("\n"); printf("if (!(i %% 2))\n"); printf(" document.write(\"<tr class='par'>\");\n"); printf(" else\n"); printf(" document.write(\"<tr class='impar'>\");\n"); printf("\n"); //printf(" document.write(\"<td></td>\");\n"); printf("\n"); printf(" document.write(\"<td width='50' align='center'>\" + linha + \".</td>\");\n"); printf("\n"); printf(" document.write(\"<td class='link' onClick='showXSL(\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \",\" + fname + \")'>\");\n"); printf("\n"); printf(" document.write(x[i].getElementsByTagName(\"nome\")[0].childNodes[0].nodeValue);\n"); printf("\n"); printf(" document.write(\"</td>\");\n"); printf(" document.write(\"<td class='link' align='center' onClick='showXSL(\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \",\" + fname + \")'>\");\n"); printf("\n"); printf(" document.write(x[i].getElementsByTagName(\"diaNasc\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"mesNasc\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"anoNasc\")[0].childNodes[0].nodeValue);\n"); printf("\n"); printf(" document.write(\"</td>\");\n"); printf("\n"); printf(" document.write(\"<td class='link' align='center' onClick='showXSL(\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \",\" + fname + \")'>\");\n"); printf("\n"); printf(" document.write(x[i].getElementsByTagName(\"diaEntr\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"mesEntr\")[0].childNodes[0].nodeValue + \"/\" + x[i].getElementsByTagName(\"anoEntr\")[0].childNodes[0].nodeValue);\n"); printf("\n"); printf(" document.write(\"</td>\");\n"); printf("\n"); printf(" document.write(\"<td class='link' align='center'>\");\n"); //printf(" var endereco = \"remover.cgi?paciente=\" + (i+1) + \"&uid=%s>\"\n",username); printf(" var endereco = \"remover.cgi?paciente=\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \"&uid=%s>\"\n",username); printf(" document.write(\"<a href=\" + endereco + \"Remover\" + \"</a>\");\n"); printf(" document.write(\"</td>\");\n"); printf(" document.write(\"<td class='link' align='center'>\");\n"); //printf(" endereco = \"editar.cgi?paciente=\" + (i+1) + \"&uid=%s>\"\n",username); printf(" endereco = \"editar.cgi?paciente=\" + x[i].getElementsByTagName(\"id\")[0].childNodes[0].nodeValue + \"&uid=%s>\"\n",username); printf(" document.write(\"<a href=\" + endereco + \"Editar\" + \"</a>\");\n"); printf(" document.write(\"</td>\");\n"); printf("\n"); printf("\n"); printf(" document.write(\"</tr>\");\n"); printf("\n"); printf(" }\n"); printf("\n"); printf(" //document.write(\"</table>\");\n"); printf("\n"); printf(" }\n"); printf("\n"); printf("\n"); printf("\n"); printf(" </script>\n"); printf("\n"); printf("</table>\n"); printf("\n"); printf(" </body>\n"); printf("\n"); printf("</html>\n"); printf("\n"); printf("\n"); cgi_end(); return 0; }
int main (void) { int atual; /* libcgi declarations */ /* libxml2 declarations */ xmlChar *strUTF = NULL; xmlDocPtr doc; xmlNodePtr root_element, cur_node, new_form, new_node, edited_patient, old_patient; char buf[5]; /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION /****************************************************************************** * READ CONTENT STRING FROM SERVER. * * PROCESS DATA. * * CREATE A LINKED LIST. * ******************************************************************************/ cgi_init(); /****************************************************************************** * OPENING AND PARSING AN XML FILE TO A TREE * ******************************************************************************/ doc = xmlReadFile(XML_FILE_PATH, NULL, XML_PARSE_NOBLANKS); if (doc == NULL) { printError("Failed to parse doc"); usualFreeMemory(NULL); exit(0); } root_element = xmlDocGetRootElement(doc); cur_node = root_element->children; /****************************************************************************** * SEARCH THE SAME <numeroGeral> * ******************************************************************************/ atual = 1; while(cur_node != NULL ) { new_form = cur_node; new_node = xmlNewNode (NULL, "id"); sprintf(buf, "%d", atual); xmlNodeAddContent (new_node, buf); xmlAddChild (new_form, new_node); atual++; cur_node = cur_node->next; } /****************************************************************************** * DUMPING DOCUMENT TO FILE * ******************************************************************************/ xmlSaveFormatFileEnc(XML_TEMP_FILE, doc, "UTF-8", 1); remove(XML_FILE_PATH); if (rename(XML_TEMP_FILE, XML_FILE_PATH)) { printError("Erro ao renomear o arquivo atualizado"); usualFreeMemory(doc); exit(0); } /****************************************************************************** * FREE MEMORY AND EXIT * ******************************************************************************/ printSuccess(buf); usualFreeMemory(doc); return 0; }
int main (void) { //modificaçoes xsltproc char tempname [L_tmpnam]; char comando[100]; char address[100]; //2 de 6 FILE *xsl; //size_t len; //char xmlSearchResultFilePath[FILE_NAME_MAX]; //char healthCenter[HEALTH_CENTER_NAME_MAX]; formvars *first; char *pid; cgi_init(); //modificações xsltproc cgi_init_headers(); fflush(stdout); //3de 6 /****************************************************************************** * READ CONTENT STRING FROM SERVER. * * PROCESS DATA. * * CREATE A LINKED LIST. * ******************************************************************************/ first = cgi_process_form(); /****************************************************************************** * ACQUIRE VALUES CHOSEN BY USER * ******************************************************************************/ pid = cgi_param("pid"); /****************************************************************************** * CREATE XSL SEARCH FILE * ******************************************************************************/ //modificações xsltproc if (tmpnam(tempname) != NULL) { xsl = fopen(tempname, "w"); // 4 de 6 fprintf(xsl,"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\r\n"); // fprintf(xsl," xmlns:fo=\"http://www.w3.org/1999/XSL/Format\"\r\n"); // fprintf(xsl," xmlns=\"http://www.w3.org/1999/xhtml\">\r\n"); fprintf(xsl,"<xsl:output omit-xml-declaration=\"yes\" encoding=\"ISO-8859-1\" method=\"xml\"/>\r\n"); fprintf(xsl,"\r\n"); getUserPublicPath(address); fprintf(xsl,"<xsl:include href=\"%s/xml/xsl/fullPatientDetails2.xsl\" />\r\n",address); // 5... fprintf(xsl,"\r\n"); fprintf(xsl,"<xsl:template match=\"/\">\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <xsl:apply-templates select=\"pacientes\" />\r\n"); fprintf(xsl," \r\n"); fprintf(xsl,"</xsl:template>\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"<xsl:template match=\"pacientes\">\r\n"); fprintf(xsl," <!-- Tags' values -->\r\n"); fprintf(xsl," <xsl:for-each select=\"paciente[@removido = 'nao']\">\r\n"); fprintf(xsl," <xsl:sort select=\"descendant::nomeCompleto\" />\r\n"); fprintf(xsl," <xsl:if test=\"triagem/numeroGeral = '%s'\">\r\n", pid); fprintf(xsl," <table>\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Critério Inicial de Triagem para TB</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"triagem\" />\r\n"); /* fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Questionário de Custos - Parte A</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"custosA\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Consulta Médica</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"consultaMedica\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td class=\"title3\" colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th class=\"title3\" colspan=\"2\">Questionário de Custos - Partes B e C</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"custosBeC\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td class=\"title3\" colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th colspan=\"2\">Follow Up - 90 dias</th>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," <xsl:apply-templates select=\"followUp\" />\r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <td colspan=\"2\" height=\"10\"></td>\r\n"); fprintf(xsl," </tr>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl," <tr>\r\n"); fprintf(xsl," <th class=\"title3\">Gráfico de Grupo</th>\r\n"); fprintf(xsl," <td><!--<a href=\"{concat(graficoGrupo, triagem/numeroGeral)}\" target=\"_blank\">Visualizar</a>--></td>\r\n"); fprintf(xsl," </tr>\r\n"); */ fprintf(xsl," </table>\r\n"); fprintf(xsl," <br /><br />\r\n"); fprintf(xsl," </xsl:if>\r\n"); fprintf(xsl," </xsl:for-each>\r\n"); fprintf(xsl," \r\n"); fprintf(xsl,"</xsl:template>\r\n"); fprintf(xsl,"\r\n"); fprintf(xsl,"</xsl:stylesheet>\r\n"); fclose(xsl); //Modificações xsltproc } else printError("Erro ao criar arquivo temporário!\n"); // 5 de 6 /****************************************************************************** * PRINTING RESULT * ******************************************************************************/ //Modificações xsltproc printf("<html>\n"); printf("<head>\n"); printf("<link rel=\"stylesheet\" type=\"text/css\" href=\"css/imprimir.css\" />\n"); printf("\t<title>Versão de Impressão</title>\n"); printf("</head>\n"); printf("<body id=\"result\" onLoad=\"window.print()\">\n"); sprintf(comando,"xsltproc %s xml/pacientesGuadalupe.xml 2>&1",tempname); fflush(stdout); system(comando); sprintf(comando,"rm %s 2>&1",tempname); system(comando); printf("</body>\n"); printf("</html>"); // 6 de 6 /****************************************************************************** * FREE MEMORY AND EXIT * ******************************************************************************/ cgi_end(); return (ok); }
int main(int argc, char *argv[]) { cgi_init(); cgi_process_form(); struct sockaddr_in servaddr, cliaddr; char buf[MAXSIZE]; int sockfd, n; char flush[BUFSIZE]; char str[BUFSIZE]; char local_dir[BUFSIZE] = "/home/xwp/upload/"; int fd; char flag_n; struct stat f_stat; char filename[BUFSIZE]; char scces = 'n'; bzero(flush, sizeof(flush)); bzero(str, sizeof(str)); bzero(filename, sizeof(filename)); if(cgi_param("msg")){ strcpy(str,cgi_param("msg"));} if(cgi_param("video")){ strcpy(filename,cgi_param("video"));} if(cgi_param("Flush")){ strcpy(flush,cgi_param("Flush"));} sockfd = socket(AF_INET, SOCK_STREAM, 0); bzero(&servaddr, sizeof(servaddr)); servaddr.sin_family = AF_INET; inet_pton(AF_INET, "127.0.0.1", &servaddr.sin_addr); servaddr.sin_port = htons(SERV_PORT); bzero(&cliaddr, sizeof(cliaddr)); cliaddr.sin_family = AF_INET; cliaddr.sin_addr.s_addr = htonl(INADDR_ANY); cliaddr.sin_port = htons(SERV_PORT + 1); bind(sockfd, (struct sockaddr *)&cliaddr, sizeof(cliaddr)); connect(sockfd, (struct sockaddr *)&servaddr, sizeof(servaddr)); if(strlen(str) != 0) { flag_n = '1'; write(sockfd, &flag_n, sizeof(flag_n)); read(sockfd, &flag_n, sizeof(flag_n)); if((n = write(sockfd, str, strlen(str))) > 0) { cgi_redirect("../word.html"); cgi_end(); close(sockfd); return 0; } } else if(strlen(filename) != 0) { { flag_n = '2'; write(sockfd, &flag_n, sizeof(flag_n)); read(sockfd, &flag_n, sizeof(flag_n)); strcat(local_dir, filename); write(sockfd, filename, strlen(filename) + 1); read(sockfd, &scces, 1); if(scces != 'y'){ } if(stat(local_dir,&f_stat) == -1){ } write(sockfd, &f_stat.st_size, sizeof(f_stat.st_size)); read(sockfd, &scces, 1); if(scces != 'y'){ } if((fd = open(local_dir, O_RDONLY)) == -1){ } while((n = read(fd, buf, MAXSIZE))){ write(sockfd, buf, n); } cgi_redirect("../upload.html"); } close(fd); cgi_end(); close(sockfd); return 0; } else if(strlen(flush) != 0) { flag_n = '0'; write(sockfd, &flag_n, sizeof(flag_n)); //read(sockfd, &flag_n, sizeof(flag_n)); //if((n = write(sockfd, flush, strlen(flush))) > 0) //{ cgi_redirect("../flash.html"); cgi_end(); close(sockfd); return 0; //} } }
int main (void) { sqlite3 *db; //char *err = 0; int ret = 0; char **datatable1; char **datatable3; int nRow; int nColumn; char *sql; int i; char *zErrMsg = 0; cgi_init(); cgi_init_headers(); cgi_process_form(); puts("<html><head><title>chaxun</title>"); puts("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />"); //puts("<link href=\"/Style.css\" rel=\"stylesheet\" type=\"text/css\" />"); puts("</head>"); puts("<body bgColor=#fffff0>"); db = open_db("OAK.db"); sql = sqlite3_mprintf("select * from IpInfo"); ret = sqlite3_get_table(db, sql, &datatable1, &nRow, &nColumn, &zErrMsg); if (ret != SQLITE_OK) { fprintf(stderr, "SQL error: %s\n", zErrMsg); exit(1); } puts("<form action=\"load.cgi\">"); puts("<table width='70%' align='left' border=1 border-coer=#000066>"); puts("<tr><td width='20%'>"); puts("<select NAME = \"ip\">"); puts("<option value = \"\"> 选择IP</option> "); if (!(0 == nRow && 0 == nColumn)) { for (i = 1; i <= nRow*nColumn ; i += nColumn ) { printf("<option value = \"%s\"", datatable1[i]); if (cgi_param("company")) { if (0 == strncmp(cgi_param("ip"), datatable1[i],strlen(datatable1[i]))) printf("SELECTED"); } printf("> %s </option> ", datatable1[i]); } } puts("</select>"); puts("</td>"); puts("<td>"); puts("<input type=\"submit\" value=\"上传\" name=\"action\" >"); puts("</td></tr></table>"); sql = sqlite3_mprintf("select R.R_id,R.R_name,R.R_flag,C.C_name from ResInfo R left join CompanyInfo C on R.C_id = C.C_id;"); puts("<br />"); puts("<br />"); ret = sqlite3_get_table(db, sql, &datatable3, &nRow, &nColumn, &zErrMsg); if (ret != SQLITE_OK) { fprintf(stderr, "SQL error: %s\n", zErrMsg); exit(1); } puts("<table width='70%' align='left' border=1>"); puts("<tr><td style=\"width:50px\" align=center>选择</td>"); puts("<td style=\"width:150px\" align=center>媒体名称</td>"); puts("<td style=\"width:120px\" align=center>媒体类型</td>"); puts("<td style=\"width:170px\" align=center>所属公司</td>"); puts("</tr>"); if (!(0 == nRow && 0 == nColumn)) { for (i = 4; i <= nRow*nColumn ; i += nColumn ) { puts("<tr><td align='center'><input type = 'checkbox' name='xuanqu' "); printf(" value=%s />", datatable3[i+0]); puts("</td>"); printf("<td>%s</td>", datatable3[i+1]); if(atoi(datatable3[i+2]) == 0){ printf("<td>视频文件</td>"); } else { printf("<td>图片文件</td>"); } printf("<td>%s</td></tr>",datatable3[i+3]); } } puts("</table>"); puts("</form>"); puts("</body></html>"); cgi_end(); return 0; }
int main(int argc, char *argv[]) { int sockfd, n; int i,y; char *strpointer; int res; char buf[MAXDATASIZE]; struct hostent *he; struct sockaddr_in their_addr; // connector's address information FILE *LOGFILE; //char hostName[] = "localhost"; //char hostName[] = "127.0.0.1"; char hostName[] = "bbs-001.boitho.com"; struct SiderFormat Sider[MaxsHits]; struct SiderHederFormat SiderHeder; char buff[64]; //generell buffer struct in_addr ipaddr; struct QueryDataForamt QueryData; //send out an HTTP header: printf("Content-type: text/xml\n\n"); //hvis vi har argumeneter er det første et query if (getenv("QUERY_STRING") == NULL) { if (argc < 2 ) { printf("Error ingen query spesifisert.\n\nEksempel på bruk for å søke på boitho:\n\tsearchkernel boitho\n\n\n"); } else { QueryData.query[0] = '\0'; for(i=1;i<argc ;i++) { sprintf(QueryData.query,"%s %s",QueryData.query,argv[i]); } //strcpy(QueryData.query,argv[1]); //printf("argc :%i %s %s\n",argc,argv[1],argv[2]); printf("query %s\n",QueryData.query); } } else { // Initialize the CGI lib res = cgi_init(); // Was there an error initializing the CGI??? if (res != CGIERR_NONE) { printf("Error # %d: %s<p>\n", res, cgi_strerror(res)); exit(0); } if (cgi_getentrystr("query") == NULL) { perror("Did'n receive any query."); } else { strncat(QueryData.query,cgi_getentrystr("query"),sizeof(QueryData.query)); } } if (strlen(QueryData.query) > MaxQueryLen -1) { printf("query to long\n"); exit(1); } //gjør om til liten case for(i=0;i<strlen(QueryData.query);i++) { QueryData.query[i] = tolower(QueryData.query[i]); } if ((he=gethostbyname(hostName)) == NULL) { // get the host info perror("gethostbyname"); exit(1); } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } their_addr.sin_family = AF_INET; // host byte order their_addr.sin_port = htons(PORT); // short, network byte order their_addr.sin_addr = *((struct in_addr *)he->h_addr); memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1) { perror("connect"); exit(1); } struct queryNodeHederFormat queryNodeHeder; //kopierer inn query strncpy(queryNodeHeder.query,QueryData.query,sizeof(queryNodeHeder.query) -1); //sender forespørsel sendall(sockfd,queryNodeHeder.query,sizeof(queryNodeHeder)); //motter hedderen for svaret if ((i=recv(sockfd, &SiderHeder, sizeof(SiderHeder),MSG_WAITALL)) == -1) { perror("recv"); } //printf("TotaltTreff %i,showabal %i,filtered %i,total_usecs %f\n",SiderHeder.TotaltTreff,SiderHeder.showabal,SiderHeder.filtered,SiderHeder.total_usecs); for(i=0;i<SiderHeder.showabal;i++) { if ((n=recv(sockfd, &Sider[i], sizeof(struct SiderFormat),MSG_WAITALL)) == -1) { perror("recv"); } //printf("url: %s\n",Sider[i].DocumentIndex.Url); } close(sockfd); y=0; //fjerner tegn som er eskapet med \, eks \" blir til " for(i=0;i<strlen(QueryData.query);i++) { if (QueryData.query[i] == '\\') { switch(QueryData.query[++i]) { case '"': //" buff[y++] = '&'; buff[y++] = 'q'; buff[y++] = 'u'; buff[y++] = 'o'; buff[y++] = 't'; buff[y++] = ';'; break; } //else { // printf("error: found \\ but no case\n"); //} } else { //printf("%c\n",QueryData.query[i]); buff[y++] = QueryData.query[i]; } } strncpy(QueryData.query,buff,sizeof(QueryData.query) -1); printf("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?> \n"); printf("<!DOCTYPE family SYSTEM \"http://www.boitho.com/xml/search.dtd\"> \n"); printf("<search>\n"); printf("<treff-info totalt=\"%i\" query=\"%s\" hilite=\"%s\" tid=\"%f\" filtered=\"%i\" showabal=\"%i\"/>\n",SiderHeder.TotaltTreff,QueryData.query,SiderHeder.hiliteQuery,SiderHeder.total_usecs,SiderHeder.filtered,SiderHeder.showabal); for(i=0;i<SiderHeder.showabal;i++) { if (!Sider[i].deletet) { //filtrerer ut tegn som ikke er lov i xml while ((strpointer = strchr(Sider[i].DocumentIndex.Url,'&')) != NULL) { (*strpointer) = 'a'; } //while ((strpointer = strchr(Sider[i].title,'&')) != NULL) { // (*strpointer) = 'a'; //} //while ((strpointer = strchr(Sider[i].description,'&')) != NULL) { // (*strpointer) = 'a'; //} printf("<treff>\n"); printf("\t<DocID>%i-%i</DocID>\n",Sider[i].iindex.DocID,rLotForDOCid(Sider[i].iindex.DocID)); printf("\t<POSISJON>%i</POSISJON>\n",i +1); //DocumentIndex printf("\t<Url>%s</Url>\n",Sider[i].DocumentIndex.Url); printf("\t<Title>%s</Title>\n",Sider[i].title); printf("\t<AdultWeight>%hu</AdultWeight>\n",Sider[i].DocumentIndex.AdultWeight); printf("\t<Sprok>%s</Sprok>\n",Sider[i].DocumentIndex.Sprok); //temp: blir rare tegn her printf("\t<Dokumenttype>%s</Dokumenttype>\n",Sider[i].DocumentIndex.Dokumenttype); printf("\t<RepositorySize>%u</RepositorySize>\n",Sider[i].DocumentIndex.htmlSize); printf("\t<THUMBNALE>%s</THUMBNALE>\n",Sider[i].thumbnale); printf("\t<CACHE>%s</CACHE>\n",Sider[i].cacheLink); printf("\t<IMAGEWIDTH>100</IMAGEWIDTH>\n"); printf("\t<IMAGEHEIGHT>100</IMAGEHEIGHT>\n"); printf("\t<METADESCRIPTION></METADESCRIPTION>\n"); printf("\t<CATEGORY></CATEGORY>\n"); printf("\t<OFFENSIVE_CODE>FALSE</OFFENSIVE_CODE>\n"); printf("\t<beskrivelse>%s</beskrivelse>\n",Sider[i].description); printf("\t<TermRank>%i</TermRank>\n",Sider[i].iindex.TermRank); printf("\t<PopRank>%i</PopRank>\n",Sider[i].iindex.PopRank); printf("\t<allrank>%i</allrank>\n",Sider[i].iindex.allrank); ipaddr.s_addr = Sider[i].DocumentIndex.IPAddress; printf("\t<IPAddress>%s</IPAddress>\n",inet_ntoa(ipaddr)); printf("\t<RESPONSE>%hu</RESPONSE>\n",Sider[i].DocumentIndex.response); printf("\t<NrOfHits>%i</NrOfHits>\n",Sider[i].iindex.TermAntall); //printer ut hits (hvor i dokumenetet orde befinner seg ). printf("\t<hits>"); for (y=0; (y < Sider[i].iindex.TermAntall) && (y < MaxTermHit); y++) { printf("%hu ",Sider[i].iindex.hits[y]); } printf("</hits>\n"); printf("</treff>\n"); } } printf("</search>\n"); //ToDo: må ha låsing her if ((LOGFILE = fopen("/home/boitho/config/query.log","a")) == NULL) { perror("logfile"); } fprintf(LOGFILE,"%s %i\n",queryNodeHeder.query,SiderHeder.TotaltTreff); fclose(LOGFILE); return 0; }
int main(int argc, char **argv, char **envp) { CGI *cgi; NEOERR *err; int ret; HASH *dbh; HASH *tplh; session_t *session = NULL; char *requri, *jsoncb; int (*data_handler)(CGI *cgi, HASH *dbh, session_t *session); void *lib; //sleep(20); mconfig_parse_file(SITE_CONFIG, &g_cfg); mtc_init(TC_ROOT"viki"); ret = ltpl_init(&tplh); if (ret != RET_RBTOP_OK) { mtc_err("init templates error"); mutil_redirect("初始化模板失败", TGT_SELF, URL_CLOSE, true); return ret; } ret = ldb_init(&dbh); if (ret != RET_RBTOP_OK) { mtc_err("init db error"); mutil_redirect("初始化数据库失败", TGT_SELF, URL_CLOSE, true); return ret; } lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL); if (lib == NULL) { mtc_err("possible? %s", dlerror()); mutil_redirect("初始化库函数失败", TGT_SELF, URL_CLOSE, true); return 1; } #ifndef DROP_FCGI cgiwrap_init_emu(NULL, &read_cb, &printf_cb, &write_cb, NULL, NULL, NULL); while (FCGI_Accept() >= 0) { #endif cgiwrap_init_std(argc, argv, environ); err = cgi_init(&cgi, NULL); JUMP_NOK_CGI(err, response); err = cgi_parse(cgi); JUMP_NOK_CGI(err, response); #ifdef NCGI_MODE hdf_set_value(cgi->hdf, PRE_REQ_URI_RW, "/csc/hc"); hdf_set_value(cgi->hdf, PRE_COOKIE".uin", "1001"); hdf_set_value(cgi->hdf, PRE_COOKIE".uname", "bigml"); hdf_set_value(cgi->hdf, PRE_COOKIE".musn", "8Y]u0|v=*MS]U3J"); #endif ret = session_init(cgi->hdf, dbh, &session); if (ret != RET_RBTOP_OK) { mtc_err("init session failure"); goto response; } requri = hdf_get_value(cgi->hdf, PRE_REQ_URI_RW, "NULL"); if (mutil_client_attack(cgi->hdf, requri, LMT_CLI_ATTACK, PERIOD_CLI_ATTACK)) { goto response; } ret = lfile_access_rewrited(cgi, dbh, session); if (ret != RET_RBTOP_OK) { goto response; } data_handler = lutil_get_data_handler(lib, cgi); if (data_handler == NULL) { mtc_err("get handler failure"); ret = RET_RBTOP_NEXIST; goto response; } ret = (*data_handler)(cgi, dbh, session); response: if (cgi != NULL && cgi->hdf != NULL) { #ifdef DEBUG_HDF hdf_write_file(cgi->hdf, TC_ROOT"hdf.viki"); #endif switch (CGI_REQ_TYPE(cgi)) { case CGI_REQ_HTML: if (CGI_REQ_METHOD(cgi) != CGI_REQ_GET) { goto resp_ajax; } if (ret != RET_RBTOP_OK && ret == RET_RBTOP_NEXIST) { cgi_redirect(cgi, "/404.html"); } else { ret = ltpl_render(cgi, tplh, session); if (ret != RET_RBTOP_OK) { if (ret == RET_RBTOP_NEXIST) cgi_redirect(cgi, "/404.html"); else cgi_redirect(cgi, "/503.html"); } } break; case CGI_REQ_AJAX: resp_ajax: ldb_opfinish_json(ret, cgi->hdf, NULL, 0); jsoncb = hdf_get_value(cgi->hdf, PRE_REQ_AJAX_FN, NULL); if (jsoncb != NULL) { mjson_execute_hdf(cgi->hdf, jsoncb, session->tm_cache_browser); } else { mjson_output_hdf(cgi->hdf, session->tm_cache_browser); } break; default: cgi_redirect(cgi, "/503.html"); break; } cgi_destroy(&cgi); session_destroy(&session); } #ifndef DROP_FCGI } #endif ldb_destroy(dbh); ltpl_destroy(tplh); mconfig_cleanup(&g_cfg); return 0; }
int main(){ cgi_init(); cgi_session_start(); cgi_process_form(); int start = atoi(cgi_param("start")); char *h = charmalloc(100); char *u = charmalloc(100); char *p = charmalloc(100); char *d = charmalloc(100); char *fl = charmalloc(100); getvarconf("MYSQL_HOST",&h); getvarconf("MYSQL_USER",&u); getvarconf("MYSQL_PASS",&p); getvarconf("MYSQL_DB",&d); getvarconf("ACCESSWEBLOG", &fl); logfile_init(fl); logerror(__FILE__,__LINE__,"Init "); if(start == 1) { puts("Content-Type: text/plain"); puts(""); MYSQL *connect; connect = mysql_init(NULL); if(!mysql_real_connect(connect, h, u, p, d, MYSQL_PORT, NULL, 0)) { logerror(__FILE__,__LINE__,"Error Mysql: %s",mysql_error(connect)); exit(1); } long double totaleconomy = 0; long double totalhits = 0; long double totalcount = 0; long double totalsize = 0; char pet[350]; char coma = ' '; strcpy(pet,"select domain,COUNT(*) as files,sum(filesize) as size,sum(filesize*requested) as eco, sum(requested) as hits from haarp where deleted=0 and static=0 group by domain order by 1 DESC"); if(mysql_query(connect, pet)) { logerror(__FILE__,__LINE__,"%s",mysql_error(connect)); exit(1); } double percent; MYSQL_RES *res = mysql_store_result(connect); MYSQL_ROW v; puts("{ data: ["); while ( (v = mysql_fetch_row(res)) != NULL ) { if(atoi(v[2])) { percent=(atof(v[3])*100)/atof(v[2]); } else continue; printf("%c{domain : '%s', files: '%s', size : '%s', eco : '%s', hits : '%s', porc :'%0.2lf', active: '%d'}\n",coma,v[0],v[1],v[2],v[3],v[4],percent,getActive(v[0])); coma = ','; totaleconomy += atof(v[3]); totalhits += atof(v[4]); totalcount += atof(v[1]); totalsize += atof(v[2]); } mysql_close(connect); printf("%c{domain: 'Totales', files : '%.2Lf', size : '%.2Lf', eco: '%.2Lf', hits : '%.2Lf', porc : '%.2Lf', active: '1' }\n", coma, totalcount, totalsize, totaleconomy, totalhits, (totaleconomy/totalsize)*100.0); puts("]"); puts("}"); return 1; } if(start == 2) //history HC, max and min date. { puts("Content-Type: text/plain"); puts(""); int len = strlen(cgi_param("domain")); char * domain = (char *)malloc(sizeof(char)*len+2); strcpy(domain,cgi_param("domain")); MYSQL *connect; connect = mysql_init(NULL); if(!mysql_real_connect(connect, h, u, p, d, MYSQL_PORT, NULL, 0)) { printf("{success: false, errors: \"Error, mysql connect\"}"); logerror(__FILE__,__LINE__,"Error Mysql: %s",mysql_error(connect)); exit(1); } char pet[200]; sprintf(pet,"select date(min(downloaded)), date(max(downloaded)) from haarp where domain=trim('%s')",domain); if(mysql_query(connect,pet)) { printf("{success: false, errors: 'Error, mysql connect'}"); logerror(__FILE__,__LINE__,"Error Mysql: %s",mysql_error(connect)); exit(1); } MYSQL_RES * res = mysql_store_result(connect); MYSQL_ROW r = mysql_fetch_row(res); printf("{success: true, min: '%s', max : '%s'}",r[0],r[1]); mysql_close(connect); free(domain); } if(start == 3) //history HC. { MYSQL *connect; connect = mysql_init(NULL); FILE *f = fopen("/tmp/t1","w"); puts("Content-Type: text/plain"); puts(""); if(!mysql_real_connect(connect, h, u, p, d, MYSQL_PORT, NULL, 0)) { printf("{success :false, errors: 'Error, mysql connect'}"); logerror(__FILE__,__LINE__,"Error Mysql: %s",mysql_error(connect)); exit(1); } int len = strlen(cgi_param("data")); char * domain = (char*)malloc(sizeof(char)*(len+2)); strcpy(domain,cgi_param("data")); len = strlen(cgi_param("fecha")); char * date = (char*)malloc(sizeof(char)*(len+2)); strcpy(date,cgi_param("fecha")); //~ trim(date); char pet[200]; sprintf(pet,"select count(*), hour(downloaded) as hora from haarp where domain='%s' and date(downloaded)='%s' group by hora",domain,date); if(mysql_query(connect,pet)) { printf("{success: false, errors: 'Error, mysql query'}"); logerror(__FILE__,__LINE__,"Error Mysql: %s",mysql_error(connect)); exit(1); } MYSQL_RES *res = mysql_store_result(connect); MYSQL_ROW r; lfiles_count *primer = NULL; lfiles_count *ultimo = NULL; while( (r = mysql_fetch_row(res)) != NULL ) { lfiles_count *nodo = (lfiles_count *)malloc(sizeof(lfiles_count)*1); nodo->files = atoi(r[0]); nodo->hora = atoi(r[1]); fprintf(f,"(files) %d\n",nodo->hora); nodo->next = NULL; if(!primer) { primer = nodo; ultimo = nodo; } else { ultimo->next = nodo; ultimo = nodo; } } sprintf(pet,"select count(*),hour(last_request) as hora from haarp where domain='%s' and date(last_request)='%s' and requested>0 group by hora;",domain,date); if(mysql_query(connect,pet)) { printf("{success: false, errors: 'Error, mysql query'}"); logerror(__FILE__,__LINE__,"Error Mysql: %s",mysql_error(connect)); exit(1); } res = mysql_store_result(connect); lfiles_count *primer1 = NULL; lfiles_count *ultimo1 = NULL; while( (r = mysql_fetch_row(res)) != NULL ) { lfiles_count *nodo = (lfiles_count *)malloc(sizeof(lfiles_count)*1); nodo->files = atoi(r[0]); nodo->hora = atoi(r[1]); fprintf(f,"(hits) %d\n", nodo->hora); nodo->next = NULL; if(!primer1) { primer1 = nodo; ultimo1 = nodo; } else { ultimo1->next = nodo; ultimo1 = nodo; } } lfiles_count *nodo = primer; puts("{ data: ["); char p = ' '; int cont = 0; while(nodo) { lfiles_count *nodo1 = primer1; int entro = 0; while(nodo1) { if(nodo->hora > nodo1->hora) { if(nodo1->hora > cont) { int i; for(i=cont;i<nodo1->hora;i++) { printf("%c{domain: '%s', cache: 0, hits: 0, date: '%d:00'}\n",p,domain,i); p = ','; } cont = ++i; } else cont++; printf("%c{domain: '%s', cache: 0, hits: %d, date: '%d:00'}\n",p,domain,nodo1->files,nodo1->hora); p = ','; primer1 = nodo1->next; free(nodo1); nodo1 = primer1; continue; } else if( nodo->hora == nodo1->hora ) { if(nodo->hora > cont) { int i; for(i=cont;i<nodo->hora;i++) { printf("%c{domain: '%s', cache: 0, hits: 0, date: '%d:00'}\n",p,domain,i); p = ','; } cont = ++i; } else cont++; printf("%c{domain: '%s', cache: %d, hits: %d, date: '%d:00'}\n",p,domain,nodo->files,nodo1->files,nodo->hora); p = ','; primer1 = nodo1->next; free(nodo1); entro = 1; break; } else { if(nodo->hora > cont) { int i; for(i=cont;i<nodo->hora;i++) { printf("%c{domain: '%s', cache: 0, hits: 0, date: '%d:00'}\n",p,domain,i); p = ','; } cont = ++i; } else cont++; printf("%c{domain: '%s', cache: %d, hits: 0, date: '%d:00'}\n",p,domain,nodo->files,nodo->hora); p = ','; entro = 1; break; } } if(!entro) { if(nodo->hora > cont) { int i; for(i=cont;i<nodo->hora;i++) { printf("%c{domain: '%s', cache: 0, hits: 0, date: '%d:00'}\n",p,domain,i); p = ','; } cont = ++i; } else cont++; printf("%c{domain: '%s', cache: %d, hits: 0, date: '%d:00'}\n",p,domain,nodo->files,nodo->hora); p = ','; } nodo = nodo->next; } nodo = primer1; while(nodo) { if(nodo->hora > cont) { int i; for(i=cont;i<nodo->hora;i++) { printf("%c{domain: '%s', cache: 0, hits: 0, date: '%d:00'}\n",p,domain,i); p = ','; } cont = ++i; } else cont++; printf("%c{domain: '%s', cache: 0, hits: %d, date: '%d:00'}\n",p,domain,nodo->files,nodo->hora); p = ','; nodo = nodo->next; } if(cont < 23) { int i; for(i=cont;i<=23;i++) { printf("%c{domain: '%s', cache: 0, hits: 0, date: '%d:00'}\n",p,domain,i); p = ','; } } mysql_close(connect); puts("]}"); } return 1; }
int main (void) { char *username; char *password; unsigned returnCode, group; //incluir aceitacao SOMENTE para metodo POST. LibCGI identifica e aceita qualquer metodo cgi_init(); cgi_process_form(); username = cgi_param("username"); password = cgi_param("password"); //se cgi_end viesse aqui teria problema com o username? //a cgi_end libera a memoria alocada, e username eh um ponteiro para uma regiao alocada //porem em uma outra cgi, ao usar cgi_end antes de usar username, o valor de username permaneceu //pq? printf ("Content-type: text/html\r\n"); if (!(returnCode = authenticateUser(username,password,&group))) { /*strncpy(ip,getenv("REMOTE_ADDR"),15); //Creating cookie createCookie(username,cookie,ip); printf("Set-Cookie: %s=%s; path=/",username,cookie);*/ printf("Location: principal.cgi?uid=%s\r\n", username); printf("\r\n"); } /* Mensagem de username ou senha invalido */ else if ((returnCode==WRONG_PASSWORD) || (returnCode==USER_NOT_FOUND) || (returnCode==NULL_POINTER)) { printf("\r\n"); printf ("<html>\n"); printf ("<head>\n"); printf (" <title>Neural TB - Entrar</title>\n"); printf (" <!--<link rel=\"stylesheet\" type=\"text/css\" href=\"css/main.css\">-->\n"); printf (" <link rel=\"stylesheet\" type=\"text/css\" href=\"css/login.css\">\n"); printf (" <script language=javascript src=\"../js/funcoes.js\"></script>\n"); printf (" </head>\n"); printf ("\n"); printf (" <body onLoad=\"login.username.focus()\">\n"); printf (" <div align=\"center\">\n"); printf ("\n"); printf (" <img src=\"../imagens/NeuralTB3.jpg\">\n"); printf (" <br /><br />\n"); printf (" <div class=\"\">\n"); printf (" <table>\n"); printf (" <tr>\n"); printf (" <td style=\"vertical-align:top; padding-top:8px\">\n"); printf (" <form name=\"login\" action=\"login.cgi\" method=\"post\">\n"); printf (" <table border=\"0\">\n"); printf (" <tr>\n"); printf (" <td style=\"text-align:right\">Usuário:</td>\n"); printf (" <td><input name=\"username\" type=\"text\" maxlength=18 ></td>\n"); printf (" </tr>\n"); printf (" <tr>\n"); printf (" <td style=\"text-align:right\">Senha:</td>\n"); printf (" <td><input name=\"password\" type=\"password\" maxlength=18 ></td>\n"); printf (" </tr>\n"); printf (" <tr>\n"); printf (" <td colspan=\"2\" height=\"15\"></td>\n"); printf (" </tr>\n"); printf (" <tr>\n"); printf (" <td></td>\n"); printf (" <td style=\"text-align:right\"><input type=\"submit\" value=\"Entrar\"></td>\n"); printf (" </tr>\n"); if (!(username)||(!password)) { printf (" <tr>\n"); printf (" <td colspan=\"2\" style=\"color:red\">Preencha todos os campos</td>\n"); printf (" </tr>\n"); } else { printf (" <tr>\n"); printf (" <td colspan=\"2\" style=\"color:red\">Usuário e senha nao correspondem</td>\n"); printf (" </tr>\n"); } printf (" </table>\n"); printf (" </form>\n"); printf (" </td>\n"); printf (" <td style=\"padding-left:20px\"><img src=\"../imagens/humanSmallest.jpg\" style=\"z-index:-1\"></td>\n"); printf (" </tr>\n"); printf (" </table>\n"); printf (" </div>\n"); printf ("\n"); printf ("</div>\n"); printf ("</body>\n"); printf ("</html>"); } else { printf("\r\n"); printf("Erro %u", returnCode); } cgi_end(); return 0; }
int main(int argc, char **argv, char **envp) { CGI *cgi = NULL; NEOERR *err; mdb_conn *conn = NULL; /* skey, user, pass, return jsoncallback*/ char *s, *u, *p, *r, *jcbk; /* keeptime(hours) */ int t; char tm[LEN_TM_GMT]; //sleep(20); mtc_init("login"); mconfig_parse_file(SITE_CONFIG, &g_cfg); mutil_wrap_fcgi(argc, argv, envp); if (mdb_init(&conn, DB_DSN) != MDB_ERR_NONE) { mtc_err("init db error %s", mdb_get_errmsg(conn)); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); return 1; } #ifndef DROP_FCGI while (FCGI_Accept() >= 0) { #endif /* * cgi init */ err = cgi_init(&cgi, NULL); if (err != STATUS_OK) { mtc_err("init cgi error"); printf("Content-Type: text/html; charset=UTF-8\r\n\r\n"); printf("{errcode: %d}", SAM_ERR_INIT); goto opfinish; } err = cgi_parse(cgi); if (err != STATUS_OK) { mtc_err("parse cgi error"); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PARSE); goto opfinish; } #if 0 if (mutil_client_attack_cookie(cgi->hdf, "login", 30, 60)) { mtc_err("client attack"); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDREST); goto opfinish; } #endif u = hdf_get_value(cgi->hdf, PRE_COOKIE".samuser", NULL); s = hdf_get_value(cgi->hdf, PRE_COOKIE".samkey", NULL); if (s && u) { if (user_has_login(conn, u, s)) { hdf_set_copy(cgi->hdf, PRE_OUTPUT".samuser", PRE_COOKIE".samuser"); hdf_set_copy(cgi->hdf, PRE_OUTPUT".samkey", PRE_COOKIE".samkey"); goto done; } } u = hdf_get_value(cgi->hdf, PRE_QUERY".u", NULL); p = hdf_get_value(cgi->hdf, PRE_QUERY".p", NULL); if (!u || !p) { mtc_err("parameter miss %s %s", u, p); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_NEEDINPUT); goto opfinish; } s = user_login_auth(conn, u, p); if (!s) { mtc_err("login error %s %s", u, p); hdf_set_int_value(cgi->hdf, PRE_OUTPUT".errcode", SAM_ERR_PASSW); goto opfinish; } cgiwrap_write(P3P_HEADER, strlen(P3P_HEADER)); cgi_cookie_set(cgi, "samuser", u, NULL, SITE_DOMAIN, NULL, 1, 0); cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, NULL, 1, 0); #if 0 t = hdf_get_int_value(cgi->hdf, PRE_QUERY".t", 0); mmisc_getdatetime_gmt(tm, sizeof(tm), "%A, %d-%b-%Y %T GMT", 60*60*t); cgi_cookie_set(cgi, "samkey", s, NULL, SITE_DOMAIN, tm, 1, 0); #endif hdf_set_value(cgi->hdf, PRE_OUTPUT".samuser", u); hdf_set_value(cgi->hdf, PRE_OUTPUT".samkey", s); free(s); done: /* * TODO set samkey, samuser to app's domain * DONE this is done by jsonp */ hdf_set_value(cgi->hdf, PRE_OUTPUT".success", "1"); opfinish: if (cgi) { r = hdf_get_value(cgi->hdf, PRE_QUERY".r", NULL); if (r) { cgi_redirect(cgi, r); } else { jcbk = hdf_get_value(cgi->hdf, PRE_QUERY".jsoncallback", NULL); if (jcbk != NULL) { mjson_execute_hdf(cgi->hdf, jcbk, 0); } else { mjson_output_hdf(cgi->hdf, 0); } } #ifdef DEBUG_HDF hdf_write_file(cgi->hdf, HF_LOG_PATH"hdf.login"); #endif cgi_destroy(&cgi); } #ifndef DROP_FCGI } /* FCGI_Accept() */ #endif mdb_destroy(conn); return 0; }