00001
00006 #include <iostream>
00007 #include <string.h>
00008 #include "include/generic.h"
00009 #include "include/plugins/Plugin.h"
00010 #include "include/plugins/AsteriskPlugin.h"
00011 #include "include/Debug.h"
00012 #include "include/Configuration.h"
00013 #include "include/Cli.h"
00014 #include "include/NetSniff.h"
00015
00016 #include <boost/bind.hpp>
00017 #include <boost/thread/thread.hpp>
00018
00019 using namespace std;
00020 using namespace plugins;
00021 using namespace network;
00022 using namespace boost;
00023 using namespace debug;
00024
00034 int main(int argc, const char* argv[]) {
00035
00036 string confFile;
00037 Debug dbg;
00038
00039 bool debug, debugcode;
00040
00041 if (argc < 2)
00042 {
00043 ostringstream err;
00044
00045 cout << "ERROR: You need to specify main config file path" << endl;
00046 cout << "Usage: " << argv[0];
00047 cout << " -conf main.conf" << endl;
00048 return -1;
00049 }
00050 else
00051 {
00052 cout << "Starting VoipHoney version " << VOIPHONEY_VER << endl;
00053
00054 for (int i=1; i < argc; i++)
00055 {
00056 if (strcmp(argv[i], "-conf") == 0)
00057 confFile = argv[++i];
00058 }
00059
00060
00061 const char* s[] = {"global", "plugins", "paths", "help"};
00062 const char* v[] = {"background", "debug", "use_sip", "use_plugins",
00063 "asterisk_plugin", "asterisk_conf_path", "verbosity", "sniff_sip",
00064 "sniff_device", "show_sniff", "capture_sniff", "capture_path",
00065 "helpcmdpath", "debugcode"};
00066 vector<string> sections(s, s + sizeof(s) / sizeof(const char*));
00067 vector<string> vars(v, v + sizeof(v) / sizeof(const char*));
00068
00069
00070 Configuration conf(confFile, &dbg, sections, vars);
00071
00072
00073 if (conf.GetValue("debug") == "yes")
00074 debug = true;
00075 else
00076 debug = false;
00077
00078 if (conf.GetValue("debugcode") == "yes")
00079 debugcode = true;
00080 else
00081 debugcode = false;
00082
00083 dbg.SetDebug(debug, debugcode);
00084 dbg.SetVerbosity(conf.GetValue("verbosity"));
00085 dbg.Prntdbg(CODEAT, 0, "Verbosity is now " + dbg.GetVerbosity());
00086 dbg.Prntdbg(CODEAT, 10, "Configuration Loaded ...");
00087 conf.LoadSysVars();
00088
00089
00090
00091
00092 string port = "5060";
00093 string sniffproto = "udp";
00094 NetSniff net(conf.GetValue("sniff_device"), port, sniffproto);
00095
00096
00097 net.setDebugger(&dbg);
00098
00099
00100 if (conf.GetValue("sniff_sip").compare("yes") == 0)
00101 {
00102 dbg.Prntdbg(CODEAT, 10, "Starting sniff process for " +
00103 conf.GetValue("sniff_device") + " device ..."
00104 );
00105
00106 if (net.Open())
00107 {
00108 if (net.ApplyFilter("default"))
00109 {
00110
00111 if (conf.GetValue("show_sniff").compare("yes") == 0)
00112 net.SetShow(true);
00113 else
00114 net.SetShow(false);
00115
00116 if (conf.GetValue("capture_sniff").compare("yes") == 0)
00117 net.SetCapture(true, conf.GetValue("capture_path"));
00118 else
00119 net.SetCapture(false, conf.GetValue("capture_path"));
00120
00121
00122 thread* sniffThread = new thread(bind(&network::NetSniff::startsniff,&net));
00123 if (sniffThread == NULL)
00124 dbg.Prnterr(CODEAT, "Error creating thread");
00125 }
00126 }
00127 else
00128 dbg.Prntdbg(CODEAT, 50, "Device open NOT possible. Check user permissions and sniff_device");
00129 }
00130
00131
00132 if (conf.GetValue("use_plugins").compare("yes") == 0)
00133 {
00134
00135 if (conf.GetValue("asterisk_plugin").compare("yes") == 0)
00136 {
00137 AsteriskPlugin ast;
00138 ast.SetDebugger(&dbg);
00139 ast.SetActive(true);
00140 ast.LoadConf(conf.GetValue("asterisk_conf_path"));
00141 }
00142 }
00143
00144
00145 if (conf.GetValue("background").compare("no") == 0)
00146 {
00147 Cli cli(conf, &net);
00148 if (cli.SetDebugger(&dbg))
00149 cli.MainLoop();
00150 }
00151 }
00152
00153
00154
00155 cout << "Finished ..." << endl;
00156 dbg.Prntdbg(CODEAT, 50, "Exit and return 0");
00157
00158 return 0;
00159
00160 }