From fc6a393766ad18e53c7c0eaa22a664e6fb2d272a Mon Sep 17 00:00:00 2001 From: Bob Mottram <bob@freedombone.net> Date: Wed, 22 Aug 2018 12:27:39 +0100 Subject: [PATCH] Allow gogs registrations via web UI --- src/freedombone-app-gogs | 16 +++ webadmin/EN/settings_gogs_registration.html | 105 ++++++++++++++++++++ webadmin/settings_gogs.php | 18 ++++ 3 files changed, 139 insertions(+) create mode 100644 webadmin/EN/settings_gogs_registration.html create mode 100755 webadmin/settings_gogs.php diff --git a/src/freedombone-app-gogs b/src/freedombone-app-gogs index 6fee6785f..3e498d9b1 100755 --- a/src/freedombone-app-gogs +++ b/src/freedombone-app-gogs @@ -53,6 +53,22 @@ gogs_variables=(ONION_ONLY DDNS_PROVIDER ARCHITECTURE) +function gogs_setting_registration { + allow_registrations="$1" + + if [[ "$allow_registrations" == '1' ]]; then + sed -i "s|DISABLE_REGISTRATION =.*|DISABLE_REGISTRATION = false|g" /home/gogs/custom/conf/app.ini + sed -i "s|SHOW_REGISTRATION_BUTTON =.*|SHOW_REGISTRATION_BUTTON = true|g" /home/gogs/custom/conf/app.ini + systemctl restart gogs + fi + + if [[ "$allow_registrations" == '0' ]]; then + sed -i "s|DISABLE_REGISTRATION =.*|DISABLE_REGISTRATION = true|g" /home/gogs/custom/conf/app.ini + sed -i "s|SHOW_REGISTRATION_BUTTON =.*|SHOW_REGISTRATION_BUTTON = false|g" /home/gogs/custom/conf/app.ini + systemctl restart gogs + fi +} + function logging_on_gogs { echo -n '' } diff --git a/webadmin/EN/settings_gogs_registration.html b/webadmin/EN/settings_gogs_registration.html new file mode 100644 index 000000000..38ab47ef6 --- /dev/null +++ b/webadmin/EN/settings_gogs_registration.html @@ -0,0 +1,105 @@ +<!DOCTYPE html> +<html> + <style> + * { + box-sizing: border-box; + } + + a, u { + text-decoration: none; + color: #72a7cf; + font-weight: bold; + } + + a:visited{ + color: #72a7cf; + font-weight: bold; + } + + #headerpic { + width: 60%; + height: auto; + margin-right : auto; + margin-left : auto; + min-width : 220px; + } + + body { + margin: 0; + font-family: Arial; + } + + .header { + text-align: center; + padding: 32px; + } + + .headertext { + color: #72a7cf; + text-align: center; + font-size: 120%; + font-weight: bold; + } + .settingtext { + text-align: center; + font-size: 100%; + } + + .row { + display: -ms-flexbox; + display: flex; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + padding: 0 4px; + } + + .column { + -ms-flex: 25%; + flex: 15%; + max-width: 25%; + padding: 0 4px; + } + + .column img { + margin-top: 8px; + vertical-align: middle; + } + + .card { + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); + max-width: 600px; + margin: auto; + text-align: center; + font-family: arial; + clear: both; + } + + .card input[type=text] { + width: 50%; + clear: both; + text-align: left; + color: black; + background-color: lightblue; + } + + </style> + <body> + + <div class="card"> + <div class="header"> + <a href="app_gogs.html"><img id="headerpic" class="img-responsive" src="images/logo.png"></a> + + <p class="headertext">Gogs allow new registrations</p> + + <form action="settings_gogs.php" method="post"> + <input type="radio" name="allowregistrations" value="0" checked>No + <input type="radio" name="allowregistrations" value="1">Yes + <br><br> + <input type="submit" name="submitallowregistrations" value="Update" /> + </form> + + </div> + </div> + + </body> +</html> diff --git a/webadmin/settings_gogs.php b/webadmin/settings_gogs.php new file mode 100755 index 000000000..1fd33dffa --- /dev/null +++ b/webadmin/settings_gogs.php @@ -0,0 +1,18 @@ +<?php + +// Gogs settings menu + +$output_filename = "app_gogs.html"; + +if (isset($_POST['submitallowregistrations'])) { + $confirm = htmlspecialchars($_POST['allowregistrations']); + $settings_file = fopen(".appsettings.txt", "w") or die("Unable to write to appsettings file"); + fwrite($settings_file, "gogs,registration,".$confirm); + fclose($settings_file); +} + +$htmlfile = fopen("$output_filename", "r") or die("Unable to open $output_filename"); +echo fread($htmlfile,filesize("$output_filename")); +fclose($htmlfile); + +?> -- GitLab