// vim: sw=4 ts=8
char const *cvs_name = "$Name: $";
-char const *cvs_id_cli = "$Id: cli.c,v 1.6 2004/06/28 02:43:13 fred_nerk Exp $";
+char const *cvs_id_cli = "$Id: cli.c,v 1.8 2004/07/07 09:09:53 bodea Exp $";
#include <stdio.h>
#include <stdarg.h>
int cmd_uptime(struct cli_def *cli, char *command, char **argv, int argc);
int regular_stuff(struct cli_def *cli);
-void init_cli()
+void init_cli(char *hostname)
{
FILE *f;
char buf[4096];
struct sockaddr_in addr;
cli = cli_init();
- cli_set_hostname(cli, "l2tpns");
+ if (hostname && *hostname)
+ cli_set_hostname(cli, hostname);
+ else
+ cli_set_hostname(cli, "l2tpns");
c = cli_register_command(cli, NULL, "show", NULL, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, NULL);
cli_register_command(cli, c, "banana", cmd_show_banana, PRIVILEGE_UNPRIVILEGED, MODE_EXEC, "Show a banana");
c = cli_register_command(cli, NULL, "restart", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL);
cli_register_command(cli, c, "bgp", cmd_restart_bgp, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Restart BGP");
- c = cli_register_command(cli, NULL, "load", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL);
- cli_register_command(cli, c, "plugin", cmd_load_plugin, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Load a plugin");
+ c = cli_register_command(cli, NULL, "load", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, NULL);
+ cli_register_command(cli, c, "plugin", cmd_load_plugin, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Load a plugin");
- c = cli_register_command(cli, NULL, "remove", NULL, PRIVILEGE_PRIVILEGED, MODE_EXEC, NULL);
- cli_register_command(cli, c, "plugin", cmd_remove_plugin, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Remove a plugin");
+ c = cli_register_command(cli, NULL, "remove", NULL, PRIVILEGE_PRIVILEGED, MODE_CONFIG, NULL);
+ cli_register_command(cli, c, "plugin", cmd_remove_plugin, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Remove a plugin");
- cli_register_command(cli, NULL, "set", cmd_set, PRIVILEGE_PRIVILEGED, MODE_EXEC, "Set a configuration variable");
+ cli_register_command(cli, NULL, "set", cmd_set, PRIVILEGE_PRIVILEGED, MODE_CONFIG, "Set a configuration variable");
// Enable regular processing
cli_regular(cli, regular_stuff);
}
else
{
- cli_allow_user(cli, buf, p);
- log(3, 0, 0, 0, "Allowing user %s to connect to the CLI\n", buf);
- }
+ cli_allow_user(cli, buf, p);
+ log(3, 0, 0, 0, "Allowing user %s to connect to the CLI\n", buf);
+ }
}
fclose(f);
}
{
log(3, 0, 0, 0, "Reading configuration file\n");
cli_print_callback(cli, cli_print_log);
- cli_file(cli, fh, PRIVILEGE_PRIVILEGED);
+ cli_file(cli, fh, PRIVILEGE_PRIVILEGED, MODE_CONFIG);
cli_print_callback(cli, NULL);
}
int cmd_show_session(struct cli_def *cli, char *command, char **argv, int argc)
{
int i;
- time_t time_now;
if (CLI_HELP_REQUESTED)
return cli_arg_help(cli, 1,
(unsigned long)session[i].total_cout,
(unsigned long)session[i].total_cin,
abs(time_now - (session[i].last_packet ? session[i].last_packet : time_now)),
- tunnelip,
+ tunnelip,
session[i].calling[0] ? session[i].calling : "*");
if (userip) free(userip);
if (tunnelip) free(tunnelip);
int cmd_show_tunnels(struct cli_def *cli, char *command, char **argv, int argc)
{
int i, x, show_all = 0;
- time_t time_now;
char *states[] = {
"Free",
"Open",
}
// Show tunnel summary
- cli_print(cli, "%s %s %s %s %s",
+ cli_print(cli, "%4s %20s %20s %6s %s",
"TID",
"Hostname",
"IP",
if (!show_all && (!tunnel[i].ip || tunnel[i].die || !tunnel[i].hostname[0])) continue;
for (x = 0; x < MAXSESSION; x++) if (session[x].tunnel == i && session[x].opened && !session[x].die) sessions++;
- cli_print(cli, "%d %s %s %s %d",
+ cli_print(cli, "%4d %20s %20s %6s %6d",
i,
*tunnel[i].hostname ? tunnel[i].hostname : "(null)",
inet_toa(htonl(tunnel[i].ip)),
{
int i;
int used = 0, free = 0, show_all = 0;
- time_t time_now;
if (!config->cluster_iam_master)
{
int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc)
{
+ int i, free = 0, used = 0, show_all = 0;
char *states[] = {
"NULL",
"CHAP",
"STOP",
"WAIT",
};
- int i, free = 0, used = 0, show_all = 0;
- time_t time_now;
if (CLI_HELP_REQUESTED)
{
if (!config->cluster_iam_master)
{
- cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
+ cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
return CLI_OK;
}
+
if (!argc)
{
cli_print(cli, "Specify a user to drop");
if (!config->cluster_iam_master)
{
- cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
+ cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
return CLI_OK;
}
+
if (!argc)
{
cli_print(cli, "Specify a tunnel to drop");
if (!config->cluster_iam_master)
{
- cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
+ cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
return CLI_OK;
}
+
if (!argc)
{
cli_print(cli, "Specify a session id to drop");
if (!config->cluster_iam_master)
{
- cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
+ cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
return CLI_OK;
}
if (!config->cluster_iam_master)
{
- cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
+ cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
return CLI_OK;
}
+
if (!argc)
{
cli_print(cli, "Specify a user");
else
cli_print(cli, "Throttling user %s", argv[i]);
}
+
return CLI_OK;
}
if (!config->cluster_iam_master)
{
- cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
+ cli_print(cli, "Can't do this on a slave. Do it on %s", inet_toa(config->cluster_master_address));
return CLI_OK;
}
+
if (!argc)
{
cli_print(cli, "Specify a user");
{
char *p = (char *) &debug_flags;
for (i = 0; i < sizeof(debug_flags); i++)
- {
- if (p[i])
{
+ if (p[i])
+ {
cli_print(cli, "Currently debugging:%s%s%s%s%s%s",
(debug_flags.critical) ? " critical" : "",
(debug_flags.error) ? " error" : "",
(debug_flags.calls) ? " calls" : "",
(debug_flags.data) ? " data" : "");
- return CLI_OK;
+ return CLI_OK;
+ }
}
- }
cli_print(cli, "Debugging off");
return CLI_OK;
FILE *fh;
char buf[100], *p = buf, *loads[3];
int i, num_sessions = 0;
- time_t time_now;
if (CLI_HELP_REQUESTED)
return CLI_HELP_NO_ARGS;