diff --git a/src/freedombone-utils-webadmin b/src/freedombone-utils-webadmin index d7747b5f6be6e1a2cc67a013ed12416a2e3a535d..264716055511422314e5cb2ba7e0836d1e4b9415 100755 --- a/src/freedombone-utils-webadmin +++ b/src/freedombone-utils-webadmin @@ -47,6 +47,127 @@ function web_admin_avahi { systemctl restart avahi-daemon } +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" + appslist_add_filename="/var/www/${local_hostname}/htdocs/admin/apps_add.html" + icons_dir="/var/www/${local_hostname}/htdocs/admin/icons" + app_add_template_filename="app_add_template.html" + FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*" + + if [ ! -d "$icons_dir" ]; then + mkdir -p "$icons_dir" + fi + + if [ ! -f "$apps_add_template_filename" ]; then + return + fi + cp "$apps_add_template_filename" "$appslist_add_filename" + sed -i '/<\/body>/d' "$appslist_add_filename" + sed -i '/<\/html>/d' "$appslist_add_filename" + + available_apps_ctr=0 + app_index=0 + for filename in $FILES + do + app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') + + app_index=0 + app_is_installed= + # shellcheck disable=SC2068 + for a in ${APPS_INSTALLED[@]} + do + installed_app_name=${APPS_INSTALLED_NAMES[$app_index]} + if [[ "$installed_app_name" == "$app_name" ]]; then + app_is_installed=1 + break + fi + + app_index=$((app_index+1)) + done + + if [ ! $app_is_installed ]; then + app_filename="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}" + if [ -f "$app_filename" ]; then + # get the icon for the app + icon_filename="/usr/share/${PROJECT_NAME}/android-app/${app_name}.png" + if [ -f "$icon_filename" ]; then + cp "$icon_filename" "/var/www/${local_hostname}/htdocs/admin/icons/${app_name}.png" + else + icon_filename= + fi + + app_name_upper=$(echo "$app_name" | awk '{print toupper($0)}') + SHORT_DESCRIPTION= + DESCRIPTION= + + if ! grep -q "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then + app_index=$((app_index+1)) + continue + fi + if grep -q "#${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename"; then + app_index=$((app_index+1)) + continue + fi + SHORT_DESCRIPTION="$(grep "${app_name_upper}_SHORT_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')" + + if grep -q "${app_name_upper}_DESCRIPTION=" "$app_filename"; then + DESCRIPTION="$(grep "${app_name_upper}_DESCRIPTION=" "$app_filename" | head -n 1 | sed 's|\$||g' | sed "s|'||g" | sed 's|\"||g' | awk -F '=' '{print $2}')" + fi + + if [ $available_apps_ctr -eq 0 ]; then + echo ' <div class="row">' >> "$appslist_add_filename" + fi + + filename="/var/www/${local_hostname}/htdocs/admin/app_${app_name}.html" + if [ -f "$filename" ]; then + rm "$filename" + fi + + filename="/var/www/${local_hostname}/htdocs/admin/app_add_${app_name}.html" + + { echo ' <div class="column">'; + echo ' <div>'; + echo " <a href=\"app_${app_name}.html\">"; + echo " <img src=\"icons/${app_name}.png\" style=\"width:100%\">"; + echo " <center>${app_name}</center>"; + echo ' </a>'; + echo ' </div>'; + echo ' </div>'; } >> "$appslist_add_filename" + + cp "$app_add_template_filename" "$filename" + + # Replace app variables + sed -i "s|APPNAME|${app_name}|g" "$filename" + sed -i "s|APPDESCRIPTION|${DESCRIPTION}|g" "$filename" + + available_apps_ctr=$((available_apps_ctr+1)) + + # four columns per row + if [ $available_apps_ctr -eq 4 ]; then + echo ' </div>' >> "$appslist_add_filename" + available_apps_ctr=0 + fi + fi + fi + done + + # Complete the rest of the four column row + # shellcheck disable=SC2034 + for i in $(seq ${available_apps_ctr} 3) + do + { echo ' <div class="column">'; + echo ' <div>'; + echo ' </div>'; + echo ' </div>'; } >> "$appslist_add_filename" + done + + echo ' </body>' >> "$appslist_add_filename" + echo '</html>' >> "$appslist_add_filename" + + chown -R www-data:www-data "/var/www/${local_hostname}/htdocs/admin" +} + function web_admin_create_installed_apps { local_hostname=$(grep 'host-name' /etc/avahi/avahi-daemon.conf | awk -F '=' '{print $2}').local appslist_template_filename="/var/www/${local_hostname}/htdocs/admin/apps_template.html" @@ -269,6 +390,9 @@ function install_web_admin { mkdir -p "/var/www/${local_hostname}/htdocs/plinth" fi + # make list of apps which can be added + web_admin_create_add_apps + # make the list of apps web_admin_create_installed_apps diff --git a/webadmin/app_add_template.html b/webadmin/app_add_template.html new file mode 100644 index 0000000000000000000000000000000000000000..ff315eb0cbd16d981f774686e504bc79a29681c9 --- /dev/null +++ b/webadmin/app_add_template.html @@ -0,0 +1,71 @@ +<!DOCTYPE html> +<html> + <head> + <style> + .header { + text-align: center; + padding: 32px; + } + + #headerpic { + width: 20%; + height: auto; + margin-right : auto; + margin-left : auto; + min-width : 120px; + } + .card { + box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2); + max-width: 600px; + margin: auto; + text-align: center; + font-family: arial; + } + + .appurl { + color: grey; + font-size: 100%; + } + + .appdesc { + color: black; + font-size: 65%; + } + + button { + border: none; + outline: 0; + display: inline-block; + padding: 8px; + color: white; + background-color: #000; + text-align: center; + cursor: pointer; + width: 100%; + font-size: 18px; + } + + a { + text-decoration: none; + color: black; + } + + button:hover, a:hover { + opacity: 0.7; + } + </style> + </head> + <body> + + <div class="header"> + <a href="apps.html"><img id="headerpic" class="img-responsive" src="icons/APPNAME.png"></a> + </div> + + <div class="card"> + <h1>APPNAME</h1> + <p class="appdesc">APPDESCRIPTION</p> + <p><button>Add</button></p> + </div> + + </body> +</html> diff --git a/webadmin/apps_add_template.html b/webadmin/apps_add_template.html new file mode 100644 index 0000000000000000000000000000000000000000..4bfbad18ed73989e496103d8e1e8f59a1956057b --- /dev/null +++ b/webadmin/apps_add_template.html @@ -0,0 +1,80 @@ +<!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; + } + + .row { + display: -ms-flexbox; + display: flex; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + padding: 0 4px; + } + + .column { + -ms-flex: 25%; + flex: 25%; + max-width: 25%; + padding: 0 4px; + } + + .column img { + margin-top: 8px; + vertical-align: middle; + } + + @media screen and (max-width: 800px) { + .column { + -ms-flex: 50%; + flex: 50%; + max-width: 50%; + } + } + + @media screen and (max-width: 200px) { + .column { + -ms-flex: 100%; + flex: 100%; + max-width: 100%; + } + } + </style> + <body> + + <div class="header"> + <a href="index.html"><img id="headerpic" class="img-responsive" src="logo.png"></a> + </div> + + </body> +</html> diff --git a/webadmin/apps_template.html b/webadmin/apps_template.html index ca77463e57d6bd9d0d614a143a76338495fc3655..85e9b75502c3dc289276d992de39377d62f20b9d 100644 --- a/webadmin/apps_template.html +++ b/webadmin/apps_template.html @@ -94,7 +94,7 @@ <br> <div class="chip"> - <a href="app_add.html"> + <a href="apps_add.html"> + </a> </div> diff --git a/webadmin/users.html b/webadmin/users.html index 6535f2f04681a43a8e938395560eebe528580a23..3ff2e40299c5708c7a02d481162b4d739e77d12a 100644 --- a/webadmin/users.html +++ b/webadmin/users.html @@ -9,7 +9,6 @@ margin-right : auto; margin-left : auto; min-width : 220px; - max-width : 320px; } a, u { @@ -27,7 +26,9 @@ text-align: center; padding: 32px; font-size: 120%; + font-family: arial; font-weight: bold; + font-size: 170%; color: #72a7cf; } @@ -58,10 +59,6 @@ background-color: #f1f1f1; } - .adduser { - font-size: 200%; - } - .chip img { float: left; margin: 0 10px 0 -25px; @@ -100,12 +97,10 @@ </a> </div> <div class="chip"> - <div class="adduser"> - <a href="newuser.html"> - <img src="admin_users.png" alt="Person" width="96" height="96"> - + - </a> - </div> + <a href="newuser.html"> + <img src="admin_users.png" alt="Person" width="96" height="96"> + + + </a> </div> </div> </div>