Changeset 5166
- Timestamp:
- 05/04/11 01:27:22 (13 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-http-helpers.c
r5165 r5166 735 735 736 736 #ifdef WITH_SSL 737 pthread_key_t getssl; 738 SSL * cur_ssl(void){ 739 return (SSL *) pthread_getspecific(getssl); 740 } 741 737 742 /* Locking functions for SSL multithreading */ 738 743 static pthread_mutex_t *lock_cs; -
trunk/oscam-http.c
r5165 r5166 18 18 extern void restart_cardreader(struct s_reader *rdr, int32_t restart); 19 19 20 static int32_t running = 1 ;20 static int32_t running = 1, fdopened = 0; 21 21 pthread_mutex_t http_lock; 22 22 … … 33 33 #endif 34 34 35 void refresh_oscam(enum refreshtypes refreshtype , struct in_addr in) {35 void refresh_oscam(enum refreshtypes refreshtype) { 36 36 37 37 switch (refreshtype) { 38 38 case REFR_ACCOUNTS: 39 cs_log("Refresh Accounts requested by WebIF from %s", inet_ntoa(in));39 cs_log("Refresh Accounts requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 40 40 41 41 cs_accounts_chk(); … … 44 44 case REFR_READERS: 45 45 cs_card_info(); 46 cs_log("Refresh Reader/Tiers requested by WebIF from %s", inet_ntoa(in));46 cs_log("Refresh Reader/Tiers requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 47 47 break; 48 48 49 49 case REFR_SERVER: 50 cs_log("Refresh Server requested by WebIF from %s", inet_ntoa(in));50 cs_log("Refresh Server requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 51 51 //kill(first_client->pid, SIGHUP); 52 52 //todo how I can refresh the server after global settings … … 54 54 55 55 case REFR_SERVICES: 56 cs_log("Refresh Services requested by WebIF from %s", inet_ntoa(in));56 cs_log("Refresh Services requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 57 57 //init_sidtab(); 58 58 cs_reinit_clients(cfg.account); … … 61 61 #ifdef CS_ANTICASC 62 62 case REFR_ANTICASC: 63 cs_log("Refresh Anticascading requested by WebIF from %s", inet_ntoa(in));63 cs_log("Refresh Anticascading requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 64 64 kill_ac_client(); 65 65 #endif … … 69 69 } 70 70 71 char *send_oscam_config_global(struct templatevars *vars, struct uriparams *params , struct in_addr in) {71 char *send_oscam_config_global(struct templatevars *vars, struct uriparams *params) { 72 72 int32_t i; 73 73 … … 83 83 if(cfg.usrfile == NULL) cfg.disableuserfile = 1; 84 84 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Global done. You should restart Oscam now.</B><BR><BR>"); 85 if(write_config()==0) refresh_oscam(REFR_SERVER , in);85 if(write_config()==0) refresh_oscam(REFR_SERVER); 86 86 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 87 87 } … … 147 147 } 148 148 149 char *send_oscam_config_loadbalancer(struct templatevars *vars, struct uriparams *params , struct in_addr in) {149 char *send_oscam_config_loadbalancer(struct templatevars *vars, struct uriparams *params) { 150 150 int32_t i; 151 151 … … 181 181 } 182 182 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Loadbalancer done.</B><BR><BR>"); 183 if(write_config()==0) refresh_oscam(REFR_SERVER , in);183 if(write_config()==0) refresh_oscam(REFR_SERVER); 184 184 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 185 185 } … … 219 219 } 220 220 221 char *send_oscam_config_camd33(struct templatevars *vars, struct uriparams *params , struct in_addr in) {221 char *send_oscam_config_camd33(struct templatevars *vars, struct uriparams *params) { 222 222 int32_t i; 223 223 … … 234 234 } 235 235 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration camd33 done. You should restart Oscam now.</B><BR><BR>"); 236 if(write_config()==0) refresh_oscam(REFR_SERVER , in);236 if(write_config()==0) refresh_oscam(REFR_SERVER); 237 237 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 238 238 } … … 252 252 } 253 253 254 char *send_oscam_config_camd35(struct templatevars *vars, struct uriparams *params , struct in_addr in) {254 char *send_oscam_config_camd35(struct templatevars *vars, struct uriparams *params) { 255 255 int32_t i; 256 256 if ((strcmp(getParam(params, "action"),"execute") == 0) && (getParam(params, "port"))[0]) { … … 263 263 } 264 264 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration camd35 done. You should restart Oscam now.</B><BR><BR>"); 265 if(write_config()==0) refresh_oscam(REFR_SERVER , in);265 if(write_config()==0) refresh_oscam(REFR_SERVER); 266 266 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 267 267 } … … 279 279 } 280 280 281 char *send_oscam_config_camd35tcp(struct templatevars *vars, struct uriparams *params , struct in_addr in) {281 char *send_oscam_config_camd35tcp(struct templatevars *vars, struct uriparams *params) { 282 282 int32_t i; 283 283 if ((strcmp(getParam(params, "action"),"execute") == 0) && (getParam(params, "port"))[0]) { … … 291 291 } 292 292 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration camd35 TCP done. You should restart Oscam now.</B><BR><BR>"); 293 if(write_config()==0) refresh_oscam(REFR_SERVER , in);293 if(write_config()==0) refresh_oscam(REFR_SERVER); 294 294 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 295 295 } … … 310 310 } 311 311 312 char *send_oscam_config_newcamd(struct templatevars *vars, struct uriparams *params , struct in_addr in) {312 char *send_oscam_config_newcamd(struct templatevars *vars, struct uriparams *params) { 313 313 int32_t i; 314 314 if (strcmp(getParam(params, "action"),"execute") == 0) { … … 325 325 } 326 326 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Newcamd done. You should restart Oscam now.</B><BR><BR>"); 327 if(write_config()==0) refresh_oscam(REFR_SERVER , in);327 if(write_config()==0) refresh_oscam(REFR_SERVER); 328 328 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 329 329 } … … 352 352 } 353 353 354 char *send_oscam_config_radegast(struct templatevars *vars, struct uriparams *params , struct in_addr in) {354 char *send_oscam_config_radegast(struct templatevars *vars, struct uriparams *params) { 355 355 int32_t i; 356 356 if (strcmp(getParam(params, "action"),"execute") == 0) { … … 366 366 } 367 367 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Radegast done. You should restart Oscam now.</B><BR><BR>"); 368 if(write_config()==0) refresh_oscam(REFR_SERVER , in);368 if(write_config()==0) refresh_oscam(REFR_SERVER); 369 369 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 370 370 } … … 381 381 } 382 382 383 char *send_oscam_config_cccam(struct templatevars *vars, struct uriparams *params , struct in_addr in) {383 char *send_oscam_config_cccam(struct templatevars *vars, struct uriparams *params) { 384 384 385 385 if (strcmp(getParam(params, "button"), "Refresh global list") == 0) { … … 399 399 } 400 400 } 401 if(write_config()==0) refresh_oscam(REFR_SERVER , in);401 if(write_config()==0) refresh_oscam(REFR_SERVER); 402 402 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 403 403 } … … 448 448 } 449 449 450 char *send_oscam_config_monitor(struct templatevars *vars, struct uriparams *params , struct in_addr in) {450 char *send_oscam_config_monitor(struct templatevars *vars, struct uriparams *params) { 451 451 int32_t i; 452 452 if (strcmp(getParam(params, "action"),"execute") == 0) { … … 469 469 } 470 470 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Monitor done. You should restart Oscam now.</B><BR><BR>"); 471 if(write_config()==0) refresh_oscam(REFR_SERVER , in);471 if(write_config()==0) refresh_oscam(REFR_SERVER); 472 472 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 473 473 } … … 546 546 } 547 547 548 char *send_oscam_config_serial(struct templatevars *vars, struct uriparams *params , struct in_addr in) {548 char *send_oscam_config_serial(struct templatevars *vars, struct uriparams *params) { 549 549 int32_t i; 550 550 if (strcmp(getParam(params, "action"),"execute") == 0) { … … 560 560 } 561 561 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Serial done. You should restart Oscam now.</B><BR><BR>"); 562 if(write_config()==0) refresh_oscam(REFR_SERVER , in);562 if(write_config()==0) refresh_oscam(REFR_SERVER); 563 563 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 564 564 } … … 584 584 585 585 #ifdef HAVE_DVBAPI 586 char *send_oscam_config_dvbapi(struct templatevars *vars, struct uriparams *params , struct in_addr in) {586 char *send_oscam_config_dvbapi(struct templatevars *vars, struct uriparams *params) { 587 587 int32_t i; 588 588 if (strcmp(getParam(params, "action"),"execute") == 0) { … … 595 595 } 596 596 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration DVB Api done. You should restart Oscam now.</B><BR><BR>"); 597 if(write_config()==0) refresh_oscam(REFR_SERVER , in);597 if(write_config()==0) refresh_oscam(REFR_SERVER); 598 598 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 599 599 } … … 626 626 627 627 #ifdef CS_ANTICASC 628 char *send_oscam_config_anticasc(struct templatevars *vars, struct uriparams *params , struct in_addr in) {628 char *send_oscam_config_anticasc(struct templatevars *vars, struct uriparams *params) { 629 629 int32_t i; 630 630 if (strcmp(getParam(params, "action"),"execute") == 0) { … … 637 637 } 638 638 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Anticascading done. You should restart Oscam now.</B><BR><BR>"); 639 refresh_oscam(REFR_ANTICASC , in);640 if(write_config()==0) refresh_oscam(REFR_SERVER , in);639 refresh_oscam(REFR_ANTICASC); 640 if(write_config()==0) refresh_oscam(REFR_SERVER); 641 641 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 642 642 } … … 656 656 #endif 657 657 658 char *send_oscam_config(struct templatevars *vars, struct uriparams *params , struct in_addr in) {658 char *send_oscam_config(struct templatevars *vars, struct uriparams *params) { 659 659 char *part = getParam(params, "part"); 660 if (!strcmp(part,"camd33")) return send_oscam_config_camd33(vars, params , in);661 else if (!strcmp(part,"camd35")) return send_oscam_config_camd35(vars, params , in);662 else if (!strcmp(part,"camd35tcp")) return send_oscam_config_camd35tcp(vars, params , in);663 else if (!strcmp(part,"newcamd")) return send_oscam_config_newcamd(vars, params , in);664 else if (!strcmp(part,"radegast")) return send_oscam_config_radegast(vars, params , in);665 else if (!strcmp(part,"cccam")) return send_oscam_config_cccam(vars, params , in);660 if (!strcmp(part,"camd33")) return send_oscam_config_camd33(vars, params); 661 else if (!strcmp(part,"camd35")) return send_oscam_config_camd35(vars, params); 662 else if (!strcmp(part,"camd35tcp")) return send_oscam_config_camd35tcp(vars, params); 663 else if (!strcmp(part,"newcamd")) return send_oscam_config_newcamd(vars, params); 664 else if (!strcmp(part,"radegast")) return send_oscam_config_radegast(vars, params); 665 else if (!strcmp(part,"cccam")) return send_oscam_config_cccam(vars, params); 666 666 #ifdef HAVE_DVBAPI 667 else if (!strcmp(part,"dvbapi")) return send_oscam_config_dvbapi(vars, params , in);667 else if (!strcmp(part,"dvbapi")) return send_oscam_config_dvbapi(vars, params); 668 668 #endif 669 669 #ifdef CS_ANTICASC 670 else if (!strcmp(part,"anticasc")) return send_oscam_config_anticasc(vars, params , in);670 else if (!strcmp(part,"anticasc")) return send_oscam_config_anticasc(vars, params); 671 671 #endif 672 else if (!strcmp(part,"monitor")) return send_oscam_config_monitor(vars, params , in);673 else if (!strcmp(part,"serial")) return send_oscam_config_serial(vars, params , in);674 else if (!strcmp(part,"loadbalancer")) return send_oscam_config_loadbalancer(vars, params , in);675 else return send_oscam_config_global(vars, params , in);672 else if (!strcmp(part,"monitor")) return send_oscam_config_monitor(vars, params); 673 else if (!strcmp(part,"serial")) return send_oscam_config_serial(vars, params); 674 else if (!strcmp(part,"loadbalancer")) return send_oscam_config_loadbalancer(vars, params); 675 else return send_oscam_config_global(vars, params); 676 676 } 677 677 … … 690 690 } 691 691 692 char *send_oscam_reader(struct templatevars *vars, struct uriparams *params , struct in_addr in) {692 char *send_oscam_reader(struct templatevars *vars, struct uriparams *params) { 693 693 struct s_reader *rdr; 694 694 int32_t i; … … 734 734 ll_remove(configured_readers, rdr); 735 735 736 if(write_server()==0) refresh_oscam(REFR_READERS , in);736 if(write_server()==0) refresh_oscam(REFR_READERS); 737 737 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 738 738 } … … 756 756 }*/ 757 757 758 refresh_oscam(REFR_READERS , in); // refresh all reader because write pipe seams not work from here758 refresh_oscam(REFR_READERS); // refresh all reader because write pipe seams not work from here 759 759 } 760 760 } … … 840 840 } 841 841 842 char *send_oscam_reader_config(struct templatevars *vars, struct uriparams *params , struct in_addr in) {842 char *send_oscam_reader_config(struct templatevars *vars, struct uriparams *params) { 843 843 int32_t i; 844 844 char *reader_ = getParam(params, "label"); … … 914 914 915 915 if(write_server()==0) { 916 refresh_oscam(REFR_READERS , in);916 refresh_oscam(REFR_READERS); 917 917 // fixme: restart_cardreader causes segfaults sometimes 918 918 if (rdr->typ & R_IS_NETWORK) … … 1209 1209 } 1210 1210 1211 char *send_oscam_reader_stats(struct templatevars *vars, struct uriparams *params, struct in_addr in,int32_t apicall) {1212 1213 tpl_printf(vars, TPLADD, "CALLINGIP", "%s", inet_ntoa(in));1211 char *send_oscam_reader_stats(struct templatevars *vars, struct uriparams *params, int32_t apicall) { 1212 1213 tpl_printf(vars, TPLADD, "CALLINGIP", "%s", cs_inet_ntoa(cur_client()->ip)); 1214 1214 1215 1215 struct s_reader *rdr = get_reader_by_label(getParam(params, "label")); … … 1219 1219 if(rdr) { 1220 1220 clear_reader_stat(rdr); 1221 cs_log("Reader %s stats resetted by WebIF from %s", rdr->label, inet_ntoa(in));1221 cs_log("Reader %s stats resetted by WebIF from %s", rdr->label, cs_inet_ntoa(cur_client()->ip)); 1222 1222 } 1223 1223 } … … 1378 1378 } 1379 1379 1380 char *send_oscam_user_config_edit(struct templatevars *vars, struct uriparams *params , struct in_addr in) {1380 char *send_oscam_user_config_edit(struct templatevars *vars, struct uriparams *params) { 1381 1381 struct s_auth *account, *ptr; 1382 1382 char user[sizeof(first_client->account->usr)]; … … 1418 1418 1419 1419 if (write_userdb(cfg.account)==0) 1420 refresh_oscam(REFR_ACCOUNTS , in);1420 refresh_oscam(REFR_ACCOUNTS); 1421 1421 else 1422 1422 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); … … 1452 1452 1453 1453 if (write_userdb(cfg.account)==0) 1454 refresh_oscam(REFR_ACCOUNTS , in);1454 refresh_oscam(REFR_ACCOUNTS); 1455 1455 else 1456 1456 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); … … 1577 1577 } 1578 1578 1579 char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, struct in_addr in,int32_t apicall) {1579 char *send_oscam_user_config(struct templatevars *vars, struct uriparams *params, int32_t apicall) { 1580 1580 struct s_auth *account, *account2; 1581 1581 char *user = getParam(params, "user"); … … 1588 1588 if (strcmp(getParam(params, "action"), "reinit") == 0) { 1589 1589 if(!cfg.http_readonly) 1590 refresh_oscam(REFR_ACCOUNTS , in);1590 refresh_oscam(REFR_ACCOUNTS); 1591 1591 } 1592 1592 … … 1614 1614 if (found > 0) { 1615 1615 if (write_userdb(cfg.account)==0) 1616 refresh_oscam(REFR_ACCOUNTS , in);1616 refresh_oscam(REFR_ACCOUNTS); 1617 1617 else 1618 1618 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); … … 1630 1630 account->disabled = 0; 1631 1631 if (write_userdb(cfg.account) == 0) 1632 refresh_oscam(REFR_ACCOUNTS , in);1632 refresh_oscam(REFR_ACCOUNTS); 1633 1633 } else { 1634 1634 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>"); … … 1812 1812 #define ENTITLEMENT_PAGE_SIZE 500 1813 1813 1814 char *send_oscam_entitlement(struct templatevars *vars, struct uriparams *params, struct in_addr in,int32_t apicall) {1814 char *send_oscam_entitlement(struct templatevars *vars, struct uriparams *params, int32_t apicall) { 1815 1815 1816 1816 //just to stop the guys open tedious tickets for warnings related to unused variables xD 1817 tpl_printf(vars, TPLADD, "CALLINGIP", "%s", inet_ntoa(in));1817 tpl_printf(vars, TPLADD, "CALLINGIP", "%s", cs_inet_ntoa(cur_client()->ip)); 1818 1818 tpl_printf(vars, TPLADD, "ISAPICALL", "%d", apicall); 1819 1819 //************** … … 2079 2079 } 2080 2080 2081 char *send_oscam_status(struct templatevars *vars, struct uriparams *params, struct in_addr in,int32_t apicall) {2081 char *send_oscam_status(struct templatevars *vars, struct uriparams *params, int32_t apicall) { 2082 2082 int32_t i; 2083 2083 char *usr; … … 2090 2090 if (cl) { 2091 2091 kill_thread(cl); 2092 cs_log("Client %s killed by WebIF from %s", cl->account->usr, inet_ntoa(in));2092 cs_log("Client %s killed by WebIF from %s", cl->account->usr, cs_inet_ntoa(cur_client()->ip)); 2093 2093 } 2094 2094 } … … 2098 2098 if(rdr) { 2099 2099 restart_cardreader(rdr, 1); 2100 cs_log("Reader %s restarted by WebIF from %s", rdr->label, inet_ntoa(in));2100 cs_log("Reader %s restarted by WebIF from %s", rdr->label, cs_inet_ntoa(cur_client()->ip)); 2101 2101 } 2102 2102 } … … 2133 2133 chk_t_webif("httphideidleclients", hideidle); 2134 2134 if(oldval != cfg.http_hide_idle_clients) { 2135 refresh_oscam(REFR_SERVER , in);2135 refresh_oscam(REFR_SERVER); 2136 2136 } 2137 2137 } … … 2504 2504 } 2505 2505 2506 char *send_oscam_services_edit(struct templatevars *vars, struct uriparams *params , struct in_addr in) {2506 char *send_oscam_services_edit(struct templatevars *vars, struct uriparams *params) { 2507 2507 struct s_sidtab *sidtab,*ptr; 2508 2508 char label[sizeof(cfg.sidtab->label)]; … … 2532 2532 2533 2533 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>New service has been added</b><BR>"); 2534 if (write_services()==0) refresh_oscam(REFR_SERVICES , in);2534 if (write_services()==0) refresh_oscam(REFR_SERVICES); 2535 2535 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Writing services to disk failed!</b><BR>"); 2536 2536 … … 2545 2545 } 2546 2546 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Services updated</B><BR><BR>"); 2547 if (write_services()==0) refresh_oscam(REFR_SERVICES , in);2547 if (write_services()==0) refresh_oscam(REFR_SERVICES); 2548 2548 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>"); 2549 2549 … … 2570 2570 } 2571 2571 2572 char *send_oscam_services(struct templatevars *vars, struct uriparams *params , struct in_addr in) {2572 char *send_oscam_services(struct templatevars *vars, struct uriparams *params) { 2573 2573 struct s_sidtab *sidtab, *sidtab2; 2574 2574 char *service = getParam(params, "service"); … … 2597 2597 if (found > 0) { 2598 2598 tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Service has been deleted!</b><BR>"); 2599 if (write_services() == 0) refresh_oscam(REFR_SERVICES , in);2599 if (write_services() == 0) refresh_oscam(REFR_SERVICES); 2600 2600 else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Writing services to disk failed!</b><BR>"); 2601 2601 } else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified service doesn't exist. No deletion will be made!</b><BR>"); … … 2635 2635 } 2636 2636 2637 char *send_oscam_shutdown(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in,int32_t apicall) {2637 char *send_oscam_shutdown(struct templatevars *vars, FILE *f, struct uriparams *params, int32_t apicall) { 2638 2638 if (strcmp(strtolower(getParam(params, "action")), "shutdown") == 0) { 2639 2639 if(!apicall){ … … 2646 2646 send_headers(f, 200, "OK", NULL, "text/html", 0, strlen(result), 0); 2647 2647 webif_write(result, f); 2648 cs_log("Shutdown requested by WebIF from %s", inet_ntoa(in));2648 cs_log("Shutdown requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 2649 2649 } else { 2650 2650 tpl_addVar(vars, TPLADD, "APICONFIRMMESSAGE", "shutdown"); 2651 cs_log("Shutdown requested by XMLApi from %s", inet_ntoa(in));2651 cs_log("Shutdown requested by XMLApi from %s", cs_inet_ntoa(cur_client()->ip)); 2652 2652 } 2653 2653 running = 0; … … 2663 2663 if(!apicall){ 2664 2664 tpl_addVar(vars, TPLADD, "STYLESHEET", CSS); 2665 tpl_printf(vars, TPLADD, "REFRESHTIME", " %d", 2);2665 tpl_printf(vars, TPLADD, "REFRESHTIME", "2"); 2666 2666 tpl_addVar(vars, TPLADD, "REFRESHURL", "status.html"); 2667 2667 tpl_addVar(vars, TPLADD, "REFRESH", tpl_getTpl(vars, "REFRESH")); 2668 tpl_ printf(vars, TPLADD, "SECONDS", "%d", 2);2668 tpl_addVar(vars, TPLADD, "SECONDS", "5"); 2669 2669 char *result = tpl_getTpl(vars, "SHUTDOWN"); 2670 2670 send_headers(f, 200, "OK", NULL, "text/html", 0,strlen(result), 0); 2671 2671 webif_write(result, f); 2672 cs_log("Restart requested by WebIF from %s", inet_ntoa(in));2672 cs_log("Restart requested by WebIF from %s", cs_inet_ntoa(cur_client()->ip)); 2673 2673 } else { 2674 2674 tpl_addVar(vars, TPLADD, "APICONFIRMMESSAGE", "restart"); 2675 cs_log("Restart requested by XMLApi from %s", inet_ntoa(in));2675 cs_log("Restart requested by XMLApi from %s", cs_inet_ntoa(cur_client()->ip)); 2676 2676 } 2677 2677 running = 0; … … 2991 2991 } 2992 2992 2993 char *send_oscam_api(struct templatevars *vars, FILE *f, struct uriparams *params , struct in_addr in) {2993 char *send_oscam_api(struct templatevars *vars, FILE *f, struct uriparams *params) { 2994 2994 if (strcmp(getParam(params, "part"), "status") == 0) { 2995 return send_oscam_status(vars, params, in,1);2995 return send_oscam_status(vars, params, 1); 2996 2996 } 2997 2997 else if (strcmp(getParam(params, "part"), "userstats") == 0) { 2998 return send_oscam_user_config(vars, params, in,1);2998 return send_oscam_user_config(vars, params, 1); 2999 2999 } 3000 3000 else if (strcmp(getParam(params, "part"), "entitlement") == 0) { … … 3004 3004 if (rdr) { 3005 3005 if (rdr->typ == R_CCCAM && rdr->enable == 1) { 3006 return send_oscam_entitlement(vars, params, in,1);3006 return send_oscam_entitlement(vars, params, 1); 3007 3007 } else { 3008 3008 //Send Errormessage … … 3025 3025 struct s_reader *rdr = get_reader_by_label(getParam(params, "label")); 3026 3026 if (rdr) { 3027 return send_oscam_reader_stats(vars, params, in,1);3027 return send_oscam_reader_stats(vars, params, 1); 3028 3028 } else { 3029 3029 //Send Errormessage … … 3040 3040 (strcmp(strtolower(getParam(params, "action")), "shutdown") == 0)){ 3041 3041 if(!cfg.http_readonly) { 3042 return send_oscam_shutdown(vars, f, params, in,1);3042 return send_oscam_shutdown(vars, f, params, 1); 3043 3043 } else { 3044 3044 tpl_addVar(vars, TPLADD, "APIERRORMESSAGE", "webif readonly mode"); … … 3083 3083 3084 3084 int32_t readRequest(FILE *f, struct in_addr in, char **result, int8_t forcePlain){ 3085 int32_t n, bufsize=0, errcount = 0 ;3085 int32_t n, bufsize=0, errcount = 0, is_ssl = 0; 3086 3086 char buf2[1024]; 3087 3087 struct pollfd pfd2[1]; 3088 #ifdef WITH_SSL 3089 if (ssl_active && !forcePlain) 3090 is_ssl = 1; 3091 #endif 3088 3092 3089 3093 while (1) { … … 3094 3098 n=webif_read(buf2, sizeof(buf2), f); 3095 3099 if (n <= 0) { 3096 if ((!ssl_active || forcePlain) && (errno == 0 || errno == EINTR || errno == EAGAIN) && errcount++ < 10){ 3097 cs_sleepms(1); 3098 continue; 3099 } 3100 cs_debug_mask(D_CLIENT, "webif read error %d (errno=%d %s)", n, errno, strerror(errno)); 3100 if ((!is_ssl) && (errno == 0 || errno == EINTR || errno == EAGAIN)){ 3101 if(errcount++ < 10){ 3102 cs_sleepms(5); 3103 continue; 3104 } else return -1; 3105 } 3101 3106 #ifdef WITH_SSL 3102 if (ssl_active && !forcePlain) 3103 ERR_print_errors_fp(stderr); 3107 if (is_ssl){ 3108 int32_t errcode = ERR_peek_error(); 3109 char errstring[128]; 3110 ERR_error_string_n(errcode, errstring, sizeof(errstring) - 1); 3111 cs_debug_mask(D_CLIENT, "WebIf: read error ret=%d (%d%s%s)", n, SSL_get_error(cur_ssl(), n), errcode?" ":"", errcode?errstring:""); 3112 return -1; 3113 } 3114 #else 3115 cs_debug_mask(D_CLIENT, "WebIf: read error ret=%d (errno=%d %s)", n, errno, strerror(errno)); 3104 3116 #endif 3105 3117 return -1; … … 3145 3157 } 3146 3158 3147 int32_t process_request(FILE *f, struct in_addr in) { 3148 3149 cur_client()->last = time((time_t)0); //reset last busy time 3150 3159 int32_t process_request(FILE *f, struct in_addr in) { 3151 3160 int32_t ok=0,v=cv(); 3152 in_addr_t addr = in.s_addr;3153 3154 ok = check_ip(cfg.http_allowed, in.s_addr) ? v : 0;3161 in_addr_t addr = cur_client()->ip; 3162 3163 ok = check_ip(cfg.http_allowed, addr) ? v : 0; 3155 3164 3156 3165 if (!ok && cfg.http_dyndns[0]) { … … 3213 3222 if (!ok) { 3214 3223 send_error(f, 403, "Forbidden", NULL, "Access denied.", 0); 3215 cs_log("unauthorized access from %s flag %d", inet_ntoa(in), v);3224 cs_log("unauthorized access from %s flag %d", cs_inet_ntoa(addr), v); 3216 3225 return 0; 3217 3226 } … … 3257 3266 3258 3267 if (!filebuf || bufsize < 1) { 3259 cs_ log("error: no data received");3268 cs_debug_mask(D_CLIENT, "WebIf: No data received from client %s. Closing connection.", cs_inet_ntoa(addr)); 3260 3269 return -1; 3261 3270 } … … 3364 3373 3365 3374 tpl_addVar(vars, TPLADD, "UPTIME", sec2timeformat(vars, (now - first_client->login))); 3366 tpl_printf(vars, TPLADD, "CURIP", "%s", inet_ntoa(in));3375 tpl_printf(vars, TPLADD, "CURIP", "%s", cs_inet_ntoa(addr)); 3367 3376 if(cfg.http_readonly) 3368 3377 tpl_addVar(vars, TPLAPPEND, "BTNDISABLED", "DISABLED"); … … 3373 3382 if(pgidx != 19 && pgidx != 20) pthread_mutex_lock(&http_lock); 3374 3383 switch(pgidx) { 3375 case 0: result = send_oscam_config(vars, ¶ms , in); break;3376 case 1: result = send_oscam_reader(vars, ¶ms , in); break;3377 case 2: result = send_oscam_entitlement(vars, ¶ms, in,0); break;3378 case 3: result = send_oscam_status(vars, ¶ms, in,0); break;3379 case 4: result = send_oscam_user_config(vars, ¶ms, in,0); break;3380 case 5: result = send_oscam_reader_config(vars, ¶ms , in); break;3381 case 6: result = send_oscam_services(vars, ¶ms , in); break;3382 case 7: result = send_oscam_user_config_edit(vars, ¶ms , in); break;3384 case 0: result = send_oscam_config(vars, ¶ms); break; 3385 case 1: result = send_oscam_reader(vars, ¶ms); break; 3386 case 2: result = send_oscam_entitlement(vars, ¶ms, 0); break; 3387 case 3: result = send_oscam_status(vars, ¶ms, 0); break; 3388 case 4: result = send_oscam_user_config(vars, ¶ms, 0); break; 3389 case 5: result = send_oscam_reader_config(vars, ¶ms); break; 3390 case 6: result = send_oscam_services(vars, ¶ms); break; 3391 case 7: result = send_oscam_user_config_edit(vars, ¶ms); break; 3383 3392 //case 8: css file 3384 case 9: result = send_oscam_services_edit(vars, ¶ms , in); break;3393 case 9: result = send_oscam_services_edit(vars, ¶ms); break; 3385 3394 case 10: result = send_oscam_savetpls(vars); break; 3386 case 11: result = send_oscam_shutdown(vars, f, ¶ms, in,0); break;3395 case 11: result = send_oscam_shutdown(vars, f, ¶ms, 0); break; 3387 3396 case 12: result = send_oscam_script(vars); break; 3388 3397 case 13: result = send_oscam_scanusb(vars); break; 3389 3398 case 14: result = send_oscam_files(vars, ¶ms); break; 3390 case 15: result = send_oscam_reader_stats(vars, ¶ms, in,0); break;3399 case 15: result = send_oscam_reader_stats(vars, ¶ms, 0); break; 3391 3400 case 16: result = send_oscam_failban(vars, ¶ms); break; 3392 3401 //case 17: js file 3393 case 18: result = send_oscam_api(vars, f, ¶ms , in); break;3402 case 18: result = send_oscam_api(vars, f, ¶ms); break; 3394 3403 case 19: result = send_oscam_image(vars, f, ¶ms, NULL); break; 3395 3404 case 20: result = send_oscam_image(vars, f, ¶ms, "ICMAI"); break; 3396 default: result = send_oscam_status(vars, ¶ms, in,0); break;3405 default: result = send_oscam_status(vars, ¶ms, 0); break; 3397 3406 } 3398 3407 if(pgidx != 19 && pgidx != 20) pthread_mutex_unlock(&http_lock); … … 3414 3423 #pragma GCC diagnostic ignored "-Wempty-body" 3415 3424 void *serve_process(void *conn){ 3416 struct s_connection myconn; 3417 memcpy(&myconn, conn, sizeof(struct s_connection)); //copy to stack to free init pointer 3418 free(conn); 3419 struct sockaddr_in remote = myconn.remote; 3420 int32_t s = myconn.socket; 3425 struct s_connection *myconn = (struct s_connection*)conn; 3426 int32_t s = myconn->socket; 3427 struct s_client *cl = myconn->cl; 3428 struct in_addr in = myconn->remote; 3421 3429 #ifdef WITH_SSL 3422 SSL *ssl = myconn.ssl; 3430 SSL *ssl = myconn->ssl; 3431 pthread_setspecific(getssl, ssl); 3423 3432 #endif 3424 3425 struct s_client *cl = create_client(remote.sin_addr.s_addr); 3426 if (cl == NULL) { 3427 close(s); 3428 return NULL; 3429 } 3430 cl->typ = 'i'; 3431 cl->wihidden = 1; 3433 free(myconn); 3432 3434 cl->thread = pthread_self(); 3433 3435 pthread_setspecific(getclient, cl); … … 3460 3462 } 3461 3463 } 3462 if (ok) 3463 process_request((FILE *)ssl, remote.sin_addr); 3464 else { 3464 if (ok){ 3465 fdopened = 1; 3466 process_request((FILE *)ssl, in); 3467 } else { 3465 3468 FILE *f; 3466 3469 f = fdopen(s, "r+"); 3470 fdopened = 1; 3467 3471 if(f != NULL) { 3468 3472 char *ptr, *filebuf = NULL, *host = NULL; 3469 int32_t bufsize = readRequest(f, remote.sin_addr, &filebuf, 1);3473 int32_t bufsize = readRequest(f, in, &filebuf, 1); 3470 3474 3471 3475 if (filebuf) { … … 3497 3501 FILE *f; 3498 3502 f = fdopen(s, "r+"); 3503 fdopened = 1; 3499 3504 if(f != NULL) { 3500 process_request(f, remote.sin_addr);3505 process_request(f, in); 3501 3506 fflush(f); 3502 3507 fclose(f); … … 3516 3521 pthread_t workthread; 3517 3522 pthread_attr_t attr; 3518 pthread_attr_init(&attr);3519 #ifndef TUXBOX3520 pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE);3521 #endif3522 3523 struct s_client * cl = create_client(first_client->ip); 3523 3524 if (cl == NULL) return; … … 3597 3598 close(s); 3598 3599 continue; 3599 }; 3600 conn->remote = remote; 3600 }; 3601 struct s_client *cl = create_client(remote.sin_addr.s_addr); 3602 if (cl == NULL) { 3603 close(s); 3604 free(conn); 3605 continue; 3606 } 3607 cur_client()->last = cl->last = time((time_t)0); //reset last busy time 3608 cl->typ = 'i'; 3609 cl->wihidden = 1; 3610 cl->port=ntohs(remote.sin_port); 3611 conn->cl = cl; 3612 memcpy(&conn->remote, &remote, sizeof(struct in_addr)); 3601 3613 conn->socket = s; 3602 3614 #ifdef WITH_SSL 3603 SSL *ssl = NULL;3615 conn->ssl = NULL; 3604 3616 if (ssl_active){ 3605 ssl = SSL_new(ctx);3606 if( ssl == NULL){3617 conn->ssl = SSL_new(ctx); 3618 if(conn->ssl == NULL){ 3607 3619 close(s); 3608 3620 cs_log("WebIf: Error calling SSL_new()."); … … 3610 3622 } 3611 3623 } 3612 conn->ssl = ssl;3613 3624 #endif 3625 pthread_attr_init(&attr); 3626 #ifndef TUXBOX 3627 pthread_attr_setstacksize(&attr, PTHREAD_STACK_SIZE); 3628 #endif 3629 fdopened = 0; 3614 3630 if (pthread_create(&workthread, &attr, serve_process, (void *)conn)) { 3615 3631 cs_log("ERROR: can't create thread for webif"); 3616 } 3617 else 3632 cleanup_thread(cl); 3633 free(conn); 3634 } 3635 else { 3618 3636 pthread_detach(workthread); 3637 int8_t i = 0; 3638 // Wait until the thread has finished opening the file descriptor 3639 while(!fdopened && i < 50){ 3640 ++i; 3641 cs_sleepms(2); 3642 } 3643 } 3644 pthread_attr_destroy(&attr); 3619 3645 } 3620 3646 } -
trunk/oscam-http.h
r5165 r5166 1 1 struct s_connection{ 2 2 int32_t socket; 3 struct sockaddr_in remote; 3 struct s_client *cl; 4 struct in_addr remote; 4 5 #ifdef WITH_SSL 5 6 SSL *ssl; … … 7 8 }; 8 9 10 #ifdef WITH_SSL 9 11 static int32_t ssl_active = 0; 12 #endif 10 13 11 14 /* The server string in the http header */
Note:
See TracChangeset
for help on using the changeset viewer.