Пример #1
0
 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)
Пример #2
0
def download(id):
    item = shared_files.get(id)
    if not item:
        abort(404)
    if item.is_expired:
        item.delete()
        return jsonify(errors={"msg": "The requested item has expired"}), 410
    if item.expires == 0:
        item.delete()
        remove_record("share", item.id)
    path = item.path
    item.fetch_count += 1
    if os.path.isdir(path):
        apath = compress(path, format="zip")
        with open(apath, "r") as f:
            data = f.read()
        resp = Response(data, mimetype="application/octet-stream")
        resp.headers["Content-Length"] = os.path.getsize(apath)
        resp.headers[
            "Content-Disposition"] = "attachment; filename={0}".format(
                os.path.basename(apath))
        return resp
    else:
        with open(path, "r") as f:
            data = f.read()
        resp = Response(data, mimetype="application/octet-stream")
        resp.headers["Content-Length"] = str(len(data))
        resp.headers[
            "Content-Disposition"] = "attachment; filename={0}".format(
                os.path.basename(path))
        return resp
Пример #3
0
 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)
Пример #4
0
 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
Пример #5
0
 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)
Пример #6
0
 def _delete(self, job, id):
     nthread = NotificationThread(id=job.id)
     site = websites.get(id)
     site.remove(nthread)
     remove_record("website", id)
     remove_record("policy", id)