Skip to content
Snippets Groups Projects
Commit 3d66fd41 authored by Bob Mottram's avatar Bob Mottram
Browse files

Create users list within web admin

parent fb46e35d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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>
......
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment