From 3d66fd41831959c9a96f87004919c6ac8bb50289 Mon Sep 17 00:00:00 2001 From: Bob Mottram <bob@freedombone.net> Date: Tue, 24 Jul 2018 22:12:10 +0100 Subject: [PATCH] Create users list within web admin --- src/freedombone-utils-webadmin | 72 ++++++++++++++++++++ webadmin/userprofile.html | 18 +++-- webadmin/{users.html => users_template.html} | 0 3 files changed, 85 insertions(+), 5 deletions(-) rename webadmin/{users.html => users_template.html} (100%) diff --git a/src/freedombone-utils-webadmin b/src/freedombone-utils-webadmin index 34f860677..ad9f1f539 100755 --- a/src/freedombone-utils-webadmin +++ b/src/freedombone-utils-webadmin @@ -47,6 +47,76 @@ function web_admin_avahi { systemctl restart avahi-daemon } +function web_admin_create_users { + ADMIN_USER=$(get_completion_param "Admin user") + local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local + users_file="/var/www/${local_hostname}/htdocs/admin/users.html" + cp "/var/www/${local_hostname}/htdocs/admin/users_template.html" "$users_file" + sed -i '/users list/,/end of users/d' "$users_file" + sed -i '/<\/body>/d' "$users_file" + sed -i '/<\/html>/d' "$users_file" + + echo " <div class=\"row\">" >> "$users_file" + echo " <div class=\"column\">" >> "$users_file" + + rm "/var/www/${local_hostname}/htdocs/admin/userprofile_"* + + for d in /home/*/ ; do + USERNAME=$(echo "$d" | awk -F '/' '{print $3}') + if [[ $(is_valid_user "$USERNAME") == "1" ]]; then + userfile="/var/www/${local_hostname}/htdocs/admin/userprofile_${USERNAME}.html" + useremail=${USERNAME}@${DEFAULT_DOMAIN_NAME} + GPG_ID=$(su -c "gpg --list-keys '$useremail'" - "$USERNAME" | sed -n '2p' | sed 's/^[ \t]*//') + if [ -f "/home/$USERNAME/.gnupg/gpg.conf" ]; then + if grep -q "default-key" "/home/$USERNAME/.gnupg/gpg.conf"; then + default_gpg_key=$(grep "default-key" "/home/$USERNAME/.gnupg/gpg.conf") + if [[ "$default_gpg_key" != *'#'* ]]; then + default_gpg_key=$(grep "default-key" "/home/$USERNAME/.gnupg/gpg.conf" | awk -F ' ' '{print $2}') + if [ ${#default_gpg_key} -gt 3 ]; then + GPG_ID=$(su -c "gpg --list-keys '$default_gpg_key'" - "$USERNAME" | sed -n '2p' | sed 's/^[ \t]*//') + fi + fi + fi + fi + pubkey_qrcode="/var/www/${local_hostname}/htdocs/admin/userprofile_${USERNAME}.png" + su -c "gpg --armor --export \"$GPG_ID\"" - "$USERNAME" | qrencode -t PNG -o "$pubkey_qrcode" + + { echo ' <div class="chip">'; + echo " <a href=\"userprofile_${USERNAME}.html\">"; + echo ' <img src="admin_users.png" alt="Person" width="96" height="96">'; + echo " $USERNAME"; + echo ' </a>'; + echo ' </div>'; } >> "$users_file" + + cp "/var/www/${local_hostname}/htdocs/admin/userprofile.html" "$userfile" + sed -i "s|USERNAME|${USERNAME}|g" "$userfile" + if [[ "$USERNAME" == "$ADMIN_USER" ]]; then + sed -i "s|USERTYPE|Admin|g" "$userfile" + else + sed -i "s|USERTYPE|User|g" "$userfile" + fi + sed -i "s|USEREMAIL|${useremail}|g" "$userfile" + sed -i "s|USERGPG|${GPG_ID}|g" "$userfile" + + chown www-data:www-data "$userfile" + chown www-data:www-data "$pubkey_qrcode" + fi + done + + { echo ' <div class="chip">'; + echo " <a href=\"newuser.html\">"; + echo ' <img src="admin_users.png" alt="Person" width="96" height="96">'; + echo ' +'; + echo ' </a>'; + echo ' </div>'; + echo ' </div>'; + echo ' </div>'; + echo ' </body>'; + echo '</html>'; } >> "$users_file" + + chown www-data:www-data "$users_file" +} + function web_admin_create_add_apps { local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local apps_add_template_filename="/var/www/${local_hostname}/htdocs/admin/apps_add_template.html" @@ -389,6 +459,8 @@ function install_web_admin { mkdir -p "/var/www/${local_hostname}/htdocs/plinth" fi + web_admin_create_users + # make list of apps which can be added web_admin_create_add_apps diff --git a/webadmin/userprofile.html b/webadmin/userprofile.html index ff84e9094..f6170debd 100644 --- a/webadmin/userprofile.html +++ b/webadmin/userprofile.html @@ -14,6 +14,13 @@ margin-left : auto; min-width : 220px; } + #qrcodepic { + width: 60%; + height: auto; + margin-right : auto; + margin-left : auto; + min-width : 220px; + } .card { box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); max-width: 600px; @@ -64,14 +71,15 @@ <body> <div class="header"> - <a href="index.html"><img id="headerpic" class="img-responsive" src="logo.png"></a> + <a href="index.html"><img id="headerpic" class="img-responsive" src="logo.png"/></a> </div> <div class="card"> - <h1>User Name</h1> - <p class="title">Admin</p> - <p class="email">Email/XMPP: username@h89h2fg34gf6d3h9fggf82fhfj9fh2fg2gfufj29f2gf2g.onion</p> - <p class="gpg">GPG: key</p> + <h1>USERNAME</h1> + <p class="title">USERTYPE</p> + <p class="email">Email/XMPP: USEREMAIL</p> + <p class="gpg">GPG: USERGPG</p> + <img id="qrcodepic" class="img-responsive" src="userprofile_USERNAME.png"/> <p><button>Change Password</button></p> <p><button>Remove</button></p> </div> diff --git a/webadmin/users.html b/webadmin/users_template.html similarity index 100% rename from webadmin/users.html rename to webadmin/users_template.html -- GitLab