def cert(): """TLS Certificate commands.""" conns.connect() applications.scan(cry=False) certificates.scan() certificates.scan_authorities() websites.scan()
def initial_scans(): from arkos import applications, certificates, databases, websites, tracked_services applications.scan() certificates.scan() databases.scan() websites.scan() tracked_services.initialize()
def get(self, id): if request.args.get("rescan", None): websites.scan() sites = websites.get(id) if id and not sites: abort(404) if isinstance(sites, websites.Site): return jsonify(website=sites.serialized) else: return jsonify(websites=[x.serialized for x in sites])
def get(self, id): if request.args.get("rescan", None): websites.scan() sites = websites.get(id) if id and not sites: abort(404) if type(sites) == list: return jsonify(websites=[x.as_dict() for x in sites]) else: return jsonify(website=sites.as_dict())
def initial_scans(): """Setup initial scans for all arkOS objects.""" from arkos import applications, backup, certificates, databases, websites from arkos import tracked_services applications.scan(cry=False) backup.get() certificates.scan() databases.scan() websites.scan() tracked_services.initialize() if config.get("general", "enable_upnp"): tracked_services.initialize_upnp(tracked_services.get())
def restore(self, data): signals.emit("backups", "pre_restore", self) # Trigger pre-restore hook for the app/site self.pre_restore() # Extract all files in archive sitename = "" with tarfile.open(data["path"], "r:gz") as t: for x in t.getnames(): if x.startswith("etc/nginx/sites-available"): sitename = os.path.basename(x) t.extractall("/") # If it's a website that had a database, restore DB via SQL file too dbpasswd = "" if self.ctype == "site" and sitename: self.site = websites.get(sitename) if not self.site: websites.scan() self.site = websites.get(sitename) meta = ConfigParser.SafeConfigParser() meta.read(os.path.join(self.site.path, ".arkos")) if meta.get("website", "dbengine", None) and os.path.exists("/%s.sql"%sitename): dbmgr = databases.get_managers(meta.get("website", "dbengine")) if databases.get(sitename): databases.get(sitename).remove() db = dbmgr.add_db(sitename) with open("/%s.sql"%sitename, "r") as f: db.execute(f.read()) os.unlink("/%s.sql"%sitename) if dbmgr.meta.database_multiuser: dbpasswd = random_string()[0:16] if databases.get_user(sitename): databases.get_user(sitename).remove() db_user = dbmgr.add_user(sitename, dbpasswd) db_user.chperm("grant", db) # Trigger post-restore hook for the app/site if self.ctype == "site": self.post_restore(self.site, dbpasswd) self.site.nginx_enable() else: self.post_restore() signals.emit("backups", "post_restore", self) data["is_ready"] = True return data
def restore(self, backup, data=True, nthread=NotificationThread()): """ Restore an associated arkOS app backup. :param Backup backup: backup to restore :param bool data: Restore backed up data files too? :param NotificationThread nthread: notification thread to use :returns: ``Backup`` :rtype: dict """ nthread.title = "Restoring backup" # Trigger pre-restore hook for the app/site signals.emit("backups", "pre_restore", self) msg = "Running pre-restore for {0}...".format(backup["pid"]) nthread.update(Notification("info", "Backup", msg)) self.pre_restore() # Extract all files in archive sitename = "" nthread.update(Notification("info", "Backup", "Extracting files...")) with tarfile.open(backup["path"], "r:gz") as t: for x in t.getnames(): if x.startswith("etc/nginx/sites-available"): sitename = os.path.basename(x) t.extractall("/") # If it's a website that had a database, restore DB via SQL file too dbpasswd = "" if self.ctype == "site" and sitename: self.site = websites.get(sitename) if not self.site: websites.scan() self.site = websites.get(sitename) meta = configparser.SafeConfigParser() meta.read(os.path.join(self.site.path, ".arkos")) sql_path = "/{0}.sql".format(sitename) if meta.get("website", "dbengine", fallback=None) \ and os.path.exists(sql_path): nthread.update( Notification("info", "Backup", "Restoring database...")) dbmgr = databases.get_managers(meta.get("website", "dbengine")) if databases.get(sitename): databases.get(sitename).remove() db = dbmgr.add_db(sitename) with open(sql_path, "r") as f: db.execute(f.read()) os.unlink(sql_path) if dbmgr.meta.database_multiuser: dbpasswd = random_string(16) dbuser = databases.get_users(sitename) if dbuser: dbuser.remove() db_user = dbmgr.add_user(sitename, dbpasswd) db_user.chperm("grant", db) # Trigger post-restore hook for the app/site msg = "Running post-restore for {0}...".format(backup["pid"]) nthread.update(Notification("info", "Backup", msg)) if self.ctype == "site": self.post_restore(self.site, dbpasswd) self.site.nginx_enable() else: self.post_restore() signals.emit("backups", "post_restore", self) backup["is_ready"] = True msg = "{0} restored successfully.".format(backup["pid"]) nthread.complete(Notification("info", "Backup", msg)) return backup
def site(): """Website commands""" conns.connect() applications.scan(cry=False) certificates.scan() websites.scan()