Dash:
[t2.git] / package / network / webmin / stone_mod_webmin.sh
blobab60a11745e9c6c30acbf3c34cd66d300e36986c
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
3 #
4 # T2 SDE: package/.../webmin/stone_mod_webmin.sh
5 # Copyright (C) 2004 - 2007 The T2 SDE Project
6 # Copyright (C) 1998 - 2003 ROCK Linux Project
7 #
8 # More information can be found in the files COPYING and README.
9 #
10 # This program is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; version 2 of the License. A copy of the
13 # GNU General Public License can be found in the file COPYING.
14 # --- T2-COPYRIGHT-NOTE-END ---
16 # [MAIN] 80 webmin Webmin Configuration
18 WEBMINDIR=/opt/webmin
19 USERFILE=/etc/opt/webmin/miniserv.users
20 CONFFILE=/etc/opt/webmin/miniserv.conf
21 ACLFILE=/etc/opt/webmin/webmin.acl
23 set_pw() {
24 LOGIN="$1"
25 PASSWORD=1
26 PASSWORD2=2
27 while [ "$PASSWORD" != "$PASSWORD2" ] ; do
28 gui_input "Enter $LOGIN password" "" PASSWORD ;
29 gui_input "Re-Enter $LOGIN password" "" PASSWORD2 ;
30 if [ "$PASSWORD" != "$PASSWORD2" ] ; then
31 gui_message "Passwords are different: no change!"
33 done
34 if [ "$2" = 1 ] ; then
35 gui_message "Changeing $LOGIN password."
36 tmp="`mktemp`"
37 sed "/^$LOGIN:.*/ s/^$LOGIN:[^:]*:/$LOGIN:`perl -e 'print crypt($ARGV[0], "XX");' "$PASSWORD"`:/ ;" < $USERFILE > $tmp
38 cat $tmp > $USERFILE ; rm -f $tmp
39 else
40 gui_message "Setting $LOGIN password."
41 perl -e 'print "$ARGV[0]:",crypt($ARGV[1], "XX"),":0::\n"' "$LOGIN" "$PASSWORD" >> $USERFILE
46 set_acl() {
47 LOGIN="$1"
48 ALLMODS=`echo $WEBMINDIR/*/module.info | sed -e "s,$WEBMINDIR/,,g ; s,/module.info,,g"`
49 if [ "$2" = 1 ] ; then
50 gui_message "Resetting $LOGIN acls to default."
51 tmp="`mktemp`"
52 sed "/^$LOGIN:.*/ s/:.*/: $ALLMODS/ ;" < $ACLFILE > $tmp
53 cat $tmp > $ACLFILE ; rm -f $tmp
54 else
55 gui_message "Setting $LOGIN acls to default."
56 echo "$LOGIN: $ALLMODS" >> $ACLFILE
60 set_user() {
61 gui_input "Enter user login" "admin" LOGIN ;
62 if [ "`grep \"^$LOGIN:\" $USERFILE`" = "" ] ; then
63 gui_message "New user $LOGIN !"
64 set_pw $LOGIN 0
65 set_acl $LOGIN 0
66 else
67 gui_message "Existing user $LOGIN !"
68 if gui_yesno "Change $LOGIN password?" ; then
69 set_pw $LOGIN 1
71 if gui_yesno "Reset $LOGIN acls?" ; then
72 set_acl $LOGIN 1
77 edit() {
78 gui_edit "Edit file $1" "$1"
79 exec $STONE webmin
82 main() {
83 while
84 cmd="gui_menu webmin 'Webmin Configuration - Select an item to'"
86 cmd="$cmd 'Add/(Re-)Set user password and acls' 'set_user'"
88 cmd="$cmd '' '' 'Configure runlevels for webmin service'"
89 cmd="$cmd '$STONE runlevel edit_srv webmin'"
90 cmd="$cmd '(Re-)Start webmin init script'"
91 cmd="$cmd '$STONE runlevel restart webmin'"
92 cmd="$cmd '' ''"
94 cmd="$cmd 'View/Edit $CONFFILE file' 'edit $CONFFILE'"
96 eval "$cmd"
97 do : ; done