def put(self, id): data = request.get_json()["website"] site = websites.get(id) if not site: abort(404) if data.get("operation") == "enable": site.nginx_enable() elif data.get("operation") == "disable": site.nginx_disable() elif data.get("operation") == "enable_ssl": cert = certificates.get(data["cert"]) cert.assign("website", site.id) elif data.get("operation") == "disable_ssl": site.cert.unassign("website", site.id) elif data.get("operation") == "update": id = as_job(self._put, site) return job_response( id, data={"website": site.serialized.update({"is_ready": False})}) else: site.domain = data["domain"] site.port = data["port"] site.edit(data.get("new_name")) if data.get("new_name"): remove_record("website", id) push_record("website", site.serialized) return jsonify(website=site.serialized)
def _request_acme(self, job, data): nthread = NotificationThread(id=job.id) try: cert = certificates.request_acme_certificate( data["domain"], nthread=nthread) except: remove_record("certificate", data["id"]) raise else: push_record("certificate", cert.serialized)
def _operation(self, job, install, remove): if install: try: pacman.refresh() prereqs = pacman.needs_for(install) upgr = (x["id"] for x in pacman.get_installed() if x.get("upgradable")) if sorted(upgr) == sorted(install): # Upgrade msg = "Performing system upgrade..." msg = Notification("info", "Packages", msg) nthread = NotificationThread(id=job.id, message=msg) pacman.upgrade() else: # Install title = "Installing {0} package(s)".format(len(prereqs)) msg = Notification("info", "Packages", ", ".join(prereqs)) nthread = NotificationThread(id=job.id, title=title, message=msg) pacman.install(install) for x in prereqs: try: info = process_info(pacman.get_info(x)) if "installed" not in info: info["installed"] = True push_record("package", info) except: pass except Exception as e: nthread.complete(Notification("error", "Packages", str(e))) return if remove: try: prereqs = pacman.depends_for(remove) title = "Removing {0} package(s)".format(len(prereqs)) msg = Notification("info", "Packages", ", ".join(prereqs)) nthread = NotificationThread(id=job.id, title=title, message=msg) pacman.remove(remove) for x in prereqs: try: info = process_info(pacman.get_info(x)) if "installed" not in info: info["installed"] = False push_record("package", info) except: pass except Exception as e: nthread.complete(Notification("error", "Packages", str(e))) return msg = "Operations completed successfully" nthread.complete(Notification("success", "Packages", msg))
def _post(self, job, data): nthread = NotificationThread(id=job.id) sapp = applications.get(data["app"]) site = sapp._website site = site(sapp, data["id"], data["domain"], data["port"]) try: specialmsg = site.install(data["extra_data"], True, nthread) if specialmsg: Notification("info", "Websites", specialmsg).send() push_record("website", site.serialized) except Exception as e: remove_record("website", data["id"]) raise
def _post(self, job, data): nthread = NotificationThread(id=job.id) disk = filesystems.VirtualDisk(id=data["id"], size=data["size"]) disk.create(will_crypt=data["crypt"], nthread=nthread) if data["crypt"]: try: msg = "Encrypting virtual disk..." nthread.update(Notification("info", "Filesystems", msg)) disk.encrypt(data["passwd"]) except Exception as e: disk.remove() raise msg = "Virtual disk created successfully" nthread.complete(Notification("success", "Filesystems", msg)) push_record("filesystem", disk.serialized)
def put(self, id): data = request.get_json()["certificate"] cert = certificates.get(id) other_certs = [x for x in certificates.get() if x.id != id] if not id or not cert: abort(404) for x in other_certs: for y in data["assigns"]: if y in x.assigns: x.unassign(y) push_record("certificate", x.serialized) for x in cert.assigns: if x not in data["assigns"]: cert.unassign(x) for x in data["assigns"]: if x not in cert.assigns: cert.assign(x) return jsonify(certificate=cert.serialized)
def _generate(self, job, data): nthread = NotificationThread(id=job.id) try: cert = certificates.generate_certificate( data["id"], data["domain"], data["country"], data["state"], data["locale"], data["email"], data["keytype"], data["keylength"], nthread=nthread) except: remove_record("certificate", data["id"]) raise else: push_record("certificate", cert.serialized) try: basehost = ".".join(data["domain"].split(".")[-2:]) ca = certificates.get_authorities(basehost) except: pass else: push_record("authority", ca.serialized)
def install(job, to_install): errors = False nthread = NotificationThread(id=job.id) nthread.title = "Setting up your server..." for x in to_install: a = applications.get(x) msg = "Installing {0}...".format(x) nthread.update(Notification("info", "FirstRun", msg)) try: a.install() push_record("app", a.serialized) except: errors = True if to_install: if errors: msg = ("One or more applications failed to install. " "Check the App Store pane for more information.") nthread.complete(Notification("warning", "FirstRun", msg)) else: msg = ("You may need to restart your device before " "changes will take effect.") nthread.complete(Notification("success", "FirstRun", msg))
def _upload(self, job, name, files): nthread = NotificationThread(id=job.id) cert = certificates.upload_certificate( name, files[0], files[1], files[2], nthread) push_record("certificate", cert.serialized)
def _put(self, job, data): nthread = NotificationThread(id=job.id) b = backup.restore(data, nthread=nthread) push_record("backup", b)
def _post(self, job, id): nthread = NotificationThread(id=job.id) b = backup.create(id, nthread=nthread) push_record("backups", b)
def _put(self, job, site): nthread = NotificationThread(id=job.id) site.update(nthread=nthread) push_record("website", site.serialized)
def _uninstall(self, job, app): nthread = NotificationThread(id=job.id) app.uninstall(nthread=nthread) push_record("app", app.serialized)
def _install(self, job, app): nthread = NotificationThread(id=job.id) app.install(nthread=nthread, force=True, cry=False) push_record("app", app.serialized)