Explorar el Código

Hack to enable or disable turtl signups

Bob Mottram hace 8 años
padre
commit
d5c55a8824
Se han modificado 1 ficheros con 81 adiciones y 1 borrados
  1. 81
    1
      src/freedombone-app-turtl

+ 81
- 1
src/freedombone-app-turtl Ver fichero

46
 TURTL_STORAGE_LIMIT_MB=100
46
 TURTL_STORAGE_LIMIT_MB=100
47
 TURTL_BASE_DIR=/etc/turtl
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
 turtl_variables=(ONION_ONLY
53
 turtl_variables=(ONION_ONLY
50
                  DEFAULT_DOMAIN_NAME
54
                  DEFAULT_DOMAIN_NAME
51
                  TURTL_DOMAIN_NAME
55
                  TURTL_DOMAIN_NAME
85
     APP_INSTALLED=1
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
     data=$(tempfile 2>/dev/null)
141
     data=$(tempfile 2>/dev/null)
90
     trap "rm -f $data" 0 1 2 5 15
142
     trap "rm -f $data" 0 1 2 5 15
91
     dialog --title $"Change storage limit" \
143
     dialog --title $"Change storage limit" \
106
     esac
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
 function reconfigure_turtl {
182
 function reconfigure_turtl {
111
     if [ -d $TURTL_BASE_DIR/data ]; then
183
     if [ -d $TURTL_BASE_DIR/data ]; then
118
 
190
 
119
     function_check set_repo_commit
191
     function_check set_repo_commit
120
     set_repo_commit $TURTL_BASE_DIR/api "turtl commit" "$TURTL_COMMIT" $TURTL_REPO
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
     nginx_dissite $TURTL_DOMAIN_NAME
201
     nginx_dissite $TURTL_DOMAIN_NAME
122
     chown -R turtl:turtl $TURTL_BASE_DIR
202
     chown -R turtl:turtl $TURTL_BASE_DIR
123
     nginx_ensite $TURTL_DOMAIN_NAME
203
     nginx_ensite $TURTL_DOMAIN_NAME