int main(void) { 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("login"); std::string mdp = getParam("password"); if (login.empty() || mdp.empty()) { cgi_redirect("./login.okz?state=err_fill_all_field"); return 0; } //Login regex boost::regex reg_pseudo("[a-zA-Z0-9]{2,}"); if (!regex_match(login, reg_pseudo)) { cgi_redirect("./login.okz?state=err_login_char"); return 0; } std::string password; mysqlpp::Query query = c.query("SELECT password FROM game_account where login=%0Q;"); query.parse(); mysqlpp::StoreQueryResult r = query.store(login); if (r && r.num_rows() > 0) { r[0]["password"].to_string(password); } else { cgi_redirect("./login.okz?state=err_no_account"); return 0; } hashwrapper* wrapper = new md5wrapper(); std::string md5mdp = wrapper->getHashFromString(mdp); delete wrapper; if (password == md5mdp) { cgi_session_register_var("login", login.c_str()); cgi_session_register_var("locale", "fr_FR.UTF-8"); } else { cgi_redirect("./login.okz?state=err_password"); return 0; } cgi_redirect("./index.okz"); 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(); cgi_init_headers(); header("sidebar_player_list"); menu(); sidebar(); body(c); footer(); cgi_end(); return 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(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(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; }
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; }
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(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(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(){ 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; }