499 lines
13 KiB
C++
499 lines
13 KiB
C++
#include <ncurses.h>
|
|
#include "ausreg-cd.h"
|
|
|
|
#define ASSERT(expr) \
|
|
if (!(expr)) { \
|
|
std::cerr << __FILE__ << ":" << __LINE__ << ":" << #expr << std::endl;}
|
|
|
|
const char *banner = CD_NAME " " CD_VERSION " compiled on " __DATE__ " @ " __TIME__ " (%d)";
|
|
const char *cmdNames[9] = { "check", "info", "poll", "transfer query",
|
|
"create", "renew", "update", "delete", "transfer" };
|
|
char theBanner[256];
|
|
int targetHost = 0;
|
|
|
|
mdDG mdg;
|
|
|
|
int is_numeric(const char *p) { int i = strlen(p),j=0;
|
|
if (*p) {
|
|
char c;
|
|
while ((c=*p++)) { j++;
|
|
if (!isdigit(c)) {
|
|
if (j == i) return 2;
|
|
else return 0;
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
void mdCommander::doHeader() {
|
|
|
|
int displayCmd = cmdsNow ? cmdNow + 1 : 0;
|
|
|
|
clear();
|
|
mvprintw(0,(col-strlen(banner))/2,"%s",theBanner);
|
|
sprintf(wwork,"Target AC host: %d this one: %d commmands: %d current: %d",
|
|
targetHost,mdStdDevIdx,activeCommands,displayCmd);
|
|
mvprintw(1,(col-strlen(wwork))/2,"%s",wwork);
|
|
|
|
}
|
|
void mdCommander::digestibleLines() {
|
|
|
|
char buffer[256],*sp;
|
|
int nLines=0, wrow=5;
|
|
|
|
nocbreak();
|
|
for (;argsNow[cmdNow] < MAX_CMD_ARGS;)
|
|
{memset(buffer,0,sizeof(buffer));
|
|
mvgetstr(wrow++,2,buffer);
|
|
if (strlen(buffer)) {
|
|
sp = (char *) malloc(strlen(buffer)+1);
|
|
commandArgs[cmdNow][argsNow[cmdNow]++] = sp;
|
|
strcpy(sp,buffer);
|
|
}
|
|
else break;
|
|
}
|
|
cbreak();
|
|
prompt(false);
|
|
|
|
}
|
|
void mdCommander::prompt(bool forStrings) {
|
|
|
|
if (forStrings)
|
|
mvprintw(row-1,1,">>");
|
|
else
|
|
mvprintw(row-1,1,">");
|
|
|
|
}
|
|
void mdCommander::driver() {
|
|
|
|
bool rc, x;
|
|
char next,rawString[128],work[128];
|
|
const char *mdErrCode = "";
|
|
int i,commandLength;
|
|
|
|
activeCommands = 0;
|
|
cmdNow = 0;
|
|
cmdsNow = 0;
|
|
memset(commandsNow,0,sizeof(commandsNow));
|
|
memset(argsNow,0,sizeof(argsNow));
|
|
initscr();
|
|
cbreak();
|
|
greet();
|
|
while(acceptingInput) {
|
|
mvprintw(row-1,1,"> ");
|
|
next=0;
|
|
i=0;
|
|
memset(rawString,0,sizeof(rawString));
|
|
while(next != '\012') {
|
|
next = mvgetch(row-1,2+i);
|
|
rawString[i++] = next;
|
|
if (i > (sizeof(rawString) - 1)) {
|
|
say((char *)"Max length exceeded!");
|
|
continue;
|
|
}
|
|
if (next == '\012')
|
|
rawString[strlen(rawString)-1] = 0;
|
|
}
|
|
if (!strlen(rawString)) continue;
|
|
if (strlen(rawString) == 1) {
|
|
switch(rawString[0]) {
|
|
case '1': ; case '2': ; case '3': ; case '4': ; case '5': ;
|
|
case '6': ; case '7': ; case '8': ; case '9':
|
|
goto retarget ;
|
|
case '!': runCommand(false);
|
|
break;
|
|
case '?': help();
|
|
break;
|
|
case 'e': eppMainMenu();
|
|
break;
|
|
case 'a': acMainMenu();
|
|
break;
|
|
case 'c': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
check(false);
|
|
break;
|
|
case 'p': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
poll(false);
|
|
break;
|
|
case 'i': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
info(false);
|
|
break;
|
|
case 't': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
queryTransfer(false);
|
|
break;
|
|
case 'C': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
create(false);
|
|
break;
|
|
case 'R': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
renew(false);
|
|
break;
|
|
case 'U': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
update(false);
|
|
break;
|
|
case 'D': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
trash(false);
|
|
break;
|
|
case 'T': commandsNow[(cmdNow=cmdsNow++)]; activeCommands++;
|
|
transfer(false);
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
if (strlen(rawString) == 2) {
|
|
if (!strcmp(rawString,"??")) {
|
|
showCommand(true);
|
|
continue;
|
|
}
|
|
if (!strcmp(rawString,"!!")) {
|
|
runCommand(true);
|
|
continue;
|
|
}
|
|
}
|
|
if (is_numeric(rawString) >= 1) {
|
|
retarget:
|
|
targetHost = atoi(rawString);
|
|
doHeader();
|
|
continue;
|
|
}
|
|
if (is_numeric(rawString+1) >= 1) {
|
|
int targetCmd = atoi(rawString+1);
|
|
switch(rawString[0]) {
|
|
case 'C':
|
|
if (isValidCmd(targetCmd,false)) {
|
|
cmdNow = --targetCmd;
|
|
doHeader();}
|
|
else say((char *)"Invalid Command Index");
|
|
break;
|
|
case 'E':
|
|
if (isValidCmd(targetCmd,false)) {
|
|
cmdNow = --targetCmd;
|
|
editingCommand(false);
|
|
doHeader();}
|
|
help();
|
|
break;
|
|
case 'S':
|
|
if (isValidCmd(targetCmd,false)) {
|
|
cmdNow = --targetCmd;
|
|
sendCommand(cmdNow);
|
|
doHeader();
|
|
}
|
|
else say((char *)"Invalid Command Index");
|
|
break;
|
|
case 'X':
|
|
if (!targetCmd) {targetCmd = 0; x = true;}
|
|
else {targetCmd--; x = false;}
|
|
if (isValidCmd(targetCmd,true)) {
|
|
flushCommand(targetCmd,x);
|
|
doHeader();
|
|
}
|
|
else say((char *)"Invalid Command Index");
|
|
break;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
if (strlen(rawString) >= 3 && strlen(rawString) <= 5 )
|
|
{if (!strcmp(rawString,"log")) {
|
|
sprintf(wwork,"cut -b 1-%d /tmp/ausreg-cd.log | less",col);
|
|
system(wwork);
|
|
clear();
|
|
continue;
|
|
}
|
|
if (!strcmp(rawString,"mlog")) {
|
|
sprintf(wwork,"cut -b 1-%d /tmp/drde-cliever.log | less",col);
|
|
system(wwork);
|
|
clear();
|
|
continue;
|
|
}
|
|
if (!strcmp(rawString,"done")) {
|
|
goto done;
|
|
}
|
|
if (!strcmp(rawString,"quit")) {
|
|
thisConfig->terminateRequest = true;
|
|
goto done;
|
|
}
|
|
continue;
|
|
}
|
|
|
|
}
|
|
done:
|
|
nocbreak();
|
|
endwin();
|
|
}
|
|
void mdCommander::say(char *what)
|
|
{ memset(wwork,' ',sizeof(wwork));
|
|
mvprintw(row-2,1,wwork);
|
|
mvprintw(row-2,1,what);
|
|
}
|
|
void mdCommander::greet() {
|
|
|
|
const char *title="AusReg Cliever Commander",
|
|
*prompt="? for main menu or enter commander command now";
|
|
|
|
sprintf(theBanner,banner,thisConfig->shellProcess);
|
|
getmaxyx(stdscr,row,col);
|
|
mvprintw(0,(col-strlen(banner))/2,"%s",theBanner);
|
|
mvprintw(row/2,(col-strlen(title))/2,"%s",title);
|
|
mvprintw(row-2,1,"%s",prompt);
|
|
refresh();
|
|
acceptingInput = true;
|
|
EPPmode = true;
|
|
|
|
}
|
|
void mdCommander::help() {
|
|
|
|
doHeader();
|
|
mvprintw(5,10," a - AC system control menu");
|
|
mvprintw(6,10," e - standard EPP command menu");
|
|
mvprintw(7,10," ? - display this screen");
|
|
mvprintw(8,10," ?? - display commands");
|
|
mvprintw(9,10," ! - run the active command");
|
|
mvprintw(10,10," !! - run active commands");
|
|
mvprintw(11,10," C<n> - make <n> the active command");
|
|
mvprintw(12,10," E<n> - display/edit command <n> ");
|
|
mvprintw(13,10," S<n> - send command <n>");
|
|
mvprintw(14,10," X<n> - discard the command(s)");
|
|
mvprintw(15,10," <n> - make <n> the target EPP server");
|
|
mvprintw(16,10," log - display this cliever's log");
|
|
mvprintw(17,10," mlog - display the master daemon log");
|
|
mvprintw(18,10," done - terminate commander but not process");
|
|
mvprintw(19,10," quit - terminate this process and its' children");
|
|
mvprintw(23,5,"<n> is an integer, above active everywhere outside data entry (>>)");
|
|
mvprintw(24,5,"no space before <n>, X0 to delete all commands.");
|
|
|
|
}
|
|
void mdCommander::eppMainMenu() {
|
|
|
|
doHeader();
|
|
mvprintw(5,10," Create a new EPP command");
|
|
|
|
mvprintw(10,10," Queries ");
|
|
mvprintw(12,10," c - check");
|
|
mvprintw(13,10," i - info");
|
|
mvprintw(14,10," p - poll");
|
|
mvprintw(15,10," t - transfer query");
|
|
mvprintw(17,10," Transactions");
|
|
mvprintw(19,10," C - create");
|
|
mvprintw(20,10," R - renew");
|
|
mvprintw(21,10," U - update");
|
|
mvprintw(22,10," D - delete");
|
|
mvprintw(23,10," T - transfer");
|
|
|
|
}
|
|
void mdCommander::acMainMenu() {
|
|
|
|
doHeader();
|
|
mvprintw(5,(col-strlen("AC System Directives"))/2,"AC System Directives");
|
|
|
|
mvprintw(15,10," (H)ALT - Flush queues, stop, ignore incoming requests");
|
|
mvprintw(16,10," (L)OAD - Resume execution, accept work");
|
|
mvprintw(17,10," (B)ANG - Force reload the entire AC system");
|
|
mvprintw(20,10,"These are only active on this screen, there's no confirmation.");
|
|
|
|
}
|
|
bool sendEPPCommand() {
|
|
|
|
mdg.dg.hdr.sourceHandle = thisCliever->myHandle;
|
|
mdg.dg.hdr.payloadSize = 0;
|
|
mdg.dg.hdr.msgType = MDDG_CDRESET;
|
|
return thisCliever->fg->send(mdg.dg);
|
|
}
|
|
bool mdCommander::runCommand(bool allOfEm) {
|
|
|
|
bool value=false;
|
|
|
|
if (!activeCommands) {say((char *)"There is no active command."); goto done;}
|
|
|
|
say((char *)"Command execution temporarily disabled.");
|
|
|
|
done: return value;
|
|
|
|
}
|
|
//--------------------------------
|
|
void mdCommander::flushCommand(int which,bool allOfEm){
|
|
|
|
int i,j;
|
|
|
|
if (!allOfEm) {
|
|
if (argsNow[which]) {
|
|
for (i=0;i<argsNow[which];i++)
|
|
free(commandArgs[which][i]);
|
|
}
|
|
argsNow[which] = 0;
|
|
deleted[which] = true;
|
|
activeCommands--;
|
|
} else for (i=0;i<cmdsNow;i++) {
|
|
if (!deleted[i]) {
|
|
if (argsNow[i]) {
|
|
for (j=0;j<argsNow[i];j++)
|
|
free(commandArgs[i][j]);
|
|
}
|
|
else deleted[i] = false; // back to start state.
|
|
}
|
|
cmdNow = 0;
|
|
cmdsNow = 0;
|
|
activeCommands = 0;
|
|
memset(commandArgs,0,sizeof(commandArgs));
|
|
memset(argsNow,0,sizeof(argsNow));
|
|
}
|
|
|
|
};
|
|
void mdCommander::sendCommand(int which){
|
|
|
|
say((char *)"Command processing disabled here during OTE Basic Testing");
|
|
};
|
|
void mdCommander::showCommand(bool allOfEm){
|
|
|
|
int activethCommand=0,i,nthItem;
|
|
const char *befehlJetzt = cmdNames[commandsNow[cmdNow]];
|
|
|
|
doHeader();
|
|
|
|
if (!activeCommands) {say((char *)"There is no active command."); goto done;}
|
|
|
|
if (!allOfEm) {
|
|
|
|
sprintf(wwork,"EPP directive: %s",befehlJetzt);
|
|
mvprintw(5,2,wwork);
|
|
for (nthItem=0;nthItem < argsNow[cmdNow];nthItem++) {
|
|
ASSERT(commandArgs[cmdNow][nthItem]);
|
|
sprintf(wwork,"%d %s",nthItem+1,(commandArgs[cmdNow][nthItem]));
|
|
mvprintw(7+nthItem,2,wwork);
|
|
}
|
|
|
|
} else {
|
|
|
|
mvprintw(5,2,"These commands are pending/active: ");
|
|
|
|
for ( i=0, nthItem=0; nthItem < cmdsNow;nthItem++ ) {
|
|
|
|
if (!deleted[nthItem]) {
|
|
sprintf(wwork,"%d %s %s",nthItem+1,cmdNames[commandsNow[nthItem]],commandArgs[nthItem][0]);
|
|
mvprintw(7+(i++),2,wwork);
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
done: return;
|
|
|
|
};
|
|
//--------------------------------
|
|
// EPP Queries and Commands
|
|
//-------------------------------
|
|
bool mdCommander::editingCommand(bool run){
|
|
const char *befehlJetzt = cmdNames[commandsNow[cmdNow]];
|
|
|
|
char sp[256],*spp;
|
|
int editLine,length;
|
|
doHeader();
|
|
mvprintw(3,(col-strlen(befehlJetzt))/2,befehlJetzt);
|
|
|
|
if (!run) {
|
|
if (!argsNow[cmdNow]) {
|
|
say((char *)"Enter command arg strings, just enter to end data entry, ? to main menu");
|
|
prompt(true);
|
|
digestibleLines();
|
|
} else {
|
|
nocbreak();
|
|
while(true) {
|
|
showCommand(false);
|
|
say((char *)"line no to replace, A to add, enter to return");
|
|
prompt(false);
|
|
mvgetstr(row-1,2,sp);
|
|
if (!strlen(sp)) goto done;
|
|
if (*sp == 'A' || *sp == 'a') {
|
|
prompt(true);
|
|
mvgetstr(row-1,2,sp);
|
|
if (length=strlen(sp)) {
|
|
spp = commandArgs[cmdNow][argsNow[cmdNow]++] = (char *) malloc(length+1);
|
|
strcpy(spp,sp);
|
|
}
|
|
}
|
|
if (is_numeric(sp) >= 1) {
|
|
editLine = atoi(sp);
|
|
if (editLine > 1 && editLine < argsNow[cmdNow]) {
|
|
prompt(true);
|
|
mvgetstr(row-1,2,sp);
|
|
if (length=strlen(sp)) {
|
|
free (commandArgs[cmdNow][editLine-1]);
|
|
spp = commandArgs[cmdNow][editLine-1] = (char *) malloc(strlen(sp)+1);
|
|
strcpy(spp,sp);
|
|
}
|
|
}
|
|
}
|
|
} // editing loop
|
|
done: cbreak();
|
|
} // editing block
|
|
} // run / execute
|
|
else {
|
|
say((char *)"Press 'Y' to confirm");
|
|
}
|
|
|
|
};
|
|
void mdCommander::check(bool run) {
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 0;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
}
|
|
void mdCommander::create(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 4;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::info(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 1;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::renew(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 5;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::queryTransfer(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 3;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::trash(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 7;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::transfer(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 8;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::poll(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 2;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
void mdCommander::update(bool run){
|
|
|
|
if (!commandsNow[cmdNow]) commandsNow[cmdNow] = 6;
|
|
if (!editingCommand(run)) {
|
|
|
|
} else help();
|
|
};
|
|
|