瀏覽代碼

Login for tahoelafs client

Bob Mottram 8 年之前
父節點
當前提交
6e12e97109
共有 1 個檔案被更改,包括 46 行新增1 行删除
  1. 46
    1
      src/freedombone-app-tahoelafs

+ 46
- 1
src/freedombone-app-tahoelafs 查看文件

58
                      TAHOELAFS_SHARES_HAPPY
58
                      TAHOELAFS_SHARES_HAPPY
59
                      TAHOELAFS_SHARES_TOTAL)
59
                      TAHOELAFS_SHARES_TOTAL)
60
 
60
 
61
+function add_user_tahoelafs {
62
+    if [[ $(app_is_installed tahoelafs) == "0" ]]; then
63
+        echo '0'
64
+        return
65
+    fi
66
+
67
+    new_username="$1"
68
+    new_user_password="$2"
69
+    ${PROJECT_NAME}-pass -u $new_username -a tahoelafs -p "$new_user_password"
70
+    if grep "${new_username}:" /etc/nginx/.htpasswd-tahoelafs; then
71
+        sed -i '/${new_username}:/d' /etc/nginx/.htpasswd-tahoelafs
72
+    fi
73
+    echo "${new_user_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${new_username}
74
+    echo '0'
75
+}
76
+
77
+function remove_user_tahoelafs {
78
+    remove_username="$1"
79
+    ${PROJECT_NAME}-pass -u $remove_username --rmapp tahoelafs
80
+    if grep "${remove_username}:" /etc/nginx/.htpasswd-tahoelafs; then
81
+        sed -i '/${remove_username}:/d' /etc/nginx/.htpasswd-tahoelafs
82
+    fi
83
+}
84
+
85
+function change_password_tahoelafs {
86
+    change_username="$1"
87
+    change_password="$2"
88
+    ${PROJECT_NAME}-pass -u $change_username -a tahoelafs -p "$change_password"
89
+    if grep "${change_username}:" /etc/nginx/.htpasswd-tahoelafs; then
90
+        sed -i '/tahoe-${change_username}:/d' /etc/nginx/.htpasswd-tahoelafs
91
+    fi
92
+    echo "${change_password}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${change_username}
93
+}
94
+
61
 function add_tahoelafs_storage_node_interactive {
95
 function add_tahoelafs_storage_node_interactive {
62
     data=$(tempfile 2>/dev/null)
96
     data=$(tempfile 2>/dev/null)
63
     trap "rm -f $data" 0 1 2 5 15
97
     trap "rm -f $data" 0 1 2 5 15
562
     echo "  root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
596
     echo "  root /var/www/tahoelafs/htdocs;" >> $tahoelafs_nginx_site
563
     echo '' >> $tahoelafs_nginx_site
597
     echo '' >> $tahoelafs_nginx_site
564
     echo '  location / {' >> $tahoelafs_nginx_site
598
     echo '  location / {' >> $tahoelafs_nginx_site
599
+    echo '    auth_basic $"Tahoe-LAFS login";' >> $tahoelafs_nginx_site
600
+    echo '    auth_basic_user_file /etc/nginx/.htpasswd-tahoelafs;' >> $tahoelafs_nginx_site
565
     function_check nginx_limits
601
     function_check nginx_limits
566
     nginx_limits tahoelafs '15m'
602
     nginx_limits tahoelafs '15m'
567
     echo '    rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
603
     echo '    rewrite /(.*) /$1 break;' >> $tahoelafs_nginx_site
574
     echo '  }' >> $tahoelafs_nginx_site
610
     echo '  }' >> $tahoelafs_nginx_site
575
     echo '}' >> $tahoelafs_nginx_site
611
     echo '}' >> $tahoelafs_nginx_site
576
 
612
 
613
+    TAHOELAFS_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
614
+    ${PROJECT_NAME}-pass -u $MY_USERNAME -a tahoelafs -p "$TAHOELAFS_ADMIN_PASSWORD"
615
+    if [ ! -f /etc/nginx/.htpasswd-tahoelafs ]; then
616
+        touch /etc/nginx/.htpasswd-tahoelafs
617
+    fi
618
+    if grep "${MY_USERNAME}:" /etc/nginx/.htpasswd-tahoelafs; then
619
+        sed -i '/${MY_USERNAME}:/d' /etc/nginx/.htpasswd-tahoelafs
620
+    fi
621
+    echo "${TAHOELAFS_ADMIN_PASSWORD}" | htpasswd -i -s /etc/nginx/.htpasswd-tahoelafs ${MY_USERNAME}
622
+
577
     function_check nginx_ensite
623
     function_check nginx_ensite
578
     nginx_ensite tahoelafs
624
     nginx_ensite tahoelafs
579
-
580
     systemctl reload nginx
625
     systemctl reload nginx
581
 }
626
 }
582
 
627