int start_snmp( std::vector<std::string> & parameters, std::string & response ) { response = "SNMP process started"; stop_snmp( parameters, response ); ConfigVAR settings("/var/smoothwall/snmp/settings"); syslog(LOG_ERR, "starting accordingly"); if (settings["ENABLE"] == "on") { std::vector<std::string> args; args.push_back("/usr/sbin/snmpd"); args.push_back("-p"); args.push_back("/var/run/snmpd.pid"); args.push_back("-Ls"); args.push_back("daemon"); args.push_back("-u"); args.push_back("99"); args.push_back("-g"); args.push_back("99"); // ConfigCSV ipcsv("/var/smoothwall/red/local-ipaddress"); // std::string ip = ipcsv[0]; // if (ip != "") // args.push_back(ip); syslog(LOG_ERR, "SNMP enabled, starting accordingly"); simplesecuresystemvector(args); } return 0; }
int restart_snmp( std::vector<std::string> & parameters, std::string & response ) { int error = 0; error += stop_snmp( parameters, response ); if ( !error ) error += start_snmp( parameters, response ); if ( !error ) response = "SNMP restart successful"; return error; }
void start_snmp(void) { int ret = 0; pid_t pid; char *snmpd_argv[] = { "snmpd", "-c", SNMP_CONF_FILE, NULL }; FILE *fp = NULL; stop_snmp(); if (!nvram_invmatch("snmpd_enable", "0")) return; fp = fopen(SNMP_CONF_FILE, "w"); if (NULL == fp) return; if (strlen(nvram_safe_get("snmpd_syslocation")) > 0) fprintf(fp, "syslocation %s\n", nvram_safe_get("snmpd_syslocation")); if (strlen(nvram_safe_get("snmpd_syscontact")) > 0) fprintf(fp, "syscontact %s\n", nvram_safe_get("snmpd_syscontact")); if (strlen(nvram_safe_get("snmpd_sysname")) > 0) fprintf(fp, "sysname %s\n", nvram_safe_get("snmpd_sysname")); if (strlen(nvram_safe_get("snmpd_rocommunity")) > 0) fprintf(fp, "rocommunity %s\n", nvram_safe_get("snmpd_rocommunity")); if (strlen(nvram_safe_get("snmpd_rwcommunity")) > 0) fprintf(fp, "rwcommunity %s\n", nvram_safe_get("snmpd_rwcommunity")); fprintf(fp, "sysservices 9\n"); fprintf(fp, "pass_persist .1.3.6.1.4.1.2021.255 /etc/wl_snmpd.sh\n"); fclose(fp); ret = _evalpid(snmpd_argv, NULL, 0, &pid); cprintf("done\n"); dd_syslog(LOG_INFO, "snmpd : SNMP daemon successfully started\n"); return; }