|
|
|
1 |
#include "PluginManager.h" |
#include "PluginManager.h" |
2 |
|
|
3 |
#include "Logger.h" |
#include "Logger.h" |
5 |
#include "Common.h" |
#include "Common.h" |
6 |
#include "Util.h" |
#include "Util.h" |
7 |
|
|
8 |
|
|
9 |
|
#include "ProxyPlugin.h" |
10 |
#include "plugins/EchoPlugin.h" |
#include "plugins/EchoPlugin.h" |
11 |
#include "plugins/SpamPlugin.h" |
#include "plugins/SpamPlugin.h" |
12 |
#include "plugins/ShellExecPlugin.h" |
#include "plugins/ShellExecPlugin.h" |
17 |
#include "plugins/WeatherPlugin.h" |
#include "plugins/WeatherPlugin.h" |
18 |
#include "plugins/UrlTriggerPlugin.h" |
#include "plugins/UrlTriggerPlugin.h" |
19 |
|
|
20 |
|
#include "AccessManager.h" |
21 |
|
|
22 |
typedef std::map<std::string, Plugin*>::iterator MapIterator; |
typedef std::map<std::string, Plugin*>::iterator MapIterator; |
23 |
|
|
24 |
PluginManager::PluginManager() |
PluginManager::PluginManager() |
86 |
return 0; |
return 0; |
87 |
} |
} |
88 |
|
|
|
void PluginManager::LoadPlugins() |
|
|
{ |
|
|
/* |
|
|
|
|
|
static ShellExecPlugin wake("wake", "/usr/local/bin/wake", false, false); |
|
|
static ShellExecPlugin ping("ping", "nmap -sP 192.168.10.1-255 | grep appears | awk '{print $2}'", false,true); |
|
|
|
|
|
|
|
89 |
|
|
90 |
|
void PluginManager::DestroyPlugins() |
91 |
|
{ |
92 |
|
for (std::map<std::string,Plugin*>::iterator it=_plugins.begin(); it!=_plugins.end(); ++it) |
93 |
|
{ |
94 |
|
delete it->second; |
95 |
|
} |
96 |
|
_plugins.clear(); |
97 |
|
} |
98 |
|
|
99 |
static UrlTriggerPlugin urltrigger("tou", "http://t-hoerup.dk/test.php"); |
void PluginManager::LoadPlugins() |
100 |
*/ |
{ |
101 |
|
Logger::logMessage("-------- PluginList --------"); |
102 |
std::vector<Value> pluginlist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "plugin"); |
std::vector<Value> pluginlist = Common::instance()->GetConfigfile()->GetValues("smsdaemon", "plugin"); |
103 |
|
|
104 |
for (unsigned i=0; i<pluginlist.size(); i++) |
for (unsigned i=0; i<pluginlist.size(); i++) |
135 |
} |
} |
136 |
|
|
137 |
if (pl) |
if (pl) |
138 |
|
{ |
139 |
AddPlugin(pl); |
AddPlugin(pl); |
140 |
|
ParseCommonOptions(name,args); |
141 |
|
} |
142 |
else |
else |
143 |
Logger::logMessage( std::string("Unknown plugin: ")+name); |
Logger::logMessage( std::string("Unknown plugin: ")+name); |
144 |
|
|
145 |
} |
} |
146 |
|
|
147 |
|
|
|
|
|
148 |
for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it) |
for (MapIterator it = _plugins.begin(); it != _plugins.end(); ++it) |
149 |
{ |
{ |
150 |
Plugin* pl = (*it).second; |
Plugin* pl = (*it).second; |
153 |
} |
} |
154 |
} |
} |
155 |
|
|
156 |
void PluginManager::DestroyPlugins() |
void PluginManager::ParseCommonOptions(const std::string& pluginName, std::map<std::string,std::string>& args) |
157 |
{ |
{ |
158 |
|
if (args["privileged"] == "1") |
159 |
|
{ |
160 |
|
AccessManager::AddPrivPlugin(pluginName); |
161 |
|
} |
162 |
} |
} |
163 |
|
|
164 |
Plugin* PluginManager::GetPlugin(const std::string& pluginname) |
Plugin* PluginManager::GetPlugin(const std::string& pluginname) |
165 |
{ |
{ |
166 |
return _plugins[ pluginname ]; |
static ProxyPlugin proxy; |
167 |
|
|
168 |
|
std::map<std::string,Plugin*>::iterator it = _plugins.find(pluginname ); |
169 |
|
|
170 |
|
if (it != _plugins.end() ) |
171 |
|
{ |
172 |
|
proxy.SetPlugin(it->second); |
173 |
|
return &proxy; |
174 |
|
} |
175 |
|
else |
176 |
|
{ |
177 |
|
return 0; |
178 |
|
} |
179 |
} |
} |
180 |
|
|
181 |
|
|