Denis 1477 Posted August 5, 2014 Share Posted August 5, 2014 Hello, While i was surfing at the internet i saw something interesting. It's a python script which does this work: You can create a python file in your web space and import it import httplib import imp import sys def register_domain(name): WebImporter.registered_domains.add(name) parts = reversed(name.split('.')) whole = [] for part in parts: whole.append(part) WebImporter.domain_modules.add(".".join(whole)) class WebImporter(object): domain_modules = set() registered_domains = set() def find_module(self, fullname, path=None): if fullname in self.domain_modules: return self if fullname.rsplit('.')[0] not in self.domain_modules: return None try: r = self._do_request(fullname, method="HEAD") except ValueError: return None else: r.close() if r.status == 200: return self return None def load_module(self, fullname): if fullname in sys.modules: return sys.modules[fullname] mod = imp.new_module(fullname) mod.__loader__ = self sys.modules[fullname] = mod if fullname not in self.domain_modules: url = "http://%s%s" % self._get_host_and_path(fullname) mod.__file__ = url r = self._do_request(fullname) code = r.read() assert r.status == 200 exec code in mod.__dict__ else: mod.__file__ = "[fake module %r]" % fullname mod.__path__ = [] return mod def _do_request(self, fullname, method="GET"): host, path = self._get_host_and_path(fullname) c = httplib.HTTPConnection(host) c.request(method, path) return c.getresponse() def _get_host_and_path(self, fullname): tld, domain, rest = fullname.split('.', 2) path = "/%s.py" % rest.replace('.', '/') return ".".join([domain, tld]), path sys.meta_path = [WebImporter()] your_site = 'dowski.com' register_domain(your_site) from com.dowski import test print "Output from "+your_site+' foo: ', test.foo print "Output from "+your_site+' bar: ', test.bar Source: http://blog.dowski.com/2008/07/31/customizing-the-python-import-system/ 5 Link to comment Share on other sites More sharing options...
Night 367 Posted August 19, 2014 Share Posted August 19, 2014 yes i think this can be usefull for importing a hack from out of the client Link to comment Share on other sites More sharing options...
pySmith 4 Posted August 21, 2014 Share Posted August 21, 2014 Not good if you want to protect your files, they need to be stored in clear text to be executed. Link to comment Share on other sites More sharing options...
DasKuchen 11 Posted August 21, 2014 Share Posted August 21, 2014 Metin2 already defined a function for this i think in prototype.py or something. Link to comment Share on other sites More sharing options...
Recommended Posts