+ if (ip_address_pool[i].last)
+ cli_print(cli, "%-15s N %8s [%s] %ds",
+ inet_toa(ip_address_pool[i].address), "",
+ ip_address_pool[i].user, time_now - ip_address_pool[i].last);
+ else if (show_all)
+ cli_print(cli, "%-15s N", inet_toa(ip_address_pool[i].address));
+
+ free++;
+ }
+ }
+
+ if (!show_all)
+ cli_print(cli, "(Not displaying unused addresses)");
+
+ cli_print(cli, "\r\nFree: %d\r\nUsed: %d", free, used);
+ return CLI_OK;
+}
+
+void print_save_config(struct cli_def *cli, char *string)
+{
+ if (save_config_fh)
+ fprintf(save_config_fh, "%s\n", string);
+}
+
+int cmd_write_memory(struct cli_def *cli, char *command, char **argv, int argc)
+{
+ if ((save_config_fh = fopen(config->config_file, "w")))
+ {
+ cli_print(cli, "Writing configuration");
+ cli_print_callback(cli, print_save_config);
+ cmd_show_run(cli, command, argv, argc);
+ cli_print_callback(cli, NULL);
+ fclose(save_config_fh);
+ sleep(1);
+ }
+ else
+ {
+ cli_print(cli, "Error writing configuration: %s", strerror(errno));
+ }
+ return CLI_OK;
+}
+
+int cmd_show_run(struct cli_def *cli, char *command, char **argv, int argc)
+{
+ int i;
+
+ cli_print(cli, "# Current configuration:");
+
+ for (i = 0; config_values[i].key; i++)
+ {
+ void *value = ((void *)config) + config_values[i].offset;
+ if (config_values[i].type == STRING)
+ cli_print(cli, "set %s \"%.*s\"", config_values[i].key, config_values[i].size, (char *)value);
+ else if (config_values[i].type == IP)
+ cli_print(cli, "set %s %s", config_values[i].key, inet_toa(*(unsigned *)value));
+ else if (config_values[i].type == SHORT)
+ cli_print(cli, "set %s %hu", config_values[i].key, *(short *)value);
+ else if (config_values[i].type == BOOL)
+ cli_print(cli, "set %s %s", config_values[i].key, (*(int *)value) ? "yes" : "no");
+ else if (config_values[i].type == INT)
+ cli_print(cli, "set %s %d", config_values[i].key, *(int *)value);
+ else if (config_values[i].type == UNSIGNED_LONG)
+ cli_print(cli, "set %s %lu", config_values[i].key, *(unsigned long *)value);
+ }
+
+ cli_print(cli, "# Plugins");
+ for (i = 0; i < MAXPLUGINS; i++)
+ {
+ if (*config->plugins[i])
+ {
+ cli_print(cli, "load plugin \"%s\"", config->plugins[i]);
+ }
+ }
+
+ cli_print(cli, "# end");
+ return CLI_OK;
+}
+
+int cmd_show_radius(struct cli_def *cli, char *command, char **argv, int argc)
+{
+ char *states[] = {
+ "NULL",
+ "CHAP",
+ "AUTH",
+ "IPCP",
+ "START",
+ "STOP",
+ "WAIT",
+ };
+ int i, free = 0, used = 0, show_all = 0;
+ time_t time_now;
+
+ cli_print(cli, "%6s%5s%6s%9s%9s%4s", "Radius", "Sock", "State", "Session", "Retry", "Try");
+
+ time(&time_now);
+
+ if (argc > 0 && strcmp(argv[0], "all") == 0)
+ show_all = 1;
+
+ for (i = 1; i < MAXRADIUS; i++)
+ {
+ if (radius[i].state == RADIUSNULL)