/* * Mausezahn - A fast versatile traffic generator * Copyright (C) 2008-2010 Herbert Haas * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License version 2 as published by the * Free Software Foundation. * * This program 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 * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html * */ #include "mz.h" #include "cli.h" #include "mops.h" #include "llist.h" struct cli_def *gcli; char mz_username[32]; char mz_password[32]; char mz_enable[32]; char mz_listen_addr[16]; int mz_port; struct mops *clipkt; // actual packet used by CLI thread int clidev; int cli_debug; void mz_cli_init(void) { amp_head = automops_init(); // Initialize default credentials (will be overwritten by mausezahn.conf) strcpy(mz_username, MZ_DEFAULT_USERNAME); strcpy(mz_password, MZ_DEFAULT_PASSWORD); strcpy(mz_enable, MZ_DEFAULT_ENABLE_PASSWORD); // read login credentials from config file if (cli_read_cfg("mausezahn.conf")) { fprintf(stderr, "mz: Problems opening config file. Will use defaults\n"); } if ((verbose) && (AUTOMOPS_ENABLED)) { automops_dump_all(amp_head); fprintf(stderr, "------------ MOPS/CLI initialization completed ------------\n"); } } // Read in configuration file int cli_read_cfg(char *str) { char filename[256]; char line[256]; char path[256]; char *ampfile; char dev[256]; FILE *fd; int i, j=0, len, found=0, nonspc=0; int user=0, pass=0, ena=0, amp=0, mgmt_only=0, cli=0, port=0, addr=0; strncpy(filename, str, 255); if (getfullpath_cfg(filename)) return 1; if (verbose) { fprintf(stderr, "Opening config file %s...\n", filename); } fd = fopen (filename, "r"); if (fd==NULL) return 1; while (fgets(line, 255, fd) != NULL) { len=strnlen(line, 255); // Take string left side of # (comments) if (len) for(i=0;i