Example #1
0
 def post(self):
     head = request.headers
     if head.get('Content-Type').startswith("application/json"):
         data = request.get_json()["certificate"]
         if data.get("is_acme"):
             certs = certificates.get()
             for x in certs:
                 if x.domain == data["domain"] and x.is_acme:
                     emsg = ("You can only have one ACME certificate at a "
                             "time for this domain.")
                     return jsonify(errors={"msg": emsg}), 422
             id = as_job(self._request_acme, data)
             return job_response(
                 id, data={"certificate": {"id": data["id"]}})
         else:
             id = as_job(self._generate, data)
             return job_response(
                 id, data={"certificate": {"id": data["id"]}})
     elif head.get('Content-Type').startswith("multipart/form-data"):
         name = request.form.get("id")
         files = [
             request.files.get("file[0]").read(),
             request.files.get("file[1]").read(),
             request.files.get("file[2]").read()
             if request.files.get("file[2]") else None]
         id = as_job(self._upload, name, files)
         return job_response(id)
     else:
         abort(400)
Example #2
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)
Example #3
0
 def put(self, id, time):
     data = request.get_json().get("backup")
     data["id"] = id + "/" + time
     if id and time and data:
         id = as_job(self._put, data)
         return job_response(id, data={"backup": data})
     else:
         abort(404)
Example #4
0
 def post(self):
     install, remove = [], []
     data = request.get_json()["packages"]
     for x in data:
         if x["operation"] == "install":
             install.append(x["id"])
         elif x["operation"] == "remove":
             remove.append(x["id"])
     id = as_job(self._operation, install, remove)
     return job_response(id)
Example #5
0
 def put(self, id):
     operation = request.get_json()["app"]["operation"]
     app = applications.get(id)
     if not app:
         abort(404)
     if operation == "install":
         if app.installed and not getattr(app, "upgradable", None):
             return jsonify(app=app.serialized)
         id = as_job(self._install, app)
     elif operation == "uninstall":
         if not app.installed:
             resp = jsonify(message="Application isn't yet installed")
             resp.status_code = 422
             return resp
         id = as_job(self._uninstall, app)
     else:
         return jsonify(errors={"msg": "Unknown operation"}), 422
     data = app.serialized
     data["is_ready"] = False
     return job_response(id, {"app": data})
Example #6
0
 def post(self, id, time):
     data = request.get_json()["backup"]
     id = as_job(self._post, data)
     return job_response(id)
Example #7
0
 def delete(self, id):
     id = as_job(self._delete, id, success_code=204)
     return job_response(id)
Example #8
0
 def post(self):
     data = request.get_json()["website"]
     id = as_job(self._post, data)
     return job_response(id)
Example #9
0
 def post(self):
     data = request.get_json()["filesystem"]
     id = as_job(self._post, data)
     return job_response(id, data={"filesystem": data})