1#!/bin/sh 2# Modified version of setup.sh distributed with webmin 3 4if [ "$wadir" = "" ]; then 5 echo "ERROR: wadir not specified" 6 echo "" 7 exit 1 8fi 9 10config_dir_runtime=$config_dir 11config_dir=$prefix$config_dir 12 13wadir_runtime=$wadir 14wadir=$prefix$wadir 15 16ver=`cat "$wadir/version"` 17 18cd "$wadir" 19 20# Work out perl library path 21PERLLIB=$wadir 22 23# Validate source directory 24allmods=`cd "$wadir"; echo */module.info | sed -e 's/\/module.info//g'` 25if [ "$allmods" = "" ]; then 26 echo "ERROR: Failed to get module list" 27 echo "" 28 exit 1 29fi 30echo "" 31 32if [ "$login" = "webmin" ]; then 33 echo "ERROR: Username 'webmin' is reserved for internal use" 34 echo "" 35 exit 14 36fi 37 38# Create webserver config file 39echo $perl > $config_dir/perl-path 40echo $var_dir > $config_dir/var-path 41echo "Creating web server config files.." 42cfile=$config_dir/miniserv.conf 43echo "port=$port" >> $cfile 44echo "root=$wadir_runtime" >> $cfile 45echo "mimetypes=$wadir_runtime/mime.types" >> $cfile 46echo "addtype_cgi=internal/cgi" >> $cfile 47echo "realm=Webmin Server" >> $cfile 48echo "logfile=$var_dir/miniserv.log" >> $cfile 49echo "errorlog=$var_dir/miniserv.error" >> $cfile 50echo "pidfile=$var_dir/miniserv.pid" >> $cfile 51echo "logtime=168" >> $cfile 52echo "ppath=$ppath" >> $cfile 53echo "ssl=$ssl" >> $cfile 54echo "env_WEBMIN_CONFIG=$config_dir_runtime" >> $cfile 55echo "env_WEBMIN_VAR=$var_dir" >> $cfile 56echo "atboot=$atboot" >> $cfile 57echo "logout=$config_dir_runtime/logout-flag" >> $cfile 58if [ "$listen" != "" ]; then 59 echo "listen=$listen" >> $cfile 60else 61 echo "listen=10000" >> $cfile 62fi 63echo "denyfile=\\.pl\$" >> $cfile 64echo "log=1" >> $cfile 65echo "blockhost_failures=5" >> $cfile 66echo "blockhost_time=60" >> $cfile 67echo "syslog=1" >> $cfile 68if [ "$allow" != "" ]; then 69 echo "allow=$allow" >> $cfile 70fi 71if [ "$session" != "" ]; then 72 echo "session=$session" >> $cfile 73else 74 echo "session=1" >> $cfile 75fi 76if [ "$pam" != "" ]; then 77 echo "pam=$pam" >> $cfile 78fi 79if [ "$no_pam" != "" ]; then 80 echo "no_pam=$no_pam" >> $cfile 81fi 82echo premodules=WebminCore >> $cfile 83echo "server=MiniServ/$ver" >> $cfile 84 85md5pass=`$perl -e 'print crypt("test", "\\$1\\$A9wB3O18\\$zaZgqrEmb9VNltWTL454R/") eq "\\$1\\$A9wB3O18\\$zaZgqrEmb9VNltWTL454R/" ? "1\n" : "0\n"'` 86 87ufile=$config_dir/miniserv.users 88if [ "$crypt" != "" ]; then 89 echo "$login:$crypt:0" > $ufile 90else 91 if [ "$md5pass" = "1" ]; then 92 $perl -e 'print "$ARGV[0]:",crypt($ARGV[1], "\$1\$XXXXXXXX"),":0\n"' "$login" "$password" > $ufile 93 else 94 $perl -e 'print "$ARGV[0]:",crypt($ARGV[1], "XX"),":0\n"' "$login" "$password" > $ufile 95 fi 96fi 97chmod 600 $ufile 98echo "userfile=$config_dir_runtime/miniserv.users" >> $cfile 99 100kfile=$config_dir/miniserv.pem 101openssl version >/dev/null 2>&1 102if [ "$?" = "0" ]; then 103 # We can generate a new SSL key for this host 104 host=`hostname` 105 openssl req -newkey rsa:512 -x509 -nodes -out $tempdir/cert -keyout $tempdir/key -days 1825 >/dev/null 2>&1 <<EOF 106. 107. 108. 109Webmin Webserver on $host 110. 111* 112root@$host 113EOF 114 if [ "$?" = "0" ]; then 115 cat $tempdir/cert $tempdir/key >$kfile 116 fi 117 rm -f $tempdir/cert $tempdir/key 118fi 119if [ ! -r $kfile ]; then 120 # Fall back to the built-in key 121 cp "$wadir/miniserv.pem" $kfile 122fi 123chmod 600 $kfile 124echo "keyfile=$config_dir_runtime/miniserv.pem" >> $cfile 125 126chmod 600 $cfile 127echo "..done" 128echo "" 129 130echo "Creating access control file.." 131afile=$config_dir/webmin.acl 132rm -f $afile 133if [ "$defaultmods" = "" ]; then 134 echo "$login: $allmods" >> $afile 135else 136 echo "$login: $defaultmods" >> $afile 137fi 138chmod 600 $afile 139echo "..done" 140echo "" 141 142if [ "$login" != "root" -a "$login" != "admin" ]; then 143 # Allow use of RPC by this user 144 echo rpc=1 >>$config_dir/$login.acl 145fi 146 147if [ "$noperlpath" = "" ]; then 148 echo "Inserting path to perl into scripts.." 149 (find "$wadir" -name '*.cgi' -print ; find "$wadir" -name '*.pl' -print) | $perl "$wadir/perlpath.pl" $perl_runtime - 150 echo "..done" 151 echo "" 152fi 153 154echo "Creating start and stop scripts.." 155rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/reload 156echo "#!/bin/sh" >>$config_dir/start 157echo "echo Starting Webmin server in $wadir_runtime" >>$config_dir/start 158echo "trap '' 1" >>$config_dir/start 159echo "LANG=" >>$config_dir/start 160echo "export LANG" >>$config_dir/start 161echo "#PERLIO=:raw" >>$config_dir/start 162echo "unset PERLIO" >>$config_dir/start 163echo "export PERLIO" >>$config_dir/start 164echo "PERLLIB=$PERLLIB" >>$config_dir/start 165echo "export PERLLIB" >>$config_dir/start 166uname -a | grep -i 'HP/*UX' >/dev/null 167if [ $? = "0" ]; then 168 echo "exec '$wadir_runtime/miniserv.pl' $config_dir_runtime/miniserv.conf &" >>$config_dir/start 169else 170 echo "exec '$wadir_runtime/miniserv.pl' $config_dir_runtime/miniserv.conf" >>$config_dir/start 171fi 172 173echo "#!/bin/sh" >>$config_dir/stop 174echo "echo Stopping Webmin server in $wadir_runtime" >>$config_dir/stop 175echo "pidfile=\`grep \"^pidfile=\" $config_dir_runtime/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop 176echo "kill \`cat \$pidfile\`" >>$config_dir/stop 177 178echo "#!/bin/sh" >>$config_dir/restart 179echo "$config_dir_runtime/stop && $config_dir_runtime/start" >>$config_dir/restart 180 181echo "#!/bin/sh" >>$config_dir/reload 182echo "echo Reloading Webmin server in $wadir_runtime" >>$config_dir/reload 183echo "pidfile=\`grep \"^pidfile=\" $config_dir_runtime/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload 184echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload 185 186chmod 755 $config_dir/start $config_dir/stop $config_dir/restart $config_dir/reload 187echo "..done" 188echo "" 189 190if [ "$upgrading" = 1 ]; then 191 echo "Updating config files.." 192else 193 echo "Copying config files.." 194fi 195newmods=`$perl "$wadir/copyconfig.pl" "$os_type/$real_os_type" "$os_version/$real_os_version" "$wadir" $config_dir "" $allmods` 196# Store the OS and version 197echo "os_type=$os_type" >> $config_dir/config 198echo "os_version=$os_version" >> $config_dir/config 199echo "real_os_type=$real_os_type" >> $config_dir/config 200echo "real_os_version=$real_os_version" >> $config_dir/config 201if [ -r /etc/system.cnf ]; then 202 # Found a caldera system config file .. get the language 203 source /etc/system.cnf 204 if [ "$CONF_LST_LANG" = "us" ]; then 205 CONF_LST_LANG=en 206 elif [ "$CONF_LST_LANG" = "uk" ]; then 207 CONF_LST_LANG=en 208 fi 209 grep "lang=$CONF_LST_LANG," "$wadir/lang_list.txt" >/dev/null 2>&1 210 if [ "$?" = 0 ]; then 211 echo "lang=$CONF_LST_LANG" >> $config_dir/config 212 fi 213fi 214 215# Turn on logging by default 216echo "log=1" >> $config_dir/config 217 218# Use licence module specified by environment variable 219if [ "$licence_module" != "" ]; then 220 echo licence_module=$licence_module >>$config_dir/config 221fi 222 223# Disallow unknown referers by default 224echo "referers_none=1" >>$config_dir/config 225echo $ver > $config_dir/version 226echo "..done" 227echo "" 228 229# Set passwd_ fields in miniserv.conf from global config 230for field in passwd_file passwd_uindex passwd_pindex passwd_cindex passwd_mindex; do 231 grep $field= $config_dir/miniserv.conf >/dev/null 232 if [ "$?" != "0" ]; then 233 grep $field= $config_dir/config >> $config_dir/miniserv.conf 234 fi 235done 236grep passwd_mode= $config_dir/miniserv.conf >/dev/null 237if [ "$?" != "0" ]; then 238 echo passwd_mode=0 >> $config_dir/miniserv.conf 239fi 240 241# If Perl crypt supports MD5, then make it the default 242if [ "$md5pass" = "1" ]; then 243 echo md5pass=1 >> $config_dir/config 244fi 245 246# Set a special theme if none was set before 247if [ "$theme" = "" ]; then 248 theme=`cat "$wadir/defaulttheme" 2>/dev/null` 249fi 250oldthemeline=`grep "^theme=" $config_dir/config` 251oldtheme=`echo $oldthemeline | sed -e 's/theme=//g'` 252if [ "$theme" != "" ] && [ "$oldthemeline" = "" ] && [ -d "$wadir/$theme" ]; then 253 themelist=$theme 254fi 255 256# Set a special overlay if none was set before 257if [ "$overlay" = "" ]; then 258 overlay=`cat "$wadir/defaultoverlay" 2>/dev/null` 259fi 260if [ "$overlay" != "" ] && [ "$theme" != "" ] && [ -d "$wadir/$overlay" ]; then 261 themelist="$themelist $overlay" 262fi 263 264# Apply the theme and maybe overlay 265if [ "$themelist" != "" ]; then 266 echo "theme=$themelist" >> $config_dir/config 267 echo "preroot=$themelist" >> $config_dir/miniserv.conf 268fi 269 270# Set the product field in the global config 271grep product= $config_dir/config >/dev/null 272if [ "$?" != "0" ]; then 273 echo product=webmin >> $config_dir/config 274fi 275 276if [ "$makeboot" = "1" ]; then 277 echo "Configuring Webmin to start at boot time.." 278 (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/atboot.pl" $bootscript) 279 echo "..done" 280 echo "" 281fi 282 283# If password delays are not specifically disabled, enable them 284grep passdelay= $config_dir/miniserv.conf >/dev/null 285if [ "$?" != "0" ]; then 286 echo passdelay=1 >> $config_dir/miniserv.conf 287fi 288 289echo "Changing ownership and permissions .." 290# Make all config dirs non-world-readable 291for m in $newmods; do 292 chown -R root $config_dir/$m 293 chgrp -R bin $config_dir/$m 294 chmod -R og-rw $config_dir/$m 295done 296# Make miniserv config files non-world-readable 297for f in miniserv.conf miniserv.pem miniserv.users; do 298 chown -R root $config_dir/$f 299 chgrp -R bin $config_dir/$f 300 chmod -R og-rw $config_dir/$f 301done 302chmod +r $config_dir/version 303if [ "$nochown" = "" ]; then 304 # Make program directory non-world-writable, but executable 305 chown -R root "$wadir" 306 chgrp -R bin "$wadir" 307 chmod -R og-w "$wadir" 308 chmod -R a+rx "$wadir" 309fi 310if [ $var_dir != "/var" ]; then 311 # Make log directory non-world-readable or writable 312 chown -R root $prefix$var_dir 313 chgrp -R bin $prefix$var_dir 314 chmod -R og-rwx $prefix$var_dir 315fi 316# Fix up bad permissions from some older installs 317for m in ldap-client ldap-server ldap-useradmin mailboxes mysql postgresql servers virtual-server; do 318 if [ -d "$config_dir/$m" ]; then 319 chown root $config_dir/$m 320 chgrp bin $config_dir/$m 321 chmod og-rw $config_dir/$m 322 chmod og-rw $config_dir/$m/config 2>/dev/null 323 fi 324done 325 326if [ "$nopostinstall" = "" ]; then 327 echo "Running postinstall scripts .." 328 (cd "$wadir" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/run-postinstalls.pl") 329 echo "..done" 330 echo "" 331fi 332 333# Enable background collection 334if [ "$upgrading" != 1 -a -r $config_dir/system-status/enable-collection.pl ]; then 335 echo "Enabling background status collection .." 336 $config_dir/system-status/enable-collection.pl 5 337 echo "..done" 338 echo "" 339fi 340 341