]> git.stg.codes - stg.git/blob - projects/stargazer/plugins/configuration/sgconfig2/net_configurator.cpp
Base plugin structure implemented for SNMP Agent plugin
[stg.git] / projects / stargazer / plugins / configuration / sgconfig2 / net_configurator.cpp
1 #include <unistd.h>
2 #include "net_configurator.h"
3 #include "../../internal_configurator.h"
4
5 //-----------------------------------------------------------------------------
6 const string & NET_CONFIGURATOR_SETTINGS::GetStrError()
7 {
8 return strError;
9 }
10 //-----------------------------------------------------------------------------
11 int NET_CONFIGURATOR_SETTINGS::ReadSettings(const CONFIGFILE &cf)
12 {
13 if (cf.ReadUShortInt("AdminPort", &port, 5555) != 0)
14     {
15     strError = "Cannot read parameter AdminPort.";
16     return -1;
17     }
18 if (port < 1 || port > 65535)
19     {
20     strError = "Incorrect value AdminPort.";
21     return -1;
22     }
23
24 string strOrder;
25 cf.ReadString("AdminOrder", &strOrder, "allow,deny");
26 if (hostAllow.ParseOrder(strOrder.c_str()) < 0)
27     {
28     strError = string("Error in parameter AdminOrder. ") + hostAllow.GetStrError();
29     return -1;
30     }
31
32 string strAllow;
33 cf.ReadString("AdminAllowFrom", &strAllow, "all");
34 if (hostAllow.ParseHosts(strAllow.c_str(), hostsAllow) != 0)
35     {
36     strError = string("Error in parameter AdminAllowFrom. ") + hostAllow.GetStrError();
37     return -1;
38     }
39
40 string strDeny;
41 cf.ReadString("AdminDenyFrom", &strDeny, "");
42 if (hostAllow.ParseHosts(strDeny.c_str(), hostsDeny) != 0)
43     {
44     strError = string("Error in parameter AdminDenyFrom. ") + hostAllow.GetStrError();
45     return -1;
46     }
47 return 0;
48 }
49 //-----------------------------------------------------------------------------
50 uint16_t NET_CONFIGURATOR_SETTINGS::GetPort()
51 {
52 return port;
53 }
54 //-----------------------------------------------------------------------------
55 HOSTALLOW * NET_CONFIGURATOR_SETTINGS::GetHostAllow()
56 {
57 return &hostAllow;
58 }
59 //-----------------------------------------------------------------------------
60 //-----------------------------------------------------------------------------
61 //-----------------------------------------------------------------------------
62 NET_CONFIGURATOR::NET_CONFIGURATOR()
63 {
64 hostAllow = settings.GetHostAllow();
65 }
66 //-----------------------------------------------------------------------------
67 NET_CONFIGURATOR::~NET_CONFIGURATOR()
68 {
69
70 }
71 //-----------------------------------------------------------------------------
72 void NET_CONFIGURATOR::SetStgConfigurator(BASE_INT_CONFIGURATOR * bsc)
73 {
74 stgConfigurator = bsc;
75 cp.SetStgConfigurator(stgConfigurator);
76 }
77 //-----------------------------------------------------------------------------
78 int NET_CONFIGURATOR::UserGetAll(string * login, 
79                        USER_CONF_RES * conf,
80                        USER_STAT_RES * stat,
81                        time_t lastUpdate)
82 {
83 return 0;
84 }
85 //-----------------------------------------------------------------------------
86 int NET_CONFIGURATOR::TatiffGetAll(TARIFF_CONF * conf)
87 {
88 return 0;
89 }
90 //-----------------------------------------------------------------------------
91 int NET_CONFIGURATOR::AdminGetAll(ADMIN_CONF  * conf)
92 {
93 return 0;
94 }
95 //-----------------------------------------------------------------------------
96 const string & NET_CONFIGURATOR::GetStrError()
97 {
98 return strError;
99 }
100 //-----------------------------------------------------------------------------
101 void NET_CONFIGURATOR::Start()
102 {
103 cp.SetPort(settings.GetPort());
104 cp.SetHostAllow(settings.GetHostAllow());
105 cp.Start();
106 }
107 //-----------------------------------------------------------------------------
108 void NET_CONFIGURATOR::Stop()
109 {
110 cp.Stop();
111 }
112 //-----------------------------------------------------------------------------
113 void NET_CONFIGURATOR::Restart()
114 {
115 cp.Restart();
116 }
117 //-----------------------------------------------------------------------------
118 CONF_STATUS NET_CONFIGURATOR::Status()
119 {
120 return cp.Status();
121 }
122 //-----------------------------------------------------------------------------
123 BASE_SETTINGS * NET_CONFIGURATOR::GetConfiguratorSettings()
124 {
125 return &settings;
126 }
127 //-----------------------------------------------------------------------------
128 void NET_CONFIGURATOR::SetAdmins(const ADMINS * a)
129 {
130 cp.SetAdmins(a);
131 }
132 //-----------------------------------------------------------------------------
133