浏览代码

Hack to enable or disable turtl signups

Bob Mottram 8 年前
父节点
当前提交
d5c55a8824
共有 1 个文件被更改,包括 81 次插入1 次删除
  1. 81
    1
      src/freedombone-app-turtl

+ 81
- 1
src/freedombone-app-turtl 查看文件

@@ -46,6 +46,10 @@ TURTL_ADMIN_PASSWORD=
46 46
 TURTL_STORAGE_LIMIT_MB=100
47 47
 TURTL_BASE_DIR=/etc/turtl
48 48
 
49
+# part of a hack to enable/disable signups
50
+TURTL_SIGNUP_STRING='Signup a new user'
51
+turtl_users_file=$TURTL_BASE_DIR/api/controllers/users.lisp
52
+
49 53
 turtl_variables=(ONION_ONLY
50 54
                  DEFAULT_DOMAIN_NAME
51 55
                  TURTL_DOMAIN_NAME
@@ -85,7 +89,55 @@ function install_interactive_turtl {
85 89
     APP_INSTALLED=1
86 90
 }
87 91
 
88
-function configure_interactive_turtl {
92
+function turtl_disable_registrations {
93
+    if grep "$TURTL_SIGNUP_STRING" $turtl_users_file; then
94
+        if [ -f $turtl_users_file ]; then
95
+            cp $turtl_users_file $TURTL_BASE_DIR/.users.lisp
96
+            sed -i '/(route (:post "\/users") (req res)/,/(send-json res user))))/{//!d}' $turtl_users_file
97
+            sed -i 's|(send-json res user))))|())|g' $turtl_users_file
98
+            chown -R turtl:turtl $TURTL_BASE_DIR
99
+            systemctl restart turtl
100
+        fi
101
+    fi
102
+}
103
+
104
+function turtl_enable_registrations {
105
+    if ! grep "$TURTL_SIGNUP_STRING" $turtl_users_file; then
106
+        if [ -f $TURTL_BASE_DIR/.users.lisp ]; then
107
+            cp $TURTL_BASE_DIR/.users.lisp $turtl_users_file
108
+            rm $TURTL_BASE_DIR/.users.lisp
109
+            chown -R turtl:turtl $TURTL_BASE_DIR
110
+            systemctl restart turtl
111
+        fi
112
+    fi
113
+}
114
+
115
+function configure_interactive_turtl_signups {
116
+    # This implements a hack which removes or adds the function needed
117
+    # to sign up new users. It should eventually be removed once that
118
+    # capability exists within the api
119
+
120
+    dialog --title $"Allow new turtl signups" \
121
+           --backtitle $"Freedombone Control Panel" \
122
+           --defaultno \
123
+           --yesno $"\nAllow registration of new users?" 10 60
124
+    sel=$?
125
+    case $sel in
126
+        0)
127
+            turtl_enable_registrations
128
+            dialog --title $"Allow new turtl signups" \
129
+                   --msgbox $"New turtl user registrations are now allowed" 6 40
130
+            return;;
131
+        1)
132
+            turtl_disable_registrations
133
+            dialog --title $"Disable new turtl signups" \
134
+                   --msgbox $"New turtl user registrations are now disabled" 6 40
135
+            return;;
136
+        255) return;;
137
+    esac
138
+}
139
+
140
+function configure_interactive_turtl_storage {
89 141
     data=$(tempfile 2>/dev/null)
90 142
     trap "rm -f $data" 0 1 2 5 15
91 143
     dialog --title $"Change storage limit" \
@@ -106,6 +158,26 @@ function configure_interactive_turtl {
106 158
     esac
107 159
 }
108 160
 
161
+function configure_interactive_turtl {
162
+    data=$(tempfile 2>/dev/null)
163
+    trap "rm -f $data" 0 1 2 5 15
164
+    dialog --backtitle $"Freedombone Control Panel" \
165
+           --title $"turtl app settings" \
166
+           --radiolist $"Choose an operation:" 4 70 3 \
167
+           1 $"Enable/disable new user registrations" off \
168
+           2 $"Change storage limit" off \
169
+           3 $"Exit" on 2> $data
170
+    sel=$?
171
+    case $sel in
172
+        1) exit 1;;
173
+        255) exit 1;;
174
+    esac
175
+    case $(cat $data) in
176
+        1) configure_interactive_turtl_signups;;
177
+        2) configure_interactive_turtl_storage;;
178
+        3) break;;
179
+    esac
180
+}
109 181
 
110 182
 function reconfigure_turtl {
111 183
     if [ -d $TURTL_BASE_DIR/data ]; then
@@ -118,6 +190,14 @@ function upgrade_turtl {
118 190
 
119 191
     function_check set_repo_commit
120 192
     set_repo_commit $TURTL_BASE_DIR/api "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
193
+
194
+    # this is used as a crude way of disabling signups and so
195
+    # should be superceded in future
196
+    if [ -f $TURTL_BASE_DIR/.users.lisp ]; then
197
+        turtl_disable_registrations
198
+    fi
199
+    systemctl restart turtl
200
+
121 201
     nginx_dissite $TURTL_DOMAIN_NAME
122 202
     chown -R turtl:turtl $TURTL_BASE_DIR
123 203
     nginx_ensite $TURTL_DOMAIN_NAME