/*
This file is part of Bolixo.
Bolixo is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bolixo is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bolixo. If not, see .
*/
/*
Command line tool to control bo-sessiond
*/
#include
#include
#include
#include
#include
#include
#include
#include "bolixo.m"
using namespace std;
#include "proto/bo-sessiond_control.protoch"
int main (int argc, char *argv[])
{
glocal int ret = -1;
glocal const char *control = "/var/run/bo-sessiond.sock";
glocal.ret = (argc,argv,"bolixo");
setproginfo ("bo-sessiond-control",VERSION
,"Command line tool to control bo-sessiond\n"
"\n"
"\tdebug 0/1\n"
"\tdebugfile filename\n"
"\teraseold time anonymous normaluser adminuser\n"
"\t\ttime is a number followed by d for days, h for hours, m for minutes, s for seconds\n"
"\tinstrument 0|1\n"
"\tlistsessions offset nb\n"
"\tresetnotifies\n"
"\tstuffsessions nb\n"
"\tquit\n"
"\tstatus\n"
);
setarg ('p',"control","Unix socket to reach sessiond",glocal.control,false);
int ret = -1;
CONNECT_INFO con;
con.port = glocal.control;
if (strcmp(argv[0],"status")==0 && argc==1){
(con);
for (auto x:lines) printf ("%s\n",x);
}else if (strcmp(argv[0],"quit")==0 && argc==1){
(con);
}else if (strcmp(argv[0],"listsessions")==0 && argc==3){
(con,atoi(argv[1]),atoi(argv[2]));
for (auto x:lines) printf ("%s\n",x);
}else if (strcmp(argv[0],"resetnotifies")==0 && argc==1){
(con);
}else if (strcmp(argv[0],"stuffsessions")==0 && argc==2){
(con,atoi(argv[1]));
printf ("total=%u\n",total);
}else if (strcmp(argv[0],"eraseold")==0 && argc==5){
unsigned old = atoi(argv[1]);
const char *pt = str_skipdig(argv[1]);
char letter = tolower(*pt);
if (letter == 'd'){
old *= 24*60*60;
}else if (letter == 'h'){
old *= 60*60;
}else if (letter == 'm'){
old *= 60;
}else if (letter != 's'){
tlmp_error (MSG_U(E_EXPECTDHMS,"Expect suffix d h m or s for duration, aborting\n"));
exit (-1);
}
(con,old,atoi(argv[2]),atoi(argv[3]),atoi(argv[4]));
printf ("deletedanon=%u deleteduser=%u deletedadmin=%u\n",deletedanon,deleteduser,deletedadmin);
}else if (strcmp(argv[0],"debug")==0 && argc==2){
(con,atoi(argv[1]));
}else if (strcmp(argv[0],"debugfile")==0 && argc==2){
(con,argv[1]);
}else if (strcmp(argv[0],"instrument")==0 && argc==2){
(con,atoi(argv[1]));
}else{
tlmp_error ("Invalid command: %s\n",argv[0]);
usage();
}
return ret;
return glocal.ret;
}