Added service management

This commit is contained in:
Illia Chub 2021-08-20 17:59:12 +03:00
parent 0980039a67
commit b9093f041b
4 changed files with 185 additions and 0 deletions

0
.gitignore vendored Normal file → Executable file
View file

185
main.py Normal file → Executable file
View file

@ -171,6 +171,191 @@ def enableSSH():
status=0
)
@app.route("/services/bitwarden/enable")
def enableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/passmgr/bitwarden.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/passmgr/bitwarden.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = false;", "enable = true;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
# Bitwarden
@app.route("/services/bitwarden/disable")
def disableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/passmgr/bitwarden.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/passmgr/bitwarden.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = true;", "enable = false;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
@app.route("/services/bitwarden/enable")
def enableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/passmgr/bitwarden.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/passmgr/bitwarden.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = false;", "enable = true;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
#Gitea
@app.route("/services/gitea/disable")
def disableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/git/gitea.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/git/gitea.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = true;", "enable = false;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
@app.route("/services/gitea/enable")
def enableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/git/gitea.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/git/gitea.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = false;", "enable = true;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
#Nextcloud
@app.route("/services/nextcloud/disable")
def disableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/nextcloud/nextcloud.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/nextcloud/nextcloud.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = true;", "enable = false;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
@app.route("/services/nextcloud/enable")
def enableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/nextcloud/nextcloud.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/nextcloud/nextcloud.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = false;", "enable = true;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
#Pleroma
@app.route("/services/pleroma/disable")
def disableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/social/pleroma.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/social/pleroma.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = true;", "enable = false;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
@app.route("/services/pleroma/enable")
def enableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/social/pleroma.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/social/pleroma.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = false;", "enable = true;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
#Ocserv
@app.route("/services/ocserv/disable")
def disableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/vpn/ocserv.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/vpn/ocserv.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = true;", "enable = false;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
@app.route("/services/ocserv/enable")
def enableBitwarden():
readOnlyFileDescriptor = open("/etc/nixos/vpn/ocserv.nix", "rt")
readWriteFileDescriptor = open("/etc/nixos/vpn/ocserv.nix", "wt")
for line in readOnlyFileDescriptor:
readWriteFileDescriptor.write(line.replace("enable = false;", "enable = true;"))
readWriteFileDescriptor.close()
readOnlyFileDescriptor.close()
return jsonify(
status=0
)
if __name__ == '__main__':
app.run(port=5050, debug=False)

0
requirements.txt Normal file → Executable file
View file

0
setup.py Normal file → Executable file
View file