Merge branch 'master' of ssh://drmichael@scm.schwerkraft.elitedvb.net/scmrepos/git...
[enigma2-plugins.git] / webinterface / src / __init__.py
1 import Plugins.Plugin
2 from Components.Language import language
3 from Tools.Directories import resolveFilename, SCOPE_PLUGINS, SCOPE_LANGUAGE
4 import os, gettext, hashlib
5
6 __version__ = "1.7.5"
7
8 PluginLanguageDomain = "WebInterface"
9 PluginLanguagePath = "Extensions/WebInterface/locale"
10
11 def localeInit():
12         lang = language.getLanguage()[:2] # getLanguage returns e.g. "fi_FI" for "language_country"
13         os.environ["LANGUAGE"] = lang # Enigma doesn't set this (or LC_ALL, LC_MESSAGES, LANG). gettext needs it!
14         print "[WebInterface] set language to ", lang
15         gettext.bindtextdomain(PluginLanguageDomain, resolveFilename(SCOPE_PLUGINS, PluginLanguagePath))
16
17 def _(txt):
18         t = gettext.dgettext(PluginLanguageDomain, txt)
19         if t == txt:
20                 print "[WebInterface] fallback to default translation for", txt
21                 t = gettext.gettext(txt)
22         return t
23
24 def bin2long(s):
25         return reduce( lambda x,y:(x<<8L)+y, map(ord, s))
26
27 def long2bin(l):
28         res = ""
29         for byte in range(128):
30                 res += chr((l >> (1024 - (byte + 1) * 8)) & 0xff)
31         return res
32
33 def rsa_pub1024(src, mod):
34         return long2bin(pow(bin2long(src), 65537, bin2long(mod)))
35
36 def decrypt_block(src, mod):
37         if len(src) != 128 and len(src) != 202:
38                 return None
39         dest = rsa_pub1024(src[:128], mod)
40         hash = hashlib.sha1(dest[1:107])
41         if len(src) == 202:
42                 hash.update(src[131:192])
43         result = hash.digest()
44         if result == dest[107:127]:
45                 return dest
46         return None
47
48 localeInit()
49 language.addCallback(localeInit)