X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=blobdiff_plain;f=admin_client.c;h=02624a08d164519cbef490e5b4dbe276fe2bfbc1;hp=5ab45f6eb82036cf8009c7e8ebaa5083eab14aa2;hb=701b046a45c2c79cc6d07ac3a4f84f499f7ed376;hpb=ef3fc1931a2fa82f482d21fb1296735206463d3a diff --git a/admin_client.c b/admin_client.c index 5ab45f6..02624a0 100644 --- a/admin_client.c +++ b/admin_client.c @@ -1,6 +1,6 @@ /*****************************************************************************\ ** ** -** LCR ** +** Linux Call Router ** ** ** **---------------------------------------------------------------------------** ** Copyright: Andreas Eversberg ** @@ -21,8 +21,8 @@ #include #include #include "macro.h" -#include "call.h" -#include "callpbx.h" +#include "join.h" +#include "joinpbx.h" #include "extension.h" #include "message.h" #include "admin.h" @@ -73,7 +73,7 @@ char red = 1, white = 7; #define LOGLINES 128 -char logline[LOGLINES][256]; +char logline[LOGLINES][512]; unsigned long logcur = 0; int logfh = -1; char logfile[128]; @@ -357,7 +357,7 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i } /* loop all related ports */ ltee = 0; - j = msg->u.s.interfaces+msg->u.s.calls+msg->u.s.epoints; + j = msg->u.s.interfaces+msg->u.s.joins+msg->u.s.epoints; jj = j + msg->u.s.ports; while(j < jj) { @@ -388,39 +388,47 @@ int debug_epoint(struct admin_message *msg, struct admin_message *m, int line, i return(line); } -int debug_call(struct admin_message *msg, struct admin_message *m, int line, int i) +int debug_join(struct admin_message *msg, struct admin_message *m, int line, int i) { - unsigned long call = m[i].u.c.serial; + unsigned long join = m[i].u.j.serial; char buffer[256]; int j, jj; color(white); - SPRINT(buffer,"CALL(%d)", call); + SPRINT(buffer,"JOIN(%d)", join); addstr(buffer); - if (m[i].u.c.partyline) + if (m[i].u.j.partyline) { color(cyan); addstr(" partyline="); color(white); - SPRINT(buffer, "%d\n", m[i].u.c.partyline); + SPRINT(buffer, "%d\n", m[i].u.j.partyline); + addstr(buffer); + } + if (m[i].u.j.remote[0]) + { + color(cyan); + addstr(" remote="); + color(white); + SPRINT(buffer, "%s\n", m[i].u.j.remote); addstr(buffer); } /* find number of epoints */ - j = msg->u.s.interfaces+msg->u.s.calls; + j = msg->u.s.interfaces+msg->u.s.joins; jj = j + msg->u.s.epoints; i = 0; while(j < jj) { - if (m[j].u.e.call == call) + if (m[j].u.e.join == join) i++; j++; } /* loop all related endpoints */ - j = msg->u.s.interfaces+msg->u.s.calls; + j = msg->u.s.interfaces+msg->u.s.joins; jj = j + msg->u.s.epoints; while(j < jj) { - if (m[j].u.e.call == call) + if (m[j].u.e.join == join) { i--; move(++line>1?line:1, 1); @@ -439,13 +447,13 @@ int debug_call(struct admin_message *msg, struct admin_message *m, int line, int return(line); } -char *admin_state(int sock) +char *admin_state(int sock, char *argv[]) { struct admin_message msg, *m; - char buffer[256], + char buffer[512], *p; - int line, offset = 0; + int line, offset = 0, hoffset = 0; int i, ii, j, jj, k; unsigned long l, ll; int num; @@ -453,6 +461,8 @@ char *admin_state(int sock) int off; int ltee; int anything; + int enter = 0; + char enter_string[128] = "", ch; /* flush logfile name */ logfile[0] = '\0'; @@ -483,7 +493,7 @@ char *admin_state(int sock) cleanup_curses(); return("Response not valid. Expecting state response."); } - num = msg.u.s.interfaces + msg.u.s.calls + msg.u.s.epoints + msg.u.s.ports; + num = msg.u.s.interfaces + msg.u.s.remotes + msg.u.s.joins + msg.u.s.epoints + msg.u.s.ports; m = (struct admin_message *)MALLOC(num*sizeof(struct admin_message)); off=0; if (num) @@ -520,13 +530,25 @@ char *admin_state(int sock) j++; } i = 0; - while(i < msg.u.s.calls) + while(i < msg.u.s.remotes) { - if (m[j].message != ADMIN_RESPONSE_S_CALL) + if (m[j].message != ADMIN_RESPONSE_S_REMOTE) { FREE(m, 0); cleanup_curses(); - return("Response not valid. Expecting call information."); + return("Response not valid. Expecting remote application information."); + } + i++; + j++; + } + i = 0; + while(i < msg.u.s.joins) + { + if (m[j].message != ADMIN_RESPONSE_S_JOIN) + { + FREE(m, 0); + cleanup_curses(); + return("Response not valid. Expecting join information."); } i++; j++; @@ -705,7 +727,7 @@ char *admin_state(int sock) if (m[i].u.i.port[j]) { /* search for port */ - l = msg.u.s.interfaces+msg.u.s.calls+msg.u.s.epoints; + l = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints; ll = l+msg.u.s.ports; while(l < ll) { @@ -761,6 +783,17 @@ char *admin_state(int sock) i++; anything = 1; } + i = 0; + ii = i + msg.u.s.remotes; + while(i < ii) + { + /* show remote summary */ + move(++line>1?line:1, 0); + color(white); + SPRINT(buffer, "Remote: %s", m[i].u.r.name); + addstr(buffer); + i++; + } if (anything) line++; if (line+2 >= LINES) goto end; @@ -769,12 +802,12 @@ char *admin_state(int sock) if (show_calls == 1) { anything = 0; - i = msg.u.s.interfaces+msg.u.s.calls; + i = msg.u.s.interfaces+msg.u.s.joins; ii = i+msg.u.s.epoints; while(i < ii) { /* for each endpoint... */ - if (!m[i].u.e.call) + if (!m[i].u.e.join) { move(++line>1?line:1, 0); color(white); @@ -809,20 +842,20 @@ char *admin_state(int sock) anything = 1; } j = msg.u.s.interfaces; - jj = j+msg.u.s.calls; + jj = j+msg.u.s.joins; while(j < jj) { /* for each call... */ move(++line>1?line:1, 0); color(white); - SPRINT(buffer, "(%d):", m[j].u.c.serial); + SPRINT(buffer, "(%d):", m[j].u.j.serial); addstr(buffer); - i = msg.u.s.interfaces+msg.u.s.calls; + i = msg.u.s.interfaces+msg.u.s.joins; ii = i+msg.u.s.epoints; while(i < ii) { /* for each endpoint... */ - if (m[i].u.e.call == m[j].u.c.serial) + if (m[i].u.e.join == m[j].u.j.serial) { color(white); SPRINT(buffer, " (%d)", m[i].u.e.serial); @@ -859,7 +892,7 @@ char *admin_state(int sock) { /* show all ports with no epoint */ anything = 0; - i = msg.u.s.interfaces+msg.u.s.calls+msg.u.s.epoints; + i = msg.u.s.interfaces+msg.u.s.joins+msg.u.s.epoints; ii = i+msg.u.s.ports; while(i < ii) { @@ -879,11 +912,11 @@ char *admin_state(int sock) /* show all epoints with no call */ anything = 0; - i = msg.u.s.interfaces+msg.u.s.calls; + i = msg.u.s.interfaces+msg.u.s.joins; ii = i+msg.u.s.epoints; while(i < ii) { - if (!m[i].u.e.call) + if (!m[i].u.e.join) { move(++line>1?line:1, 4); if (line+2 >= LINES) goto end; @@ -897,15 +930,15 @@ char *admin_state(int sock) line++; if (line+2 >= LINES) goto end; - /* show all calls */ + /* show all joins */ anything = 0; i = msg.u.s.interfaces; - ii = i+msg.u.s.calls; + ii = i+msg.u.s.joins; while(i < ii) { move(++line>1?line:1, 0); if (line+2 >= LINES) goto end; - line = debug_call(&msg, m, line, i); + line = debug_join(&msg, m, line, i); if (line+2 >= LINES) goto end; i++; anything = 1; @@ -933,10 +966,19 @@ char *admin_state(int sock) while(l!=ll) { move(line++>1?line-1:1, 0); - SCPY(buffer, logline[l % LOGLINES]); - if (COLS < (int)sizeof(buffer)) - buffer[COLS] = '\0'; - addstr(buffer); + if (strlen(logline[l % LOGLINES]) > hoffset) + SCPY(buffer, logline[l % LOGLINES] + hoffset); + else + buffer[0] = '\0'; + if (COLS < (int)strlen(buffer)) + { + buffer[COLS-1] = '\0'; + addstr(buffer); + color(red); + addch('*'); + color(white); + } else + addstr(buffer); l++; } } @@ -972,13 +1014,23 @@ char *admin_state(int sock) color(red); addstr(buffer); } + if (hoffset) + { + move(1, 13); + SPRINT(buffer, "H-Offset +%d", hoffset); + color(red); + addstr(buffer); + } /* display end */ move(LINES-2, 0); color(white); hline(ACS_HLINE, COLS); move(LINES-1, 0); color(white); - SPRINT(buffer, "i = interfaces '%s' c = calls '%s' l = log q = quit +/- = scroll", text_interfaces[show_interfaces], text_calls[show_calls]); + if (enter) + SPRINT(buffer, "-> %s", enter_string); + else + SPRINT(buffer, "i=interfaces '%s' c=calls '%s' l=log q=quit +-*/=scroll enter", text_interfaces[show_interfaces], text_calls[show_calls]); addstr(buffer); refresh(); @@ -990,47 +1042,125 @@ char *admin_state(int sock) goto again; } - /* user input */ - switch(getch()) + if (enter) { - case 12: /* refresh */ - cleanup_curses(); - init_curses(); - goto again; - break; - - case 3: /* abort */ - case 'q': - case 'Q': - break; + /* user input in enter mode */ + ch = getch(); + if (ch == 10) + { + FILE *fp; + + enter = 0; + if (!enter_string[0]) + goto again; + + SPRINT(logline[logcur++ % LOGLINES], "> %s", enter_string); + if (!!strncmp(enter_string, "interface", 10) && + !!strncmp(enter_string, "route", 6) && + !!strncmp(enter_string, "release ", 8) && + !!strncmp(enter_string, "block ", 6) && + !!strncmp(enter_string, "unblock ", 8) && + !!strncmp(enter_string, "unload ", 7)) + { + SPRINT(logline[logcur++ % LOGLINES], "usage:"); + SPRINT(logline[logcur++ % LOGLINES], "interface (reload interface.conf)"); + SPRINT(logline[logcur++ % LOGLINES], "route (reload routing.conf)"); + SPRINT(logline[logcur++ % LOGLINES], "release (release endpoint with given ID)"); + SPRINT(logline[logcur++ % LOGLINES], "block (block port for further calls)"); + SPRINT(logline[logcur++ % LOGLINES], "unblock (unblock port for further calls, load if not loaded)"); + SPRINT(logline[logcur++ % LOGLINES], "unload (unload mISDN stack, release call calls)"); + } else + { + /* applend output to log window */ + SPRINT(buffer, "%s %s", argv[0], enter_string); + fp = popen(buffer, "r"); + if (fp) + { + while(fgets(logline[logcur % LOGLINES], sizeof(logline[0]), fp)) + logline[logcur++ % LOGLINES][sizeof(logline[0])-1] = '\0'; + pclose(fp); + } else + { + SPRINT(logline[logcur++ % LOGLINES], "failed to execute '%s'", buffer); + } + } + logline[logcur % LOGLINES][0] = '\0'; + enter_string[0] = '\0'; + goto again; + } + if (ch>=32 && ch<=126) + { + SCCAT(enter_string, ch); + goto again; + } else + if (ch==8 || ch==127) + { + if (enter_string[0]) + enter_string[strlen(enter_string)-1] = '\0'; + goto again; + } else + if (ch != 3) + { + usleep(250000); + goto again; + } + } else + { + /* user input in normal mode */ + switch(getch()) + { + case 12: /* refresh */ + cleanup_curses(); + init_curses(); + goto again; + break; - case 'i': /* toggle interface */ - show_interfaces++; - if (show_interfaces > 3) show_interfaces = 0; - goto again; + case 3: /* abort */ + case 'q': + case 'Q': + break; - case 'c': /* toggle calls */ - show_calls++; - if (show_calls > 2) show_calls = 0; - goto again; + case 'i': /* toggle interface */ + show_interfaces++; + if (show_interfaces > 3) show_interfaces = 0; + goto again; - case 'l': /* toggle log */ - show_log++; - if (show_log > 1) show_log = 0; - goto again; + case 'c': /* toggle calls */ + show_calls++; + if (show_calls > 2) show_calls = 0; + goto again; - case '+': /* scroll down */ - offset++; - goto again; - - case '-': /* scroll up */ - if (offset) - offset--; - goto again; + case 'l': /* toggle log */ + show_log++; + if (show_log > 1) show_log = 0; + goto again; - default: - usleep(250000); - goto again; + case '+': /* scroll down */ + offset++; + goto again; + + case '-': /* scroll up */ + if (offset) + offset--; + goto again; + + case '*': /* scroll right */ + hoffset += 2; + goto again; + + case '/': /* scroll left */ + if (hoffset) + hoffset -= 2; + goto again; + + case 10: /* entermode */ + enter = 1; + goto again; + + default: + usleep(250000); + goto again; + } } /* check for logfh */ @@ -1425,7 +1555,7 @@ int main(int argc, char *argv[]) switch(mode) { case MODE_STATE: - ret = admin_state(sock); + ret = admin_state(sock, argv); break; case MODE_INTERFACE: