Index: /trunk/oscam-http-helpers.c
===================================================================
--- /trunk/oscam-http-helpers.c (revision 1693)
+++ /trunk/oscam-http-helpers.c (revision 1693)
@@ -0,0 +1,424 @@
+#ifdef WEBIF
+#include "oscam-http.h"
+
+/* Adds a name->value-mapping or appends to it. You will get a reference back which you may freely
+ use (but you should not call free/realloc on this!)*/
+char *tpl_addVar(struct templatevars *vars, int append, char *name, char *value){
+ int i;
+ char *tmp,*result = NULL;
+ for(i = (*vars).varscnt-1; i >= 0; --i){
+ if(strcmp((*vars).names[i], name) == 0){
+ result = (*vars).values[i];
+ break;
+ }
+ }
+ if(result == NULL){
+ if((*vars).varsalloc <= (*vars).varscnt){
+ (*vars).varsalloc = (*vars).varscnt * 2;
+ (*vars).names = (char**) realloc ((*vars).names, (*vars).varsalloc * sizeof(char**));
+ (*vars).values = (char**) realloc ((*vars).values, (*vars).varsalloc * sizeof(char**));
+ }
+ tmp = (char *) malloc((strlen(name) + 1) * sizeof(char));
+ strcpy(tmp, name);
+ (*vars).names[(*vars).varscnt] = tmp;
+ tmp = (char *) malloc((strlen(value) + 1) * sizeof(char));
+ strcpy(tmp, value);
+ (*vars).values[(*vars).varscnt] = tmp;
+ (*vars).varscnt = (*vars).varscnt + 1;
+ } else {
+ int newlen = strlen(value);
+ if(append == 1){
+ int oldlen = strlen((*vars).values[i]);
+ tmp = (char*) malloc ((oldlen + newlen + 1) * sizeof(char));
+ memcpy(tmp, (*vars).values[i], oldlen);
+ strcpy(tmp + oldlen, value);
+ } else {
+ tmp = (char*) malloc ((newlen + 1) * sizeof(char));
+ strcpy(tmp, value);
+ }
+ free((*vars).values[i]);
+ (*vars).values[i] = tmp;
+ }
+ return tmp;
+}
+
+/* Allows to add a char array which has been allocated by malloc. It will automatically get
+ freed when calling tpl_clear(). Please do NOT free the memory yourself or realloc
+ it after having added the array here! */
+char *tpl_addTmp(struct templatevars *vars, char *value){
+ if((*vars).tmpalloc <= (*vars).tmpcnt){
+ (*vars).tmpalloc = (*vars).tmpcnt * 2;
+ (*vars).tmp = (char**) realloc ((*vars).tmp, (*vars).tmpalloc * sizeof(char**));
+ }
+ (*vars).tmp[(*vars).tmpcnt] = value;
+ (*vars).tmpcnt = (*vars).tmpcnt + 1;
+ return value;
+}
+
+/* Allows to do a dynamic printf without knowing and defining the needed memory size. If you specify
+ varname, the printf-result will be added/appended to the varlist. You will always get a reference
+ back which you may freely use (but you should not call free/realloc on this!)*/
+char *tpl_printf(struct templatevars *vars, int append, char *varname, char *fmtstring, ...){
+ unsigned int allocated = strlen(fmtstring) - (strlen(fmtstring)%16) + 16;
+ char *result, *tmp = (char *) malloc(allocated * sizeof(char));
+ va_list argptr;
+
+ va_start(argptr,fmtstring);
+ vsnprintf(tmp ,allocated, fmtstring, argptr);
+ va_end(argptr);
+ while (strlen(tmp) + 1 == allocated){
+ allocated += 16;
+ tmp = (char *) realloc(tmp, allocated * sizeof(char));
+ va_start(argptr,fmtstring);
+ vsnprintf(tmp, allocated, fmtstring, argptr);
+ va_end(argptr);
+ }
+ result = (char *) malloc(strlen(tmp) + 1 * sizeof(char));
+ strcpy(result, tmp);
+ free(tmp);
+ if(varname == NULL) tpl_addTmp(vars, result);
+ else {
+ char *tmp = tpl_addVar(vars, append, varname, result);
+ free(result);
+ result = tmp;
+ }
+ return result;
+}
+
+/* Returns the value for a name or an empty string if nothing was found. */
+char *tpl_getVar(struct templatevars *vars, char *name){
+ int i;
+ char *result = NULL;
+ for(i = (*vars).varscnt-1; i >= 0; --i){
+ if(strcmp((*vars).names[i], name) == 0){
+ result = (*vars).values[i];
+ break;
+ }
+ }
+ if(result == NULL) return "";
+ else return result;
+}
+
+/* Initializes all variables vor a templatevar-structure and returns a pointer to it. Make
+ sure to call tpl_clear() when you are finished or you'll run into a memory leak! */
+struct templatevars *tpl_create(){
+ struct templatevars *vars = (struct templatevars *) malloc(sizeof(struct templatevars));
+ (*vars).varsalloc = 16;
+ (*vars).varscnt = 0;
+ (*vars).tmpalloc = 16;
+ (*vars).tmpcnt = 0;
+ (*vars).names = (char**) malloc ((*vars).varsalloc * sizeof(char**));
+ (*vars).values = (char**) malloc ((*vars).varsalloc * sizeof(char**));
+ (*vars).tmp = (char**) malloc ((*vars).tmpalloc * sizeof(char**));
+ return vars;
+}
+
+/* Clears all allocated memory for the specified templatevar-structure. */
+void tpl_clear(struct templatevars *vars){
+ int i;
+ for(i = (*vars).varscnt-1; i >= 0; --i){
+ free((*vars).names[i]);
+ free((*vars).values[i]);
+ }
+ free((*vars).names);
+ free((*vars).values);
+ for(i = (*vars).tmpcnt-1; i >= 0; --i){
+ free((*vars).tmp[i]);
+ }
+ free((*vars).tmp);
+ free(vars);
+}
+
+/* Creates a path to a template file. You need to set the resultsize to the correct size of result. */
+char *tpl_getTplPath(const char *name, const char *path, char *result, unsigned int resultsize){
+ char *pch;
+ if((strlen(path) + strlen(name) + 6) <= resultsize){
+ strcpy(result, path);
+ strcat(result, name);
+ strcat(result, ".tpl");
+ result[resultsize - 1] = '\0';
+ for(pch = result + strlen(path); pch[0] != '\0'; ++pch){
+ if(pch[0] == '/' || pch[0] == '\\') pch[0] = ' ';
+ }
+ } else result[0] = '\0';
+ return result;
+}
+
+/* Returns an unparsed template either from disk or from internal templates.
+ Note: You must free() the result after using it!*/
+char *tpl_getUnparsedTpl(const char* name){
+ int i;
+ int tplcnt = sizeof(tpl)/sizeof(char *);
+ int tplmapcnt = sizeof(tplmap)/sizeof(char *);
+ char *result;
+
+ for(i = 0; i < tplcnt; ++i){
+ if(strcmp(name, tpl[i]) == 0) break;
+ }
+
+ if(strlen(cfg->http_tpl) > 0){
+ char path[200];
+ if(strlen(tpl_getTplPath(name, cfg->http_tpl, path, 200)) > 0 && file_exists(path)){
+ FILE *fp;
+ char buffer[1024];
+ int read, allocated = 1025, size = 0;
+ result = (char *) malloc(allocated * sizeof(char));
+ if((fp = fopen(path,"r"))!=NULL){
+ while((read = fread(&buffer,sizeof(char),1024,fp)) > 0){
+ if(allocated < size + read + 1) {
+ allocated += size + 1024;
+ result = (char *) realloc(result, allocated * sizeof(char));
+ }
+ memcpy(result + size, buffer, read);
+ size += read;
+ }
+ result[size] = '\0';
+ fclose (fp);
+ return result;
+ }
+ }
+ }
+ if(i >= 0 && i < tplmapcnt){
+ int len = (strlen(tplmap[i])) + 1;
+ result = (char *) malloc(len * sizeof(char));
+ memcpy(result, tplmap[i], len);
+ } else {
+ result = (char *) malloc(1 * sizeof(char));
+ result[0] = '\0';
+ }
+ return result;
+}
+
+/* Returns the specified template with all variables/other templates replaced or an
+ empty string if the template doesn't exist*/
+char *tpl_getTpl(struct templatevars *vars, const char* name){
+ char *tplorg = tpl_getUnparsedTpl(name);
+ char *tplend = tplorg + strlen(tplorg);
+ char *pch, *pch2, *tpl=tplorg;
+ char varname[33];
+
+ int tmp,respos = 0;
+ int allocated = 2 * strlen(tpl) + 1;
+ char *result = (char *) malloc(allocated * sizeof(char));
+
+ while(tpl < tplend){
+ if(tpl[0] == '#' && tpl[1] == '#' && tpl[2] != '#'){
+ pch2 = tpl;
+ pch = tpl + 2;
+ while(pch[0] != '\0' && (pch[0] != '#' || pch[1] != '#')) ++pch;
+ if(pch - pch2 < 32 && pch[0] == '#' && pch[1] == '#'){
+ memcpy(varname, pch2 + 2, pch - pch2 - 2);
+ varname[pch - pch2 - 2] = '\0';
+ if(strncmp(varname, "TPL", 3) == 0){
+ pch2 = tpl_getTpl(vars, varname + 3);
+ } else {
+ pch2 = tpl_getVar(vars, varname);
+ }
+ tmp = strlen(pch2);
+ if(tmp + respos + 2 >= allocated){
+ allocated = tmp + respos + 256;
+ result = (char *) realloc(result, allocated * sizeof(char));
+ }
+ memcpy(result + respos, pch2, tmp);
+ respos += tmp;
+ tpl = pch + 2;
+ }
+ } else {
+ if(respos + 2 >= allocated){
+ allocated = respos + 256;
+ result = (char *) realloc(result, allocated * sizeof(char));
+ }
+ result[respos] = tpl[0];
+ ++respos;
+ ++tpl;
+ }
+ }
+ free(tplorg);
+ result[respos] = '\0';
+ tpl_addTmp(vars, result);
+ return result;
+}
+
+/* Saves all templates to the specified paths. Existing files will be overwritten! */
+int tpl_saveIncludedTpls(const char *path){
+ int tplcnt = sizeof(tpl)/sizeof(char *);
+ int tplmapcnt = sizeof(tplmap)/sizeof(char *);
+ int i, cnt = 0;
+ char tmp[200];
+ FILE *fp;
+ for(i = 0; i < tplcnt && i < tplmapcnt; ++i){
+ if(strlen(tpl_getTplPath(tpl[i], path, tmp, 200)) > 0 && (fp = fopen(tmp,"w")) != NULL){
+ fwrite(tplmap[i], sizeof(char), strlen(tplmap[i]), fp);
+ fclose (fp);
+ ++cnt;
+ }
+ }
+ return cnt;
+}
+
+/* Parses a value in an authentication string by removing all quotes/whitespace. Note that the original array is modified*/
+char *parse_auth_value(char *value){
+ char *pch = value;
+ char *pch2;
+ value = strstr(value, "=");
+ if(value != NULL){
+ do{
+ ++value;
+ } while (value[0] == ' ' || value[0] == '"');
+ pch = value;
+ for(pch2 = value + strlen(value) - 1; pch2 >= value && (pch2[0] == ' ' || pch2[0] == '"' || pch2[0] == '\r' || pch2[0] == '\n'); --pch2) pch2[0] = '\0';
+ }
+ return pch;
+}
+
+/* Calculates the currently valid nonce value and copies it to result*/
+void calculate_nonce(char *result, int resultlen){
+ char *expectednonce, *noncetmp;
+ noncetmp = (char*) malloc (128*sizeof(char));
+ sprintf(noncetmp, "%d", (int)time(NULL)/AUTHNONCEVALIDSECS);
+ strcat(noncetmp, ":");
+ strcat(noncetmp, noncekey);
+ fflush(stdout);
+ expectednonce =char_to_hex(MD5((unsigned char*)noncetmp, strlen(noncetmp), NULL), MD5_DIGEST_LENGTH, hex2ascii);
+ cs_strncpy(result, expectednonce, resultlen);
+ free(noncetmp);
+ free(expectednonce);
+}
+
+/* Checks if authentication is correct. Returns -1 if not correct, 1 if correct and 2 if nonce isn't valid anymore */
+int check_auth(char *authstring, char *method, char *path, char *expectednonce){
+ int authok = 0, uriok = 0;
+ char *authnonce;
+ char *authnc;
+ char *authcnonce;
+ char *uri;
+ char *authresponse;
+ char *A1tmp, *A2tmp, *A3tmp;
+ char *A1, *A2, *A3;
+ char *pch, *pch2;
+
+ authnonce = "";
+ authnc = "";
+ authcnonce = "";
+ authresponse = "";
+ uri = "";
+ pch = authstring + 22;
+ pch = strtok (pch,",");
+ while (pch != NULL){
+ pch2 = pch;
+ while(pch2[0] == ' ' && pch2[0] != '\0') ++pch2;
+ if(strncmp(pch2, "nonce", 5) == 0){
+ authnonce=parse_auth_value(pch2);
+ } else if (strncmp(pch2, "nc", 2) == 0){
+ authnc=parse_auth_value(pch2);
+ } else if (strncmp(pch2, "cnonce", 6) == 0){
+ authcnonce=parse_auth_value(pch2);
+ } else if (strncmp(pch2, "response", 8) == 0){
+ authresponse=parse_auth_value(pch2);
+ } else if (strncmp(pch2, "uri", 3) == 0){
+ uri=parse_auth_value(pch2);
+ }
+ pch = strtok (NULL, ",");
+ }
+ if(strncmp(uri, path, strlen(path)) == 0) uriok = 1;
+ else {
+ pch2 = uri;
+ for(pch = uri; pch[0] != '\0'; ++pch) {
+ if(pch[0] == '/') pch2 = pch;
+ }
+ if(strncmp(pch2, path, strlen(path)) == 0) uriok = 1;
+ }
+ if(uriok == 1){
+ A1tmp = (char*) malloc ((3 + strlen(cfg->http_user) + strlen(AUTHREALM) + strlen(cfg->http_pwd))*sizeof(char));
+ strcpy(A1tmp, cfg->http_user);
+ strcat(A1tmp, ":");
+ strcat(A1tmp, AUTHREALM);
+ strcat(A1tmp, ":");
+ strcat(A1tmp, cfg->http_pwd);
+ A2tmp = (char*) malloc ((2 + strlen(method) + strlen(uri))*sizeof(char));
+ strcpy(A2tmp, method);
+ strcat(A2tmp, ":");
+ strcat(A2tmp, uri);
+ A1=char_to_hex(MD5((unsigned char*)A1tmp, strlen(A1tmp), NULL), MD5_DIGEST_LENGTH, hex2ascii);
+ A2=char_to_hex(MD5((unsigned char*)A2tmp, strlen(A2tmp), NULL), MD5_DIGEST_LENGTH, hex2ascii);
+ A3tmp = (char*) malloc ((10 + strlen(A1) + strlen(A2) + strlen(authnonce) + strlen(authnc) + strlen(authcnonce))*sizeof(char));
+ strcpy(A3tmp, A1);
+ strcat(A3tmp, ":");
+ strcat(A3tmp, authnonce);
+ strcat(A3tmp, ":");
+ strcat(A3tmp, authnc);
+ strcat(A3tmp, ":");
+ strcat(A3tmp, authcnonce);
+ strcat(A3tmp, ":auth:");
+ strcat(A3tmp, A2);
+ A3=char_to_hex(MD5((unsigned char*)A3tmp, strlen(A3tmp), NULL), MD5_DIGEST_LENGTH, hex2ascii);
+ if(strcmp(A3, authresponse) == 0) {
+ if(strcmp(expectednonce, authnonce) == 0) authok = 1;
+ else authok = 2;
+ }
+ free(A1tmp);
+ free(A2tmp);
+ free(A3tmp);
+ free(A1);
+ free(A2);
+ free(A3);
+ }
+ return authok;
+}
+
+void send_headers(FILE *f, int status, char *title, char *extra, char *mime){
+
+ time_t now;
+ char timebuf[128];
+
+ fprintf(f, "%s %d %s\r\n", PROTOCOL, status, title);
+ fprintf(f, "Server: %s\r\n", SERVER);
+
+ now = time(NULL);
+ strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now));
+ fprintf(f, "Date: %s\r\n", timebuf);
+
+ if (extra)
+ fprintf(f, "%s\r\n", extra);
+
+ if (mime)
+ fprintf(f, "Content-Type: %s\r\n", mime);
+
+ strftime(timebuf, sizeof(timebuf), RFC1123FMT, gmtime(&now));
+ fprintf(f, "Cache-Control: no-store, no-cache, must-revalidate\r\n");
+ fprintf(f, "Expires: Sat, 26 Jul 1997 05:00:00 GMT\r\n");
+ fprintf(f, "Last-Modified: %s\r\n", timebuf);
+ fprintf(f, "Connection: close\r\n");
+ fprintf(f, "\r\n");
+}
+
+void send_css(FILE *f){
+ if(strlen(cfg->http_css) > 0 && file_exists(cfg->http_css) == 1){
+ FILE *fp;
+ char buffer[1024];
+ int read;
+
+ if((fp = fopen(cfg->http_css,"r"))==NULL) return;
+ while((read = fread(&buffer,sizeof(char),1024,fp)) > 0) fwrite(&buffer, sizeof(char), read, f);
+ fclose (fp);
+ } else {
+ fputs(CSS, f);
+ }
+}
+
+void send_error(FILE *f, int status, char *title, char *extra, char *text){
+ send_headers(f, status, title, extra, "text/html");
+ fprintf(f, "
%d %s\r\n", status, title);
+ fprintf(f, "%d %s
\r\n", status, title);
+ fprintf(f, "%s\r\n", text);
+ fprintf(f, "\r\n");
+}
+
+char *getParam(struct uriparams *params, char *name){
+ int i;
+ for(i=(*params).paramcount-1; i>=0; --i){
+ if(strcmp((*params).params[i], name) == 0) return (*params).values[i];
+ }
+ return "";
+}
+#endif
Index: /trunk/oscam-http.c
===================================================================
--- /trunk/oscam-http.c (revision 1693)
+++ /trunk/oscam-http.c (revision 1693)
@@ -0,0 +1,1717 @@
+#ifdef WEBIF
+//
+// OSCam HTTP server module
+//
+#include "oscam-http-helpers.c"
+#include
+#include
+#include
+#include
+#include
+#include
+
+static int running = 1;
+
+void refresh_oscam(enum refreshtypes refreshtype, struct in_addr in){
+int i;
+ switch (refreshtype){
+ case REFR_ACCOUNTS:
+ cs_log("Refresh Accounts requested by WebIF from %s", inet_ntoa(*(struct in_addr *)&in));
+ kill(client[0].pid, SIGHUP);
+#ifdef CS_ANTICASC
+ for (i=0; i\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+
+ chk_t_global((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Global done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ if (cfg->srvip != 0)
+ tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->srvip));
+ if (cfg->pidfile != NULL) tpl_addVar(vars, 0, "PIDFILE", cfg->pidfile);
+ if (cfg->usrfile != NULL) tpl_addVar(vars, 0, "USERFILE", cfg->usrfile);
+ if (cfg->logfile != NULL) tpl_addVar(vars, 0, "LOGFILE", cfg->logfile);
+ if (cfg->cwlogdir != NULL) tpl_addVar(vars, 0, "CWLOGDIR", cfg->cwlogdir);
+ tpl_printf(vars, 0, "USERFILEFLAG", "%d", cfg->usrfileflag);
+ tpl_printf(vars, 0, "CLIENTTIMEOUT", "%ld", cfg->ctimeout/1000);
+ tpl_printf(vars, 0, "FALLBACKTIMEOUT", "%ld", cfg->ftimeout/1000);
+ tpl_printf(vars, 0, "CLIENTMAXIDLE", "%d", cfg->cmaxidle);
+ tpl_printf(vars, 0, "CACHEDELAY", "%ld", cfg->delay);
+ tpl_printf(vars, 0, "BINDWAIT", "%d", cfg->bindwait);
+ tpl_printf(vars, 0, "NETPRIO", "%ld", cfg->netprio);
+ tpl_printf(vars, 0, "RESOLVEDELAY", "%d", cfg->resolvedelay);
+ tpl_printf(vars, 0, "SLEEP", "%d", cfg->tosleep);
+ tpl_printf(vars, 0, "UNLOCKPARENTAL", "%d", cfg->ulparent);
+ tpl_printf(vars, 0, "NICE", "%d", cfg->nice);
+ tpl_printf(vars, 0, "SERIALTIMEOUT", "%d", cfg->srtimeout);
+ tpl_printf(vars, 0, "MAXLOGSIZE", "%d", cfg->max_log_size);
+ tpl_printf(vars, 0, "WAITFORCARDS", "%d", cfg->waitforcards);
+ tpl_printf(vars, 0, "PREFERLOCALCARDS", "%d", cfg->preferlocalcards);
+
+ fputs(tpl_getTpl(vars, "CONFIGGLOBAL"), f);
+}
+
+void send_oscam_config_camd33(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+
+ if (strcmp(getParam(params, "action"), "execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ if (strcmp((*params).params[i], "nocrypt") == 0){
+ clear_sip(&cfg->c33_plain);
+ }
+ //we use the same function as used for parsing the config tokens
+ chk_t_camd33((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration camd33 done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ tpl_printf(vars, 0, "PORT", "%d", cfg->c33_port);
+ if (cfg->c33_srvip != 0)
+ tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip));
+ tpl_printf(vars, 0, "PASSIVE", "%d", cfg->c33_passive);
+
+ for (i = 0; i < (int) sizeof(cfg->c33_key); ++i) tpl_printf(vars, 1, "KEY", "%02X",cfg->c33_key[i]);
+ struct s_ip *cip;
+ char *dot="";
+ for (cip = cfg->c33_plain; cip; cip = cip->next){
+ tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
+ if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
+ dot=",";
+ }
+
+ fputs(tpl_getTpl(vars, "CONFIGCAMD33"), f);
+}
+
+void send_oscam_config_camd35(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ chk_t_camd35((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration camd35 done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ tpl_printf(vars, 0, "PORT", "%d", cfg->c35_port);
+ if (cfg->c35_tcp_srvip != 0)
+ tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
+
+ if (cfg->c35_suppresscmd08)
+ tpl_addVar(vars, 0, "SUPPRESSCMD08", "checked");
+
+ fputs(tpl_getTpl(vars, "CONFIGCAMD35"), f);
+}
+
+void send_oscam_config_camd35tcp(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ clear_ptab(&cfg->c35_tcp_ptab); /*clear Porttab*/
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ chk_t_camd35_tcp((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration camd35 TCP done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+
+ int j;
+ char *dot1, *dot2;
+ if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)){
+ dot1 = "";
+ for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){
+ tpl_printf(vars, 1, "PORT", "%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid);
+ if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){
+ tpl_printf(vars, 1, "PORT", ":");
+ dot2 = "";
+ for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){
+ tpl_printf(vars, 1, "PORT", "%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]);
+ dot2 = ",";
+ }
+ }
+ dot1=";";
+ }
+ }
+ if (cfg->c35_tcp_srvip != 0)
+ tpl_addVar(vars, 1, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip));
+
+ fputs(tpl_getTpl(vars, "CONFIGCAMD35TCP"), f);
+}
+
+void send_oscam_config_newcamd(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ clear_ptab(&cfg->ncd_ptab); /*clear Porttab*/
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ if (strcmp((*params).params[i], "allowed") == 0){
+ clear_sip(&cfg->ncd_allowed);
+ }
+ chk_t_newcamd((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Newcamd done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ int j;
+ char *dot1, *dot2;
+ if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){
+ dot1 = "";
+ for(i = 0; i < cfg->ncd_ptab.nports; ++i){
+ tpl_printf(vars, 1, "PORT", "%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid);
+ if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){
+ tpl_printf(vars, 1, "PORT", ":");
+ dot2 = "";
+ for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){
+ tpl_printf(vars, 1, "PORT", "%s%06X", dot2, cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]);
+ dot2 = ",";
+ }
+ }
+ dot1=";";
+ }
+ }
+
+ if (cfg->ncd_srvip != 0)
+ tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip));
+ for (i=0;i<14;i++) tpl_printf(vars, 1, "KEY", "%02X", cfg->ncd_key[i]);
+
+ struct s_ip *cip;
+ char *dot="";
+ for (cip = cfg->ncd_allowed; cip; cip = cip->next){
+ tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
+ if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
+ dot=",";
+ }
+
+ if (cfg->ncd_keepalive)
+ tpl_addVar(vars, 0, "KEEPALIVE", "checked");
+
+ fputs(tpl_getTpl(vars, "CONFIGNEWCAMD"), f);
+}
+
+void send_oscam_config_radegast(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ if (strcmp((*params).params[i], "allowed") == 0){
+ clear_sip(&cfg->rad_allowed);
+ }
+ //we use the same function as used for parsing the config tokens
+ chk_t_radegast((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Radegast done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ tpl_printf(vars, 0, "PORT", "%d", cfg->rad_port);
+ if (cfg->rad_srvip != 0)
+ tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip));
+ tpl_addVar(vars, 0, "USER", cfg->rad_usr);
+
+ struct s_ip *cip;
+ char *dot="";
+ for (cip=cfg->rad_allowed; cip; cip=cip->next){
+ tpl_printf(vars, 1, "ALLOWED", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
+ if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "ALLOWED", "-%s", cs_inet_ntoa(cip->ip[1]));
+ dot=",";
+ }
+
+ fputs(tpl_getTpl(vars, "CONFIGRADEGAST"), f);
+}
+
+void send_oscam_config_cccam(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ chk_t_cccam((*params).params[i], (*params).values[i]);
+ }
+ }
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+
+ tpl_printf(vars, 1, "PORT", "%d", cfg->cc_port);
+ tpl_printf(vars, 0, "RESHARE", "%d", cfg->cc_reshare);
+ tpl_printf(vars, 0, "VERSION", "%s", cfg->cc_version);
+ tpl_printf(vars, 0, "BUILD", "%s", cfg->cc_build);
+
+ fputs(tpl_getTpl(vars, "CONFIGCCCAM"), f);
+}
+
+#ifdef CS_WITH_GBOX
+void send_oscam_config_gbox(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ chk_t_gbox((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Gbox done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ tpl_printf(vars, 0, "MAXDIST", "%d", cfg->maxdist);
+ for (i=0;i<4;i++) tpl_printf(vars, 1, "PASSWORD", "%02X", cfg->gbox_pwd[i]);
+ tpl_addVar(vars, 0, "IGNORELIST", (char *)cfg->ignorefile);
+ tpl_addVar(vars, 0, "ONLINEINFOS", (char *)cfg->gbxShareOnl);
+ tpl_addVar(vars, 0, "CARDINFOS", (char *)cfg->cardfile);
+ char *dot = "";
+ for (i = 0; i < cfg->num_locals; i++){
+ tpl_printf(vars, 1, "LOCALS", "%s%06lX", dot, cfg->locals[i]);
+ dot=";";
+ }
+ fputs(tpl_getTpl(vars, "CONFIGGBOX"), f);
+}
+#endif
+
+void send_oscam_config_monitor(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ if (strcmp((*params).params[i], "nocrypt") == 0){
+ clear_sip(&cfg->mon_allowed);
+ }
+ //we use the same function as used for parsing the config tokens
+ chk_t_monitor((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Monitor done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ tpl_printf(vars, 0, "MONPORT", "%d", cfg->mon_port);
+ if (cfg->mon_srvip != 0)
+ tpl_addVar(vars, 0, "SERVERIP", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip));
+ tpl_printf(vars, 0, "AULOW", "%d", cfg->mon_aulow);
+ tpl_printf(vars, 0, "HIDECLIENTTO", "%d", cfg->mon_hideclient_to);
+ tpl_printf(vars, 0, "HTTPPORT", "%d", cfg->http_port);
+ tpl_addVar(vars, 0, "HTTPUSER", cfg->http_user);
+ tpl_addVar(vars, 0, "HTTPPASSWORD", cfg->http_pwd);
+ tpl_addVar(vars, 0, "HTTPCSS", cfg->http_css);
+ tpl_printf(vars, 0, "HTTPREFRESH", "%d", cfg->http_refresh);
+ tpl_addVar(vars, 0, "HTTPTPL", cfg->http_tpl);
+ tpl_addVar(vars, 0, "HTTPSCRIPT", cfg->http_script);
+ if (cfg->http_hide_idle_clients > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
+
+ struct s_ip *cip;
+ char *dot="";
+ for (cip = cfg->mon_allowed; cip; cip = cip->next){
+ tpl_printf(vars, 1, "NOCRYPT", "%s%s", dot, cs_inet_ntoa(cip->ip[0]));
+ if (cip->ip[0] != cip->ip[1]) tpl_printf(vars, 1, "NOCRYPT", "-%s", cs_inet_ntoa(cip->ip[1]));
+ dot=",";
+ }
+
+ //Monlevel selector
+ tpl_printf(vars, 0, "TMP", "MONSELECTED%d", cfg->mon_level);
+ tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
+
+ fputs(tpl_getTpl(vars, "CONFIGMONITOR"), f);
+}
+
+void send_oscam_config_serial(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ //chk_t_serial((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Serial Not yet implemented
");
+ refresh_oscam(REFR_SERVER, in);
+ }
+
+ tpl_addVar(vars, 0, "SERIALDEVICE", cfg->ser_device);
+
+ fputs(tpl_getTpl(vars, "CONFIGSERIAL"), f);
+}
+
+#ifdef HAVE_DVBAPI
+void send_oscam_config_dvbapi(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ chk_t_dvbapi((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration DVB Api done. You should restart Oscam now.
");
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+
+ if (cfg->dvbapi_enabled > 0) tpl_addVar(vars, 0, "ENABLEDCHECKED", "checked");
+ if (cfg->dvbapi_au > 0) tpl_addVar(vars, 0, "AUCHECKED", "checked");
+ tpl_addVar(vars, 0, "BOXTYPE", cfg->dvbapi_boxtype);
+ tpl_addVar(vars, 0, "USER", cfg->dvbapi_usr);
+
+ fputs(tpl_getTpl(vars, "CONFIGDVBAPI"), f);
+}
+#endif
+
+#ifdef CS_ANTICASC
+void send_oscam_config_anticasc(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int i;
+ if (strcmp(getParam(params, "action"),"execute") == 0){
+ for(i = 0; i < (*params).paramcount; ++i){
+ if ((strcmp((*params).params[i], "part")) && (strcmp((*params).params[i], "action"))){
+ tpl_printf(vars, 1, "MESSAGE", "Parameter: %s set to Value: %s
\n", (*params).params[i], (*params).values[i]);
+ //we use the same function as used for parsing the config tokens
+ chk_t_ac((*params).params[i], (*params).values[i]);
+ }
+ }
+ tpl_addVar(vars, 1, "MESSAGE", "
Configuration Anticascading done. You should restart Oscam now.
");
+ refresh_oscam(REFR_ANTICASC, in);
+ if(write_config()==0) refresh_oscam(REFR_SERVER, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ if (cfg->ac_enabled > 0) tpl_addVar(vars, 0, "CHECKED", "checked");
+ tpl_printf(vars, 0, "NUMUSERS", "%d", cfg->ac_users);
+ tpl_printf(vars, 0, "SAMPLETIME", "%d", cfg->ac_stime);
+ tpl_printf(vars, 0, "SAMPLES", "%d", cfg->ac_samples);
+ tpl_printf(vars, 0, "PENALTY", "%d", cfg->ac_penalty);
+ tpl_addVar(vars, 0, "ACLOGFILE", cfg->ac_logfile);
+ tpl_printf(vars, 0, "FAKEDELAY", "%d", cfg->ac_fakedelay);
+ tpl_printf(vars, 0, "DENYSAMPLES", "%d", cfg->ac_denysamples);
+ fputs(tpl_getTpl(vars, "CONFIGANTICASC"), f);
+}
+#endif
+
+void send_oscam_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ char *part = getParam(params, "part");
+ if (!strcmp(part,"camd33")) send_oscam_config_camd33(vars, f, params, in);
+ else if (!strcmp(part,"camd35")) send_oscam_config_camd35(vars, f, params, in);
+ else if (!strcmp(part,"camd35tcp")) send_oscam_config_camd35tcp(vars, f, params, in);
+ else if (!strcmp(part,"newcamd")) send_oscam_config_newcamd(vars, f, params, in);
+ else if (!strcmp(part,"radegast")) send_oscam_config_radegast(vars, f, params, in);
+ else if (!strcmp(part,"cccam")) send_oscam_config_cccam(vars, f, params, in);
+#ifdef CS_WITH_GBOX
+ else if (!strcmp(part,"gbox")) send_oscam_config_gbox(vars, f, params, in);
+#endif
+#ifdef HAVE_DVBAPI
+ else if (!strcmp(part,"dvbapi")) send_oscam_config_dvbapi(vars, f, params, in);
+#endif
+#ifdef CS_ANTICASC
+ else if (!strcmp(part,"anticasc")) send_oscam_config_anticasc(vars, f, params, in);
+#endif
+ else if (!strcmp(part,"monitor")) send_oscam_config_monitor(vars, f, params, in);
+ else if (!strcmp(part,"serial")) send_oscam_config_serial(vars, f, params, in);
+ else send_oscam_config_global(vars, f, params, in);
+}
+
+void send_oscam_reader(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int readeridx, isphysical = 0;
+ char *ctyp;
+ //uchar dummy[1]={0x00};
+
+ if (strcmp(getParam(params, "action"), "reread") == 0){
+ readeridx = atoi(getParam(params, "ridx"));
+ //reset the counters
+ reader[readeridx].emmerror = 0;
+ reader[readeridx].emmwritten = 0;
+ reader[readeridx].emmskipped = 0;
+ reader[readeridx].emmblocked = 0;
+ //write_to_pipe(client[reader[readeridx].cs_idx)].fd_m2c, PIP_ID_CIN, dummy, 1); // do not work for whatever reason
+ refresh_oscam(REFR_READERS, in); // refresh all reader because write pipe seams not work from here
+ }
+
+ for(readeridx = 0; readeridx < CS_MAXREADER; readeridx++){
+ isphysical = 0;
+
+ if(!reader[readeridx].device[0]) break;
+
+ tpl_addVar(vars, 0, "READERNAME", reader[readeridx].label);
+ tpl_addVar(vars, 0, "READERNAMEENC", tpl_addTmp(vars, urlencode(reader[readeridx].label)));
+
+ switch(reader[readeridx].typ){
+ case R_MOUSE :
+ ctyp = "mouse";
+ isphysical = 1;
+ break;
+ case R_INTERNAL:
+ ctyp = "intern";
+ isphysical = 1;
+ break;
+ case R_SMART :
+ ctyp = "smartreader";
+ isphysical = 1;
+ break;
+ case R_SERIAL :
+ ctyp = "serial";
+ isphysical = 1;
+ break;
+ case R_DB2COM1 :
+ ctyp = "dbox COM1";
+ isphysical = 1;
+ break;
+ case R_DB2COM2 :
+ ctyp = "dbox COM2";
+ isphysical = 1;
+ break;
+ case R_CAMD35 : ctyp="camd 3.5x";break;
+ case R_CAMD33 : ctyp="camd 3.3x";break;
+ case R_NEWCAMD : ctyp="newcamd"; break;
+ case R_RADEGAST: ctyp="radegast"; break;
+#ifdef CS_WITH_GBOX
+ case R_GBOX : ctyp="gbox"; break;
+#endif
+#ifdef HAVE_PCSC
+ case R_PCSC :
+ ctyp="pcsc";
+ isphysical = 1;
+ break;
+#endif
+ case R_CCCAM : ctyp="cccam"; break;
+ case R_CS378X : ctyp="cs378x"; break;
+ default : ctyp="unknown"; break;
+ }
+
+ if (isphysical == 1) {
+ tpl_printf(vars, 0, "RIDX", "%d", readeridx);
+ tpl_printf(vars, 0, "EMMERROR", "%d", reader[readeridx].emmerror);
+ tpl_printf(vars, 0, "EMMWRITTEN", "%d", reader[readeridx].emmwritten);
+ tpl_printf(vars, 0, "EMMSKIPPED", "%d", reader[readeridx].emmskipped);
+ tpl_printf(vars, 0, "EMMBLOCKED", "%d", reader[readeridx].emmblocked);
+ tpl_addVar(vars, 0, "REFRICO", ICREF);
+ tpl_addVar(vars, 0, "READERREFRESH", tpl_getTpl(vars, "READERREFRESHBIT"));
+#ifdef CS_RDR_INIT_HIST
+ tpl_addVar(vars, 0, "ENTICO", ICENT);
+ tpl_addVar(vars, 0, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT"));
+#endif
+ } else {
+ tpl_printf(vars, 0, "RIDX", "");
+ tpl_addVar(vars, 0, "EMMERROR", "");
+ tpl_addVar(vars, 0, "EMMWRITTEN", "");
+ tpl_addVar(vars, 0, "EMMSKIPPED", "");
+ tpl_addVar(vars, 0, "EMMBLOCKED", "");
+ tpl_addVar(vars, 0, "READERREFRESH","");
+#ifdef CS_RDR_INIT_HIST
+ tpl_addVar(vars, 0, "ENTITLEMENT","");
+#endif
+ }
+
+ tpl_addVar(vars, 0, "CTYP", ctyp);
+ tpl_addVar(vars, 0, "EDIICO", ICEDI);
+ tpl_addVar(vars, 1, "READERLIST", tpl_getTpl(vars, "READERSBIT"));
+
+ }
+ fputs(tpl_getTpl(vars, "READERS"), f);
+}
+
+void send_oscam_reader_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ int ridx;
+ char *reader_ = getParam(params, "reader");
+ for(ridx = 0; ridx < CS_MAXREADER && strcmp(reader_, reader[ridx].label) != 0; ++ridx);
+ if(ridx == CS_MAXREADER){
+ tpl_addVar(vars, 0, "MESSAGE", "
Reader not found
");
+ } else if(strcmp(getParam(params, "action"), "execute") == 0){
+ tpl_addVar(vars, 0, "MESSAGE", "
Saving not yet implemented
");
+ refresh_oscam(REFR_READERS, in);
+ }
+ int i;
+
+ tpl_addVar(vars, 0, "READERNAME", reader[ridx].label);
+ tpl_printf(vars, 0, "DEVICE", "%s", reader[ridx].device);
+ tpl_addVar(vars, 0, "NCD_KEY", (char *)reader[ridx].ncd_key);
+ tpl_addVar(vars, 0, "PINCODE", reader[ridx].pincode);
+ //tpl_addVar(vars, 0, "EMMFILE", (char *)reader[ridx].emmfile);
+ tpl_printf(vars, 0, "INACTIVITYTIMEOUT", "%d", reader[ridx].tcp_ito);
+ tpl_printf(vars, 0, "RECEIVETIMEOUT", "%d", reader[ridx].tcp_rto);
+ tpl_printf(vars, 0, "DISABLESERVERFILTER", "%d", reader[ridx].ncd_disable_server_filt);
+ tpl_printf(vars, 0, "FALLBACK", "%d", reader[ridx].fallback);
+ tpl_printf(vars, 0, "LOGPORT", "%d", reader[ridx].log_port);
+ tpl_printf(vars, 0, "BOXID", "%ld", reader[ridx].boxid);
+ tpl_addVar(vars, 0, "USER", reader[ridx].r_usr);
+ tpl_addVar(vars, 0, "PASS", reader[ridx].r_pwd);
+ tpl_addVar(vars, 0, "RSAKEY", (char *)reader[ridx].rsa_mod);
+ tpl_addVar(vars, 0, "BOXKEY", (char *)reader[ridx].nagra_boxkey);
+
+ if (reader[ridx].detect&0x80)
+ tpl_printf(vars, 0, "DETECT", "!%s", RDR_CD_TXT[reader[ridx].detect&0x7f]);
+ else
+ tpl_printf(vars, 0, "DETECT", "%s", RDR_CD_TXT[reader[ridx].detect&0x7f]);
+
+ tpl_printf(vars, 0, "MHZ", "%d", reader[ridx].mhz);
+ tpl_printf(vars, 0, "CARDMHZ", "%d", reader[ridx].cardmhz);
+
+
+#ifdef CS_WITH_GBOX
+ tpl_addVar(vars, 0, "GBOXPWD", (char *)reader[ridx].gbox_pwd);
+ tpl_addVar(vars, 0, "PREMIUM", reader[ridx].gbox_prem);
+#endif
+
+ if(reader[ridx].r_port) tpl_printf(vars, 0, "R_PORT", ",%d", reader[ridx].r_port);
+ if(reader[ridx].l_port) {
+ if(reader[ridx].r_port) tpl_printf(vars, 0, "L_PORT", ",%d", reader[ridx].l_port);
+ else tpl_printf(vars, 0, "L_PORT", ",,%d", reader[ridx].l_port);
+ }
+
+ //group
+ char *value = mk_t_group((ulong*)reader[ridx].grp);
+ tpl_printf(vars, 0, "GRP", "%s", value);
+ free(value);
+
+ //services
+ char sidok[33];
+ long2bitchar(reader[ridx].sidtabok, sidok);
+ char sidno[33];
+ long2bitchar(reader[ridx].sidtabno,sidno);
+ struct s_sidtab *sidtab = cfg->sidtab;
+ //build matrix
+ i = 0;
+ while(sidtab != NULL){
+ tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
+ if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
+ else tpl_addVar(vars, 0, "CHECKED", "");
+ tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDOKBIT"));
+ if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
+ else tpl_addVar(vars, 0, "CHECKED", "");
+ tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "READERCONFIGSIDNOBIT"));
+ sidtab=sidtab->next;
+ i++;
+ }
+
+ // CAID
+ value = mk_t_caidtab(&reader[ridx].ctab);
+ tpl_addVar(vars, 0, "CAIDS", value);
+ free(value);
+
+ //ident
+ value = mk_t_ftab(&reader[ridx].ftab);
+ tpl_printf(vars, 0, "IDENTS", "%s\n", value);
+ free(value);
+
+ //class
+ CLASSTAB *clstab = &reader[ridx].cltab;
+ char *dot="";
+ for(i = 0; i < clstab->an; ++i){
+ tpl_printf(vars, 1, "CLASS", "%s%02x", dot, (int)clstab->aclass[i]);
+ dot=",";
+ }
+ for(i = 0; i < clstab->bn; ++i){
+ tpl_printf(vars, 0, "CLASS", "%s!%02x", dot, (int)clstab->bclass[i]);
+ dot=",";
+ }
+
+ //chid
+ int j;
+ dot="";
+ FTAB *ftab = &reader[ridx].fchid;
+ for (i = 0; i < ftab->nfilts; ++i){
+ tpl_printf(vars, 1, "CHIDS", "%s%04X", dot, ftab->filts[i].caid);
+ dot=":";
+ for (j = 0; j < ftab->filts[i].nprids; ++j) {
+ tpl_printf(vars, 1, "CHIDS", "%s%06lX", dot, ftab->filts[i].prids[j]);
+ dot=",";
+ }
+ dot=";";
+ }
+
+ tpl_printf(vars, 0, "SHOWCLS", "%d", reader[ridx].show_cls);
+ tpl_printf(vars, 0, "MAXQLEN", "%d", reader[ridx].maxqlen);
+ tpl_printf(vars, 0, "EMMCACHE", "%d,%d,&d", reader[ridx].cachemm, reader[ridx].rewritemm, reader[ridx].logemm);
+
+ //savenano
+ int all = 1;
+ dot="";
+ for(i = 0; i < 256; ++i){
+ if(!(reader[ridx].b_nano[i] & 0x02)){
+ all = 0;
+ break;
+ }
+ }
+ if (all == 1) tpl_printf(vars, 0, "SAVENANO", "all", reader[ridx].maxqlen);
+ else {
+ for(i = 0; i < 256; ++i){
+ if(reader[ridx].b_nano[i] & 0x02) tpl_printf(vars, 1, "SAVENANO", "%s%02x\n", dot, i);
+ dot=",";
+ }
+ }
+
+ //blocknano
+ dot="";
+ for(i = 0; i < 256; ++i){
+ if(!(reader[ridx].b_nano[i] & 0x01)){
+ all = 0;
+ break;
+ }
+ }
+ if (all == 1) tpl_printf(vars, 0, "BLOCKNANO", "all", reader[ridx].maxqlen);
+ else {
+ for(i = 0; i < 256; ++i){
+ if(reader[ridx].b_nano[i] & 0x01) tpl_printf(vars, 1, "BLOCKNANO", "%s%02x\n", dot, i);
+ dot=",";
+ }
+ }
+
+ tpl_addVar(vars, 0, "CCCVERSION", reader[ridx].cc_version);
+ tpl_addVar(vars, 0, "CCCBUILD", reader[ridx].cc_build);
+ tpl_printf(vars, 0, "CCCMAXHOP", "%d", reader[ridx].cc_maxhop);
+
+
+ // Show only parameters which needed for the reader
+ switch (reader[ridx].typ) {
+
+ case R_MOUSE :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGMOUSEBIT"));
+ break;
+ case R_SMART :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSMARTBIT"));
+ break;
+ case R_INTERNAL:
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGINTERNALBIT"));
+ break;
+ case R_SERIAL :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGSERIALBIT"));
+ break;
+ case R_CAMD35 :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCAMD35BIT"));
+ break;
+ case R_CS378X :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGCS378XBIT"));
+ break;
+ case R_RADEGAST:
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGRADEGASTBIT"));
+ break;
+ case R_NEWCAMD :
+ if ( reader[ridx].ncd_proto == NCD_525 )
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD525BIT"));
+ else if ( reader[ridx].ncd_proto == NCD_524 )
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGNCD524BIT"));
+ break;
+#ifdef CS_WITH_GBOX
+ case R_GBOX :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGGBOXBIT"));
+ break;
+#endif
+#ifdef HAVE_PCSC
+ case R_PCSC :
+ tpl_addVar(vars, 1, "READERDEPENDINGCONFIG", tpl_getTpl(vars, "READERCONFIGPCSCBIT"));
+ break;
+#endif
+
+
+ }
+ //READERCONFIGMOUSEBIT
+ fputs(tpl_getTpl(vars, "READERCONFIG"), f);
+}
+
+void send_oscam_user_config_edit(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in){
+ struct s_auth *account, *ptr;
+ char user[128];
+
+ if (strcmp(getParam(params, "action"), "Save As") == 0) cs_strncpy(user, getParam(params, "newuser"), sizeof(user)/sizeof(char));
+ else cs_strncpy(user, getParam(params, "user"), sizeof(user)/sizeof(char));
+
+ int i;
+
+ for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
+
+ // Create a new user if it doesn't yet
+ if (account == NULL){
+ i = 1;
+ while(strlen(user) < 1){
+ snprintf(user, sizeof(user)/sizeof(char) - 1, "NEWUSER%d", i);
+ for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
+ if(account != NULL) user[0] = '\0';
+ ++i;
+ }
+ if (!(account=malloc(sizeof(struct s_auth)))){
+ cs_log("Error allocating memory (errno=%d)", errno);
+ return;
+ }
+ if(cfg->account == NULL) cfg->account = account;
+ else {
+ for (ptr = cfg->account; ptr != NULL && ptr->next != NULL; ptr = ptr->next);
+ ptr->next = account;
+ }
+ memset(account, 0, sizeof(struct s_auth));
+ cs_strncpy((char *)account->usr, user, sizeof(account->usr));
+ account->au=(-1);
+ account->monlvl=cfg->mon_level;
+ account->tosleep=cfg->tosleep;
+ for (i=1; ictab.mask[i++]=0xffff);
+ for (i=1; ittab.bt_srvid[i++]=0x0000);
+ account->expirationdate=(time_t)NULL;
+#ifdef CS_ANTICASC
+ account->ac_users=cfg->ac_users;
+ account->ac_penalty=cfg->ac_penalty;
+ account->ac_idx = account->ac_idx + 1;
+#endif
+ tpl_addVar(vars, 1, "MESSAGE", "New user has been added with default settings
");
+ if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Writing configuration to disk failed!
");
+ // need to reget account as writing to disk changes account!
+ for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
+ }
+
+ if((strcmp(getParam(params, "action"), "Save") == 0) || (strcmp(getParam(params, "action"), "Save As") == 0)){
+ char servicelabels[255]="";
+ //clear group
+ account->grp = 0;
+
+ for(i=0;i<(*params).paramcount;i++){
+ if ((strcmp((*params).params[i], "action")) && (strcmp((*params).params[i], "user")) && (strcmp((*params).params[i], "newuser"))){
+ if (!strcmp((*params).params[i], "expdate"))
+ account->expirationdate=(time_t)NULL;
+ if (!strcmp((*params).params[i], "services"))
+ sprintf(servicelabels + strlen(servicelabels), "%s,", (*params).values[i]);
+ else
+ chk_account((*params).params[i], (*params).values[i], account);
+ }
+ }
+ chk_account("services", servicelabels, account);
+ tpl_addVar(vars, 1, "MESSAGE", "Settings updated
");
+ if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Write Config failed
");
+ }
+ for (account = cfg->account; account != NULL && strcmp(user, account->usr) != 0; account = account->next);
+
+ tpl_addVar(vars, 0, "USERNAME", account->usr);
+ tpl_addVar(vars, 0, "PASSWORD", account->pwd);
+
+ //Disabled
+ if(account->disabled)
+ tpl_addVar(vars, 0, "DISABLEDCHECKED", "checked");
+
+ //Expirationdate
+ struct tm * timeinfo = localtime (&account->expirationdate);
+ char buf [80];
+ strftime (buf,80,"%Y-%m-%d",timeinfo);
+ if(strcmp(buf,"1970-01-01")) tpl_addVar(vars, 0, "EXPDATE", buf);
+
+ //Group
+ char *value = mk_t_group((ulong*)account->grp);
+ tpl_addVar(vars, 0, "GROUPS", value);
+ free(value);
+
+ //Hostname
+ tpl_addVar(vars, 0, "DYNDNS", (char *)account->dyndns);
+
+ //Uniq
+ tpl_printf(vars, 0, "TMP", "UNIQSELECTED%d", account->uniq);
+ tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
+
+ //Sleep
+ if(!account->tosleep) tpl_addVar(vars, 0, "SLEEP", "0");
+ else tpl_printf(vars, 0, "SLEEP", "%d", account->tosleep);
+ //Monlevel selector
+ tpl_printf(vars, 0, "TMP", "MONSELECTED%d", account->monlvl);
+ tpl_addVar(vars, 0, tpl_getVar(vars, "TMP"), "selected");
+
+ //AU Selector
+ if (!account->au) tpl_addVar(vars, 0, "AUSELECTED", "selected");
+ if (account->autoau == 1) tpl_addVar(vars, 0, "AUTOAUSELECTED", "selected");
+ int ridx;
+ for (ridx=0; ridxau == ridx) tpl_addVar(vars, 0, "SELECTED", "selected");
+ else tpl_addVar(vars, 0, "SELECTED", "");
+ tpl_addVar(vars, 1, "RDROPTION", tpl_getTpl(vars, "USEREDITRDRSELECTED"));
+ }
+
+ /* SERVICES */
+ //services - first we have to move the long sidtabok/sidtabno to a binary array
+ char sidok[33];
+ long2bitchar(account->sidtabok,sidok);
+ char sidno[33];
+ long2bitchar(account->sidtabno,sidno);
+ struct s_sidtab *sidtab = cfg->sidtab;
+ //build matrix
+ i=0;
+ while(sidtab != NULL){
+ tpl_addVar(vars, 0, "SIDLABEL", sidtab->label);
+ if(sidok[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
+ else tpl_addVar(vars, 0, "CHECKED", "");
+ tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDOKBIT"));
+ if(sidno[i]=='1') tpl_addVar(vars, 0, "CHECKED", "checked");
+ else tpl_addVar(vars, 0, "CHECKED", "");
+ tpl_addVar(vars, 1, "SIDS", tpl_getTpl(vars, "USEREDITSIDNOBIT"));
+ sidtab=sidtab->next;
+ i++;
+ }
+
+ // CAID
+ value = mk_t_caidtab(&account->ctab);
+ tpl_addVar(vars, 0, "CAIDS", value);
+ free(value);
+
+ //ident
+ value = mk_t_ftab(&account->ftab);
+ tpl_printf(vars, 0, "IDENTS", "%s\n", value);
+ free(value);
+
+ //Betatunnel
+ value = mk_t_tuntab(&account->ttab);
+ tpl_addVar(vars, 0, "BETATUNNELS", value);
+ free(value);
+
+ //SUPPRESSCMD08
+ if (account->c35_suppresscmd08)
+ tpl_addVar(vars, 0, "SUPPRESSCMD08", "checked");
+
+ //Keepalive
+ if (account->ncd_keepalive)
+ tpl_addVar(vars, 0, "KEEPALIVE", "checked");
+
+#ifdef CS_ANTICASC
+ tpl_printf(vars, 0, "AC_USERS", "%d", account->ac_users);
+ tpl_printf(vars, 0, "AC_PENALTY", "%d", account->ac_penalty);
+#endif
+ fputs(tpl_getTpl(vars, "USEREDIT"), f);
+}
+
+void send_oscam_user_config(struct templatevars *vars, FILE *f, struct uriparams *params, struct in_addr in) {
+ struct s_auth *account, *account2;
+ char *user = getParam(params, "user");
+ int i, found = 0;
+ int hideclient = 10;
+
+ if (cfg->mon_hideclient_to > 10)
+ hideclient = cfg->mon_hideclient_to;
+
+ if (strcmp(getParam(params, "action"), "delete") == 0){
+ account=cfg->account;
+ if(strcmp(account->usr, user) == 0){
+ cfg->account = account->next;
+ free(account);
+ found = 1;
+ } else if (account->next != NULL){
+ do{
+ if(strcmp(account->next->usr, user) == 0){
+ account2 = account->next;
+ account->next = account2->next;
+ free(account2);
+ found = 1;
+ break;
+ }
+ } while ((account = account->next) && (account->next != NULL));
+ }
+
+ if (found > 0){
+ tpl_addVar(vars, 1, "MESSAGE", "Account has been deleted!
");
+ if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Writing configuration to disk failed!
");
+ } else tpl_addVar(vars, 1, "MESSAGE", "Sorry but the specified user doesn't exist. No deletion will be made!
");
+ }
+
+ if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)){
+ for (account=cfg->account; (account) ; account=account->next){
+ if(strcmp(getParam(params, "user"), account->usr) == 0){
+ if(strcmp(getParam(params, "action"), "disable") == 0)
+ account->disabled = 1;
+ else
+ account->disabled = 0;
+ found = 1;
+ }
+ }
+
+ if (found > 0){
+ tpl_addVar(vars, 1, "MESSAGE", "Account has been switched!
");
+ if (write_userdb()==0) refresh_oscam(REFR_ACCOUNTS, in);
+ else tpl_addVar(vars, 1, "MESSAGE", "Writing configuration to disk failed!
");
+ } else tpl_addVar(vars, 1, "MESSAGE", "Sorry but the specified user doesn't exist. No deletion will be made!
");
+ }
+
+ /* List accounts*/
+ char *status = "offline";
+ char *expired = "";
+ char *classname="offline";
+ char *lastchan=" ";
+ time_t now = time((time_t)0);
+ int isec = 0, isonline = 0;
+
+ for (account=cfg->account; (account) ; account=account->next){
+ //clear for next client
+ expired = ""; classname = "offline"; status = "offline";
+ isonline = 0;
+ tpl_addVar(vars, 0, "CWOK", "");
+ tpl_addVar(vars, 0, "CWNOK", "");
+ tpl_addVar(vars, 0, "CWIGN", "");
+ tpl_addVar(vars, 0, "CWTOUT", "");
+ tpl_addVar(vars, 0, "CWCACHE", "");
+ tpl_addVar(vars, 0, "CWTUN", "");
+ tpl_addVar(vars, 0, "CLIENTPROTO","");
+ tpl_addVar(vars, 0, "IDLESECS","");
+ tpl_addVar(vars, 0, "CWLASTRESPONSET","");
+ tpl_addVar(vars, 0, "EMMOK","");
+ tpl_addVar(vars, 0, "EMMNOK","");
+ tpl_addVar(vars, 0, "CLIENTPROTO","");
+ tpl_addVar(vars, 0, "LASTCHANNEL", "");
+
+ if(account->expirationdate && account->expirationdate