summaryrefslogtreecommitdiffstats
path: root/module/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'module/plugins')
-rw-r--r--module/plugins/Hook.py4
-rw-r--r--module/plugins/Plugin.py2
-rw-r--r--module/plugins/hooks/MultiHome.py80
3 files changed, 83 insertions, 3 deletions
diff --git a/module/plugins/Hook.py b/module/plugins/Hook.py
index 41264e559..749dc7ff6 100644
--- a/module/plugins/Hook.py
+++ b/module/plugins/Hook.py
@@ -50,11 +50,11 @@ class Hook():
def getConfig(self, option):
""" gets config values """
- return self.plugin.getPlugin(self.__name__, option)
+ return self.config.getPlugin(self.__name__, option)
def setConfig(self, option, value):
""" sets config value """
- self.plugin.setPlugin(self.__name__, option, value)
+ self.config.setPlugin(self.__name__, option, value)
def coreReady(self):
pass
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py
index 25323f6ed..549caba22 100644
--- a/module/plugins/Plugin.py
+++ b/module/plugins/Plugin.py
@@ -81,7 +81,7 @@ class Plugin(object):
self.ocr = None # captcha reader instance
self.account = pyfile.m.core.accountManager.getAccountPlugin(self.__name__) # account handler instance
- if not self.account.canUse(): self.account = None
+ if self.account and not self.account.canUse(): self.account = None
if self.account:
self.req = self.account.getAccountRequest(self)
else:
diff --git a/module/plugins/hooks/MultiHome.py b/module/plugins/hooks/MultiHome.py
new file mode 100644
index 000000000..023a282bb
--- /dev/null
+++ b/module/plugins/hooks/MultiHome.py
@@ -0,0 +1,80 @@
+# -*- coding: utf-8 -*-
+
+"""
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License,
+ or (at your option) any later version.
+
+ 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/>.
+
+ @author: mkaay
+"""
+
+from module.plugins.Hook import Hook
+from time import time
+
+class MultiHome(Hook):
+ __name__ = "MultiHome"
+ __version__ = "0.1"
+ __description__ = """ip address changer"""
+ __config__ = [ ("activated", "bool", "Activated" , "True"),
+ ("interfaces", "str", "Interfaces" , "") ]
+ __author_name__ = ("mkaay")
+ __author_mail__ = ("mkaay@mkaay.de")
+
+ def setup(self):
+ self.register = {}
+ self.interfaces = []
+ self.parseInterfaces(self.getConfig("interfaces").split(";"))
+ if not self.interfaces:
+ self.parseInterfaces([self.config["general"]["download_interface"]])
+ self.setConfig("interfaces", self.toConfig())
+
+ def toConfig(self):
+ return ";".join([i.adress for i in self.interfaces])
+
+ def parseInterfaces(self, interfaces):
+ for interface in interfaces:
+ if not interface or str(interface).lower() == "none":
+ continue
+ self.interfaces.append(Interface(interface))
+
+ def coreReady(self):
+ requestFactory = self.core.requestFactory
+ oldGetRequest = requestFactory.getRequest
+ def getRequest(pluginName, account=None, type="HTTP"):
+ iface = self.bestInterface(pluginName, account)
+ iface.useFor(pluginName, account)
+ requestFactory.iface = iface.adress
+ return oldGetRequest(pluginName, account, type)
+ requestFactory.getRequest = getRequest
+
+ def bestInterface(self, pluginName, account):
+ best = None
+ for interface in self.interfaces:
+ if not best or interface.lastPluginAccess(pluginName, account) < best.lastPluginAccess(pluginName, account):
+ best = interface
+ return best
+
+class Interface(object):
+ def __init__(self, adress):
+ self.adress = adress
+ self.history = {}
+
+ def lastPluginAccess(self, pluginName, account):
+ if self.history.has_key((pluginName, account)):
+ return self.history[(pluginName, account)]
+ return 0
+
+ def useFor(self, pluginName, account):
+ self.history[(pluginName, account)] = time()
+
+ def __repr__(self):
+ return "<Interface - %s>" % self.adress