Example #1
0
	def actionSiteList(self, to):
		ret = []
		SiteManager.load() # Reload sites
		for site in self.server.sites.values():
			if not site.content: continue # Broken site
			ret.append(self.formatSiteInfo(site))
		self.response(to, ret)
Example #2
0
	def actionSiteDelete(self, to, address):
		site = self.server.sites.get(address)
		if site:
			site.settings["serving"] = False
			site.saveSettings()
			site.worker_manager.running = False
			site.worker_manager.stopWorkers()
			site.deleteFiles()
			SiteManager.delete(address)
			site.updateWebsocket()
		else:
			self.response(to, {"error": "Unknown site: %s" % address})
Example #3
0
	def __init__(self):
		self.ip = config.fileserver_ip
		self.port = config.fileserver_port
		self.log = logging.getLogger(__name__)
		if config.ip_external: # Ip external definied in arguments
			self.port_opened = True
			SiteManager.peer_blacklist.append((config.ip_external, self.port)) # Add myself to peer blacklist
		else:
			self.port_opened = None # Is file server opened on router
		self.sites = SiteManager.list()
Example #4
0
    def __init__(self):
        self.ip = config.ui_ip
        self.port = config.ui_port
        if self.ip == "*": self.ip = ""  # Bind all
        #self.sidebar_websockets = [] # Sidebar websocket connections
        #self.auth_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(12)) # Global admin auth key
        self.sites = SiteManager.list()
        self.log = logging.getLogger(__name__)

        self.ui_request = UiRequest(self)
Example #5
0
    def actionWrapper(self, path):
        if "." in path and not path.endswith(".html"):
            return self.actionSiteMedia(
                "/media" + path)  # Only serve html files with frame
        if self.env.get("HTTP_X_REQUESTED_WITH"):
            return self.error403()  # No ajax allowed on wrapper

        match = re.match("/(?P<site>[A-Za-z0-9]+)(?P<inner_path>/.*|$)", path)
        if match:
            inner_path = match.group("inner_path").lstrip("/")
            if not inner_path:
                inner_path = "index.html"  # If inner path defaults to index.html

            site = self.server.sites.get(match.group("site"))
            if site and site.content and (
                    not site.bad_files
                    or site.settings["own"]):  # Its downloaded or own
                title = site.content["title"]
            else:
                title = "Loading %s..." % match.group("site")
                site = SiteManager.need(
                    match.group("site"))  # Start download site
                if not site: self.error404()

            self.sendHeader(extra_headers=[("X-Frame-Options", "DENY")])

            # Wrapper variable inits
            if self.env.get("QUERY_STRING"):
                query_string = "?" + self.env["QUERY_STRING"]
            else:
                query_string = ""
            body_style = ""
            if site.content and site.content.get("background-color"):
                body_style += "background-color: " + site.content[
                    "background-color"] + ";"

            return self.render(
                "src/Ui/template/wrapper.html",
                inner_path=inner_path,
                address=match.group("site"),
                title=title,
                body_style=body_style,
                query_string=query_string,
                wrapper_key=site.settings["wrapper_key"],
                permissions=json.dumps(site.settings["permissions"]),
                show_loadingscreen=json.dumps(
                    not os.path.isfile(site.getPath(inner_path))),
                homepage=config.homepage)

        else:  # Bad url
            return self.error404(path)
Example #6
0
    def actionSiteMedia(self, path):
        path = path.replace("/index.html/",
                            "/")  # Base Backward compatibility fix

        match = re.match("/media/(?P<site>[A-Za-z0-9]+)/(?P<inner_path>.*)",
                         path)

        referer = self.env.get("HTTP_REFERER")
        if referer:  # Only allow same site to receive media
            referer = re.sub("http://.*?/", "/",
                             referer)  # Remove server address
            referer = referer.replace("/media", "")  # Media
            if not referer.startswith("/" + match.group("site")):
                return self.error403(
                )  # Referer not starts same address as requested path

        if match:  # Looks like a valid path
            file_path = "data/%s/%s" % (match.group("site"),
                                        match.group("inner_path"))
            allowed_dir = os.path.abspath(
                "data/%s" %
                match.group("site"))  # Only files within data/sitehash allowed
            if ".." in file_path or not os.path.dirname(
                    os.path.abspath(file_path)).startswith(
                        allowed_dir):  # File not in allowed path
                return self.error403()
            else:
                if config.debug and file_path.split("/")[-1].startswith(
                        "all."
                ):  # When debugging merge *.css to all.css and *.js to all.js
                    site = self.server.sites.get(match.group("site"))
                    if site.settings["own"]:
                        from Debug import DebugMedia
                        DebugMedia.merge(file_path)
                if os.path.isfile(file_path):  # File exits
                    return self.actionFile(file_path)
                else:  # File not exits, try to download
                    site = SiteManager.need(match.group("site"),
                                            all_file=False)
                    self.sendHeader(content_type=self.getContentType(
                        file_path))  # ?? Get Exception without this
                    result = site.needFile(
                        match.group("inner_path"),
                        priority=1)  # Wait until file downloads
                    return self.actionFile(file_path)

        else:  # Bad url
            return self.error404(path)
Example #7
0
 def __init__(self, server=None):
     if server:
         self.server = server
         self.log = server.log
     self.sites = SiteManager.list()