Commit eb68baaa authored by El Mghazli Yacine's avatar El Mghazli Yacine

Merge branch 'websrv' of gitlab.eurecom.fr:oai/openairinterface5g into websrv

parents b4e02802 16fc6028
...@@ -110,7 +110,7 @@ telnetshell_vardef_t telnet_vardef[] = { ...@@ -110,7 +110,7 @@ telnetshell_vardef_t telnet_vardef[] = {
telnetshell_cmddef_t telnet_cmdarray[] = { telnetshell_cmddef_t telnet_cmdarray[] = {
{"redirlog","[here,file,off]",setoutput,{wsetoutput},0,NULL}, {"redirlog","[here,file,off]",setoutput,{wsetoutput},0,NULL},
{"param","[prio]",setparam,{wsetparam},0,NULL}, {"param","[prio]",setparam,{wsetparam},0,NULL},
{"history","[list,reset]",history_cmd,{NULL},0,NULL}, {"history","[list,reset]",history_cmd,{NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"","",NULL,{NULL},0,NULL}, {"","",NULL,{NULL},0,NULL},
}; };
......
...@@ -85,6 +85,7 @@ typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg); ...@@ -85,6 +85,7 @@ typedef int(*qcmdfunc_t)(char*, int, telnet_printfunc_t prnt,void *arg);
#define TELNETSRV_CMDFLAG_WEBSRVONLY (1<<3) // Only for web server connections #define TELNETSRV_CMDFLAG_WEBSRVONLY (1<<3) // Only for web server connections
#define TELNETSRV_CMDFLAG_CONFEXEC (1<<4) // Ask for confirm before exec #define TELNETSRV_CMDFLAG_CONFEXEC (1<<4) // Ask for confirm before exec
#define TELNETSRV_CMDFLAG_GETWEBTBLDATA (1<<8) // When called from web server, use the get table data variant of the function #define TELNETSRV_CMDFLAG_GETWEBTBLDATA (1<<8) // When called from web server, use the get table data variant of the function
#define TELNETSRV_CMDFLAG_PRINTWEBTBLDATA (1<<9) // Print as a single column table
typedef struct cmddef { typedef struct cmddef {
char cmdname[TELNET_CMD_MAXSIZE]; char cmdname[TELNET_CMD_MAXSIZE];
char helpstr[TELNET_HELPSTR_SIZE]; char helpstr[TELNET_HELPSTR_SIZE];
......
...@@ -139,7 +139,9 @@ char toksep[2]; ...@@ -139,7 +139,9 @@ char toksep[2];
prnt("%s\n",prntline); prnt("%s\n",prntline);
} /*decode_procstat */ } /*decode_procstat */
void read_statfile(char *fname,int debug, telnet_printfunc_t prnt)
void read_statfile(char *fname,int debug, telnet_printfunc_t prnt, void *data)
{ {
FILE *procfile; FILE *procfile;
char arecord[1024]; char arecord[1024];
...@@ -169,9 +171,9 @@ struct dirent *entry; ...@@ -169,9 +171,9 @@ struct dirent *entry;
prnt(" id name state USRmod KRNmod prio nice vsize proc pol \n\n"); prnt("\n id name state USRmod KRNmod prio nice vsize proc pol \n\n");
snprintf(aname, sizeof(aname), "/proc/%d/stat", getpid()); snprintf(aname, sizeof(aname), "/proc/%d/stat", getpid());
read_statfile(aname,debug,prnt); read_statfile(aname,debug,prnt,NULL);
prnt("\n"); prnt("\n");
snprintf(aname, sizeof(aname), "/proc/%d/task", getpid()); snprintf(aname, sizeof(aname), "/proc/%d/task", getpid());
proc_dir = opendir(aname); proc_dir = opendir(aname);
...@@ -183,10 +185,11 @@ struct dirent *entry; ...@@ -183,10 +185,11 @@ struct dirent *entry;
while ((entry = readdir(proc_dir)) != NULL) while ((entry = readdir(proc_dir)) != NULL)
{ {
if(entry->d_name[0] == '.') if(entry->d_name[0] != '.')
continue; {
snprintf(aname, sizeof(aname), "/proc/%d/task/%.*s/stat", getpid(),(int)(sizeof(aname)-24),entry->d_name); snprintf(aname, sizeof(aname), "/proc/%d/task/%.*s/stat", getpid(),(int)(sizeof(aname)-24),entry->d_name);
read_statfile(aname,debug,prnt); read_statfile(aname,debug,prnt,NULL);
}
} /* while entry != NULL */ } /* while entry != NULL */
closedir(proc_dir); closedir(proc_dir);
} /* print_threads */ } /* print_threads */
...@@ -213,7 +216,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) { ...@@ -213,7 +216,7 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
logsdata->lines[i].val[0]= (char *)(g_log->log_component[i].name); logsdata->lines[i].val[0]= (char *)(g_log->log_component[i].name);
logsdata->lines[i].val[1]=map_int_to_str(log_level_names,(g_log->log_component[i].level>=0)?g_log->log_component[i].level:g_log->log_component[i].savedlevel); logsdata->lines[i].val[1]=map_int_to_str(log_level_names,(g_log->log_component[i].level>=0)?g_log->log_component[i].level:g_log->log_component[i].savedlevel);
logsdata->lines[i].val[2]=(g_log->log_component[i].level>=0)?(char *)0xFFFFFFFF:NULL; logsdata->lines[i].val[2]=(g_log->log_component[i].level>=0)?"true":"false";
logsdata->lines[i].val[3]=(g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout"; logsdata->lines[i].val[3]=(g_log->log_component[i].filelog>0)?g_log->log_component[i].filelog_name:"stdout";
} }
} }
...@@ -232,8 +235,8 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) { ...@@ -232,8 +235,8 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
for (int i=0; log_maskmap[i].name != NULL ; i++) { for (int i=0; log_maskmap[i].name != NULL ; i++) {
logsdata->numlines++; logsdata->numlines++;
logsdata->lines[i].val[0]= log_maskmap[i].name; logsdata->lines[i].val[0]= log_maskmap[i].name;
logsdata->lines[i].val[1]= (g_log->debug_mask & log_maskmap[i].value)?(char *)0xFFFFFFFF:NULL; logsdata->lines[i].val[1]= (g_log->debug_mask & log_maskmap[i].value)?"true":"false";
logsdata->lines[i].val[2]=(g_log->dump_mask & log_maskmap[i].value)?(char *)0xFFFFFFFF:NULL; logsdata->lines[i].val[2]=(g_log->dump_mask & log_maskmap[i].value)?"true":"false";
} }
} }
...@@ -249,9 +252,10 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) { ...@@ -249,9 +252,10 @@ int proccmd_websrv_getdata(char *cmdbuff, int debug, void *data) {
for (int i=0; log_options[i].name != NULL; i++) { for (int i=0; log_options[i].name != NULL; i++) {
logsdata->numlines++; logsdata->numlines++;
logsdata->lines[i].val[0]=log_options[i].name; logsdata->lines[i].val[0]=log_options[i].name;
logsdata->lines[i].val[1]=(g_log->flag & log_options[i].value)?(char *)0xFFFFFFFF:NULL; logsdata->lines[i].val[1]=(g_log->flag & log_options[i].value)?"true":"false";
} }
} }
return 0; return 0;
} }
...@@ -354,7 +358,7 @@ char sv1[64]; ...@@ -354,7 +358,7 @@ char sv1[64];
prnt(" proccmd_thread: %i params = %i,%s,%i\n",res,bv1,sv1,bv2); prnt(" proccmd_thread: %i params = %i,%s,%i\n",res,bv1,sv1,bv2);
if(res != 3) if(res != 3)
{ {
prnt("softmodem thread needs 3 params, %i received\n",res); print_threads(buf, debug, prnt);
return 0; return 0;
} }
......
...@@ -76,11 +76,11 @@ telnetshell_vardef_t proc_vardef[] = { ...@@ -76,11 +76,11 @@ telnetshell_vardef_t proc_vardef[] = {
telnetshell_cmddef_t proc_cmdarray[] = { telnetshell_cmddef_t proc_cmdarray[] = {
{"show","loglvl|thread|config", proccmd_show,{(webfunc_t)proccmd_websrv_getdata},TELNETSRV_CMDFLAG_TELNETONLY,NULL}, {"show","loglvl|thread|config", proccmd_show,{(webfunc_t)proccmd_websrv_getdata},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"log","(enter help for details)", proccmd_log, {NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL}, {"log","(enter help for details)", proccmd_log, {NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"show loglvl","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBDATA,NULL}, {"show loglvl","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL},
{"show logopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL}, {"show logopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL},
{"show dbgopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL}, {"show dbgopt","", proccmd_log,{(webfunc_t)proccmd_websrv_getdata}, TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_GETWEBTBLDATA,NULL},
{"show config","", proccmd_show,{(webfunc_t)proccmd_show}, TELNETSRV_CMDFLAG_WEBSRVONLY,NULL}, {"show config","", proccmd_show,{(webfunc_t)proccmd_show}, TELNETSRV_CMDFLAG_WEBSRVONLY,NULL},
{"thread","(enter help for details)", proccmd_thread,{(webfunc_t)proccmd_websrv_getdata},0,NULL}, {"show thread","", proccmd_thread,{(webfunc_t)proccmd_show},TELNETSRV_CMDFLAG_WEBSRVONLY|TELNETSRV_CMDFLAG_PRINTWEBTBLDATA,NULL},
{"exit","", proccmd_exit,{NULL},TELNETSRV_CMDFLAG_CONFEXEC,NULL}, {"exit","", proccmd_exit,{NULL},TELNETSRV_CMDFLAG_CONFEXEC,NULL},
{"","",NULL}, {"","",NULL},
}; };
......
...@@ -68,6 +68,7 @@ void websrv_printjson(char * label, json_t *jsonobj){ ...@@ -68,6 +68,7 @@ void websrv_printjson(char * label, json_t *jsonobj){
LOG_I(UTIL,"[websrv] %s:%s\n", label, (jstr==NULL)?"??\n":jstr); LOG_I(UTIL,"[websrv] %s:%s\n", label, (jstr==NULL)?"??\n":jstr);
free(jstr); free(jstr);
} }
void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wdata) ;
/*-----------------------------------*/ /*-----------------------------------*/
/* build a json body in a response */ /* build a json body in a response */
void websrv_jbody( struct _u_response * response, json_t *jbody) { void websrv_jbody( struct _u_response * response, json_t *jbody) {
...@@ -144,6 +145,27 @@ void websrv_printf_end(int httpstatus ) { ...@@ -144,6 +145,27 @@ void websrv_printf_end(int httpstatus ) {
pthread_mutex_unlock(&(websrv_printf_buff.mutex)); pthread_mutex_unlock(&(websrv_printf_buff.mutex));
} }
/* buid a response via a webdatadef_t structure containing one string column */
void websrv_printf_tbl_end(int httpstatus ) {
webdatadef_t pdata;
char *tokctx;
pdata.numcols=1;
pdata.numlines=0;
pdata.columns[0].coltype = TELNET_VARTYPE_STRING | TELNET_CHECKVAL_RDONLY;
pdata.columns[0].coltitle[0]=0;
for ( char *alineptr=strtok_r(websrv_printf_buff.buff,"\n",&tokctx); alineptr != NULL ; alineptr=strtok_r(NULL,"\n",&tokctx) ) {
pdata.lines[pdata.numlines].val[0]=alineptr;
pdata.numlines++;
}
websrv_gettbldata_response(websrv_printf_buff.response,&pdata);
free(websrv_printf_buff.buff);
websrv_printf_buff.buff=NULL;
pthread_mutex_unlock(&(websrv_printf_buff.mutex));
}
/*--------------------------------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------------------------------*/
/* format a json response from a result table returned from a call to a telnet server command */ /* format a json response from a result table returned from a call to a telnet server command */
void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata) { void websrv_getdata_response(struct _u_response * response,webdatadef_t * wdata) {
...@@ -190,7 +212,7 @@ void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wda ...@@ -190,7 +212,7 @@ void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wda
json_t *jline=json_array(); json_t *jline=json_array();
for (int j=0; j<wdata->numcols; j++) { for (int j=0; j<wdata->numcols; j++) {
if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL) if(wdata->columns[j].coltype & TELNET_CHECKVAL_BOOL)
jval=json_boolean(wdata->lines[i].val[j]); jval=json_string(wdata->lines[i].val[j]);
else if (wdata->columns[j].coltype & TELNET_VARTYPE_STRING) else if (wdata->columns[j].coltype & TELNET_VARTYPE_STRING)
jval=json_string(wdata->lines[i].val[j]); jval=json_string(wdata->lines[i].val[j]);
// else if (wdata->columns[j].coltype == TELNET_VARTYPE_DOUBLE) // else if (wdata->columns[j].coltype == TELNET_VARTYPE_DOUBLE)
...@@ -201,9 +223,10 @@ void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wda ...@@ -201,9 +223,10 @@ void websrv_gettbldata_response(struct _u_response * response,webdatadef_t * wda
} }
json_array_append_new(jdata,jline); json_array_append_new(jdata,jline);
} }
json_t *jbody=json_pack("{s:o,s:o}","columns",jcols,"rows",jdata); json_t *jbody=json_pack("{s:[],s:{s:o,s:o}}","display","table","columns",jcols,"rows",jdata);
websrv_jbody(response,jbody); websrv_jbody(response,jbody);
} }
/*----------------------------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------------------------*/
/* callbacks and utility functions to stream a file */ /* callbacks and utility functions to stream a file */
char * websrv_read_file(const char * filename) { char * websrv_read_file(const char * filename) {
...@@ -449,7 +472,11 @@ int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestr ...@@ -449,7 +472,11 @@ int websrv_processwebfunc(struct _u_response * response, cmdparser_t * modulestr
websrv_gettbldata_response(response,&wdata); websrv_gettbldata_response(response,&wdata);
} else { } else {
websrv_printf_start(response,16384); websrv_printf_start(response,16384);
cmd->cmdfunc(cmd->cmdname,websrvparams.dbglvl,websrv_printf); char *sptr=index(cmd->cmdname,' ');
cmd->cmdfunc((sptr==NULL)?cmd->cmdname:sptr,websrvparams.dbglvl,websrv_printf);
if (cmd->cmdflags & TELNETSRV_CMDFLAG_PRINTWEBTBLDATA)
websrv_printf_tbl_end(200);
else
websrv_printf_end(200); websrv_printf_end(200);
} }
return 200; return 200;
......
...@@ -49,8 +49,10 @@ static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt) ...@@ -49,8 +49,10 @@ static int channelmod_modify_cmd(char *buff, int debug, telnet_printfunc_t prnt)
static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt); static int channelmod_print_help(char *buff, int debug, telnet_printfunc_t prnt);
static telnetshell_cmddef_t channelmod_cmdarray[] = { static telnetshell_cmddef_t channelmod_cmdarray[] = {
{"help","",channelmod_print_help,{NULL},0,NULL}, {"help","",channelmod_print_help,{NULL},0,NULL},
{"show","<predef,current>",channelmod_show_cmd,{NULL},0,NULL}, {"show","<predef,current>",channelmod_show_cmd,{NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"modify","<channelid> <param> <value>",channelmod_modify_cmd,{NULL},0,NULL}, {"show predef","",channelmod_show_cmd,{NULL},TELNETSRV_CMDFLAG_WEBSRVONLY,NULL},
{"show current","",channelmod_show_cmd,{NULL},TELNETSRV_CMDFLAG_WEBSRVONLY,NULL},
{"modify","<channelid> <param> <value>",channelmod_modify_cmd,{NULL},TELNETSRV_CMDFLAG_TELNETONLY,NULL},
{"","",NULL,{NULL},0,NULL}, {"","",NULL,{NULL},0,NULL},
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment