Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # Modified version of setup.sh distributed with webmin |
| 3 | |
| 4 | if [ "$wadir" = "" ]; then |
| 5 | echo "ERROR: wadir not specified" |
| 6 | echo "" |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
| 10 | config_dir_runtime=$config_dir |
| 11 | config_dir=$prefix$config_dir |
| 12 | |
| 13 | wadir_runtime=$wadir |
| 14 | wadir=$prefix$wadir |
| 15 | |
| 16 | ver=`cat "$wadir/version"` |
| 17 | |
| 18 | cd "$wadir" |
| 19 | |
| 20 | # Work out perl library path |
| 21 | PERLLIB=$wadir |
| 22 | |
| 23 | # Validate source directory |
| 24 | allmods=`cd "$wadir"; echo */module.info | sed -e 's/\/module.info//g'` |
| 25 | if [ "$allmods" = "" ]; then |
| 26 | echo "ERROR: Failed to get module list" |
| 27 | echo "" |
| 28 | exit 1 |
| 29 | fi |
| 30 | echo "" |
| 31 | |
| 32 | if [ "$login" = "webmin" ]; then |
| 33 | echo "ERROR: Username 'webmin' is reserved for internal use" |
| 34 | echo "" |
| 35 | exit 14 |
| 36 | fi |
| 37 | |
| 38 | # Create webserver config file |
| 39 | echo $perl > $config_dir/perl-path |
| 40 | echo $var_dir > $config_dir/var-path |
| 41 | echo "Creating web server config files.." |
| 42 | cfile=$config_dir/miniserv.conf |
| 43 | echo "port=$port" >> $cfile |
| 44 | echo "root=$wadir_runtime" >> $cfile |
| 45 | echo "mimetypes=$wadir_runtime/mime.types" >> $cfile |
| 46 | echo "addtype_cgi=internal/cgi" >> $cfile |
| 47 | echo "realm=Webmin Server" >> $cfile |
| 48 | echo "logfile=$var_dir/miniserv.log" >> $cfile |
| 49 | echo "errorlog=$var_dir/miniserv.error" >> $cfile |
| 50 | echo "pidfile=$var_dir/miniserv.pid" >> $cfile |
| 51 | echo "logtime=168" >> $cfile |
| 52 | echo "ppath=$ppath" >> $cfile |
| 53 | echo "ssl=$ssl" >> $cfile |
| 54 | echo "env_WEBMIN_CONFIG=$config_dir_runtime" >> $cfile |
| 55 | echo "env_WEBMIN_VAR=$var_dir" >> $cfile |
| 56 | echo "atboot=$atboot" >> $cfile |
| 57 | echo "logout=$config_dir_runtime/logout-flag" >> $cfile |
| 58 | if [ "$listen" != "" ]; then |
| 59 | echo "listen=$listen" >> $cfile |
| 60 | else |
| 61 | echo "listen=10000" >> $cfile |
| 62 | fi |
| 63 | echo "denyfile=\\.pl\$" >> $cfile |
| 64 | echo "log=1" >> $cfile |
| 65 | echo "blockhost_failures=5" >> $cfile |
| 66 | echo "blockhost_time=60" >> $cfile |
| 67 | echo "syslog=1" >> $cfile |
| 68 | if [ "$allow" != "" ]; then |
| 69 | echo "allow=$allow" >> $cfile |
| 70 | fi |
| 71 | if [ "$session" != "" ]; then |
| 72 | echo "session=$session" >> $cfile |
| 73 | else |
| 74 | echo "session=1" >> $cfile |
| 75 | fi |
| 76 | if [ "$pam" != "" ]; then |
| 77 | echo "pam=$pam" >> $cfile |
| 78 | fi |
| 79 | if [ "$no_pam" != "" ]; then |
| 80 | echo "no_pam=$no_pam" >> $cfile |
| 81 | fi |
| 82 | echo premodules=WebminCore >> $cfile |
| 83 | echo "server=MiniServ/$ver" >> $cfile |
| 84 | |
| 85 | md5pass=`$perl -e 'print crypt("test", "\\$1\\$A9wB3O18\\$zaZgqrEmb9VNltWTL454R/") eq "\\$1\\$A9wB3O18\\$zaZgqrEmb9VNltWTL454R/" ? "1\n" : "0\n"'` |
| 86 | |
| 87 | ufile=$config_dir/miniserv.users |
| 88 | if [ "$crypt" != "" ]; then |
| 89 | echo "$login:$crypt:0" > $ufile |
| 90 | else |
| 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 |
| 96 | fi |
| 97 | chmod 600 $ufile |
| 98 | echo "userfile=$config_dir_runtime/miniserv.users" >> $cfile |
| 99 | |
| 100 | kfile=$config_dir/miniserv.pem |
| 101 | openssl version >/dev/null 2>&1 |
| 102 | if [ "$?" = "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 | . |
| 109 | Webmin Webserver on $host |
| 110 | . |
| 111 | * |
| 112 | root@$host |
| 113 | EOF |
| 114 | if [ "$?" = "0" ]; then |
| 115 | cat $tempdir/cert $tempdir/key >$kfile |
| 116 | fi |
| 117 | rm -f $tempdir/cert $tempdir/key |
| 118 | fi |
| 119 | if [ ! -r $kfile ]; then |
| 120 | # Fall back to the built-in key |
| 121 | cp "$wadir/miniserv.pem" $kfile |
| 122 | fi |
| 123 | chmod 600 $kfile |
| 124 | echo "keyfile=$config_dir_runtime/miniserv.pem" >> $cfile |
| 125 | |
| 126 | chmod 600 $cfile |
| 127 | echo "..done" |
| 128 | echo "" |
| 129 | |
| 130 | echo "Creating access control file.." |
| 131 | afile=$config_dir/webmin.acl |
| 132 | rm -f $afile |
| 133 | if [ "$defaultmods" = "" ]; then |
| 134 | echo "$login: $allmods" >> $afile |
| 135 | else |
| 136 | echo "$login: $defaultmods" >> $afile |
| 137 | fi |
| 138 | chmod 600 $afile |
| 139 | echo "..done" |
| 140 | echo "" |
| 141 | |
| 142 | if [ "$login" != "root" -a "$login" != "admin" ]; then |
| 143 | # Allow use of RPC by this user |
| 144 | echo rpc=1 >>$config_dir/$login.acl |
| 145 | fi |
| 146 | |
| 147 | if [ "$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 "" |
| 152 | fi |
| 153 | |
| 154 | echo "Creating start and stop scripts.." |
| 155 | rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/reload |
| 156 | echo "#!/bin/sh" >>$config_dir/start |
| 157 | echo "echo Starting Webmin server in $wadir_runtime" >>$config_dir/start |
| 158 | echo "trap '' 1" >>$config_dir/start |
| 159 | echo "LANG=" >>$config_dir/start |
| 160 | echo "export LANG" >>$config_dir/start |
| 161 | echo "#PERLIO=:raw" >>$config_dir/start |
| 162 | echo "unset PERLIO" >>$config_dir/start |
| 163 | echo "export PERLIO" >>$config_dir/start |
| 164 | echo "PERLLIB=$PERLLIB" >>$config_dir/start |
| 165 | echo "export PERLLIB" >>$config_dir/start |
| 166 | uname -a | grep -i 'HP/*UX' >/dev/null |
| 167 | if [ $? = "0" ]; then |
| 168 | echo "exec '$wadir_runtime/miniserv.pl' $config_dir_runtime/miniserv.conf &" >>$config_dir/start |
| 169 | else |
| 170 | echo "exec '$wadir_runtime/miniserv.pl' $config_dir_runtime/miniserv.conf" >>$config_dir/start |
| 171 | fi |
| 172 | |
| 173 | echo "#!/bin/sh" >>$config_dir/stop |
| 174 | echo "echo Stopping Webmin server in $wadir_runtime" >>$config_dir/stop |
| 175 | echo "pidfile=\`grep \"^pidfile=\" $config_dir_runtime/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop |
| 176 | echo "kill \`cat \$pidfile\`" >>$config_dir/stop |
| 177 | |
| 178 | echo "#!/bin/sh" >>$config_dir/restart |
| 179 | echo "$config_dir_runtime/stop && $config_dir_runtime/start" >>$config_dir/restart |
| 180 | |
| 181 | echo "#!/bin/sh" >>$config_dir/reload |
| 182 | echo "echo Reloading Webmin server in $wadir_runtime" >>$config_dir/reload |
| 183 | echo "pidfile=\`grep \"^pidfile=\" $config_dir_runtime/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload |
| 184 | echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload |
| 185 | |
| 186 | chmod 755 $config_dir/start $config_dir/stop $config_dir/restart $config_dir/reload |
| 187 | echo "..done" |
| 188 | echo "" |
| 189 | |
| 190 | if [ "$upgrading" = 1 ]; then |
| 191 | echo "Updating config files.." |
| 192 | else |
| 193 | echo "Copying config files.." |
| 194 | fi |
| 195 | newmods=`$perl "$wadir/copyconfig.pl" "$os_type/$real_os_type" "$os_version/$real_os_version" "$wadir" $config_dir "" $allmods` |
| 196 | # Store the OS and version |
| 197 | echo "os_type=$os_type" >> $config_dir/config |
| 198 | echo "os_version=$os_version" >> $config_dir/config |
| 199 | echo "real_os_type=$real_os_type" >> $config_dir/config |
| 200 | echo "real_os_version=$real_os_version" >> $config_dir/config |
| 201 | if [ -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 |
| 213 | fi |
| 214 | |
| 215 | # Turn on logging by default |
| 216 | echo "log=1" >> $config_dir/config |
| 217 | |
| 218 | # Use licence module specified by environment variable |
| 219 | if [ "$licence_module" != "" ]; then |
| 220 | echo licence_module=$licence_module >>$config_dir/config |
| 221 | fi |
| 222 | |
| 223 | # Disallow unknown referers by default |
| 224 | echo "referers_none=1" >>$config_dir/config |
| 225 | echo $ver > $config_dir/version |
| 226 | echo "..done" |
| 227 | echo "" |
| 228 | |
| 229 | # Set passwd_ fields in miniserv.conf from global config |
| 230 | for 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 |
| 235 | done |
| 236 | grep passwd_mode= $config_dir/miniserv.conf >/dev/null |
| 237 | if [ "$?" != "0" ]; then |
| 238 | echo passwd_mode=0 >> $config_dir/miniserv.conf |
| 239 | fi |
| 240 | |
| 241 | # If Perl crypt supports MD5, then make it the default |
| 242 | if [ "$md5pass" = "1" ]; then |
| 243 | echo md5pass=1 >> $config_dir/config |
| 244 | fi |
| 245 | |
| 246 | # Set a special theme if none was set before |
| 247 | if [ "$theme" = "" ]; then |
| 248 | theme=`cat "$wadir/defaulttheme" 2>/dev/null` |
| 249 | fi |
| 250 | oldthemeline=`grep "^theme=" $config_dir/config` |
| 251 | oldtheme=`echo $oldthemeline | sed -e 's/theme=//g'` |
| 252 | if [ "$theme" != "" ] && [ "$oldthemeline" = "" ] && [ -d "$wadir/$theme" ]; then |
| 253 | themelist=$theme |
| 254 | fi |
| 255 | |
| 256 | # Set a special overlay if none was set before |
| 257 | if [ "$overlay" = "" ]; then |
| 258 | overlay=`cat "$wadir/defaultoverlay" 2>/dev/null` |
| 259 | fi |
| 260 | if [ "$overlay" != "" ] && [ "$theme" != "" ] && [ -d "$wadir/$overlay" ]; then |
| 261 | themelist="$themelist $overlay" |
| 262 | fi |
| 263 | |
| 264 | # Apply the theme and maybe overlay |
| 265 | if [ "$themelist" != "" ]; then |
| 266 | echo "theme=$themelist" >> $config_dir/config |
| 267 | echo "preroot=$themelist" >> $config_dir/miniserv.conf |
| 268 | fi |
| 269 | |
| 270 | # Set the product field in the global config |
| 271 | grep product= $config_dir/config >/dev/null |
| 272 | if [ "$?" != "0" ]; then |
| 273 | echo product=webmin >> $config_dir/config |
| 274 | fi |
| 275 | |
| 276 | if [ "$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 "" |
| 281 | fi |
| 282 | |
| 283 | # If password delays are not specifically disabled, enable them |
| 284 | grep passdelay= $config_dir/miniserv.conf >/dev/null |
| 285 | if [ "$?" != "0" ]; then |
| 286 | echo passdelay=1 >> $config_dir/miniserv.conf |
| 287 | fi |
| 288 | |
| 289 | echo "Changing ownership and permissions .." |
| 290 | # Make all config dirs non-world-readable |
| 291 | for 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 |
| 295 | done |
| 296 | # Make miniserv config files non-world-readable |
| 297 | for 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 |
| 301 | done |
| 302 | chmod +r $config_dir/version |
| 303 | if [ "$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" |
| 309 | fi |
| 310 | if [ $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 |
| 315 | fi |
| 316 | # Fix up bad permissions from some older installs |
| 317 | for 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 |
| 324 | done |
| 325 | |
| 326 | if [ "$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 "" |
| 331 | fi |
| 332 | |
| 333 | # Enable background collection |
| 334 | if [ "$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 "" |
| 339 | fi |
| 340 | |