Your IP : 216.73.216.21


Current Path : /pkg/zhost/1.0/bin.old/
Upload File :
Current File : //pkg/zhost/1.0/bin.old/zz-web-create

#!/bin/bash

# TODO: quotas, restart nginx, test PHP logging, add custom rewrite rules

if ! echo $PATH | grep -q '/cmd'; then
    PATH="/cmd:$PATH"
    export PATH
fi

#user=$(zz-util-base32 $user_id)
vhost=$1 # if with www, include without
user=$2 # add $user.zootzone.net to nginx vhost server_name
php_memory=$3
http_post=$4
#app=$5 # reserved for app installations, like WordPress, Drupal

errors=0

# global settings
cd /etc/zootzone/web
user_root=$(head -1 user_root)
http_user=$(head -1 http_user)
host_ip=$(head -1 host_ip)

if [ "$php_memory" == '' ]; then
    php_memory=$(head -1 php_memory)
fi
if [ "$http_post" == '' ]; then
    http_post=$(head -1 http_post)
fi

if echo "$vhost" | grep -q ^www; then
    vhost=$(echo $vhost | sed 's/^www\.//')
    vhost_nginx="$vhost www.$vhost"
    echo -e "\n$vhost\n$vhost_nginx\n"
fi

if [ ! -L /pkg/php/current ]; then
    echo "ERROR: no current PHP configured"
    exit 1
fi

cd /pkg/php
php_version=$(readlink current)

# TODO: more error checking
groupadd $user
useradd -g $user -s /bin/true -d $user_root/$user $user
gpasswd -a $user web # to enable SFTP access (see /etc/ssh/sshd_config)
user_passwd=$(zz-util-randpasswd)
echo "Password is $user_passwd" # TODO: email/SMS
echo "$user:$user_passwd" | chpasswd

if [ -d $user_root/$user ]; then
    echo "ERROR: $user_root/$user exists"
    exit 1
fi

mkdir -p $user_root/$user

cd $user_root/$user

mkdir -p {etc/{notify,php},home/default/{log,private,public},log/php,tmp/php/{sessions,uploads},.svc/php/multilog}
chown -R $user:$user etc home log tmp
chown $user:$http_user home tmp log
chown log:log .svc/php/multilog
chown root:$user etc
chmod 750 home log tmp etc # TODO: add to cron job to check
chmod 755 .svc # TODO: lock this down further

cat << EOF > .svc/php/run
#!/bin/ash
exec 2>&1
user=\$(pwd | cut -d '/' -f4)
echo "user = \$user"
if [ ! -d multilog ]; then
        mkdir multilog
    fi
    chown log:log multilog
    conf="$user_root/\$user/etc/php"
    echo "conf = \$conf"
    version=\$(head -1 \$conf/version)
    exec /pkg/php/\${version}/sbin/php-fpm -n -y \$conf/php.conf -c \$conf/php.ini
EOF

cat << EOF > .svc/php/log
#!/bin/ash
exec setuidgid log /cmd/multilog t ./multilog
EOF

chmod 755 .svc/php/{run,log}

echo $php_version > etc/php/version

cat << EOF > etc/php/php.ini
include_path=".:/pkg/php/$php_version/lib/php"
EOF

cat << EOF > etc/php/php.conf
[global]
daemonize = no
error_log = $user_root/$user/log/php/php.log
[$user]
user = $user
group = $http_user
listen = $user_root/$user/.svc/php/sock
listen.owner = $user
listen.group = $http_user
pm = dynamic
pm.max_children = 4
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 2
pm.max_requests = 200
catch_workers_output = yes
php_admin_flag[log_errors] = on
php_admin_value[error_log] = $user_root/$user/log/php/php.log
php_admin_value[session.save_path] = $user_root/$user/tmp/php/sessions
php_admin_value[upload_tmp_dir] = $user_root/$user/tmp/php/uploads
php_admin_flag[display_startup_errors] = off
php_admin_flag[display_errors] = off
php_admin_value[memory_limit] = ${php_memory}M
php_admin_value[upload_max_filesize] = ${http_post}M
php_admin_value[post_max_size] = ${http_post}M
php_value[date.timezone] = "Africa/Johannesburg"
php_admin_value[sendmail_path] = /cmd/sendmail -t -i -f noreply
EOF

cd /svc

if [ ! -L "$user-php" ]; then
    ln -s $user_root/$user/.svc/php "$user-php"
    sleep 6
else
    echo "NOTICE: service /svc/$user-php already running"
fi

svstat "/svc/$user-php"

if [ -f /etc/nginx/vhosts/$user ]; then
    echo "ERROR: /etc/nginx/vhosts/$user exists"
    exit 1
fi

cat << EOF > /etc/nginx/vhosts/$user
server {
    listen $host_ip:80;
    server_name $vhost_nginx $user.zootzone.net;

    root $user_root/$user/home/default/public;

    access_log $user_root/$user/home/default/log/access.log combined;
    error_log $user_root/$user/home/default/log/error.log error;

    client_max_body_size ${http_post}m;

    index index.php index.html;

    location ~ \.php$ {
        fastcgi_pass   unix:$user_root/$user/.svc/php/sock;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include        fastcgi_params;
        fastcgi_read_timeout 60;
    }
}
EOF

if [ -f /etc/nginx/auth/$user/tools ]; then
    echo "ERROR: /etc/nginx/auth/$user/tools exists"
    exit 1
fi
[[ ! -d /etc/nginx/auth/$user ]] && mkdir -p /etc/nginx/auth/$user
zz-util-htpasswd $user $user_passwd > /etc/nginx/auth/$user/tools

if [ -f /etc/nginx/tools/$user ]; then
    echo "ERROR: /etc/nginx/tools/$user exists"
    exit 1
fi
[[ ! -d /etc/nginx/tools ]] && mkdir -p /etc/nginx/tools

cat << EOF > /etc/nginx/tools/$user
  location /files/$user {
    auth_basic "File Manager";
    auth_basic_user_file /etc/nginx/auth/$user/tools;
    root $user_root/share;
    location ~* \.php {
      fastcgi_pass   unix:$user_root/$user/.svc/php/sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
      fastcgi_param  FILES_ROOT $user_root/$user/home;
      include        fastcgi_params;
    }
    location /files/$user/home {
      alias $user_root/$user/home;
    }
  }
  location /mariadb/$user {
    index index.php;
    auth_basic "File Manager";
    auth_basic_user_file /etc/nginx/auth/$user/tools;
    root $user_root/share;
    location ~* \.php {
      fastcgi_pass   unix:$user_root/$user/.svc/php/sock;
      fastcgi_index  index.php;
      fastcgi_param  SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
      include        fastcgi_params;
    }
  }
EOF

if [ ! -L $user_root/share/files/$user ]; then
    cd $user_root/share/files
    if [ -d .files ]; then
        ln -s .files $user
    else
	echo "ERROR: $user_root/share/files/.adminer missing"
	exit 1
    fi
fi

if [ ! -L $user_root/share/mariadb/$user ]; then
    cd $user_root/share/mariadb
    if [ -d .adminer ]; then
        ln -s .adminer $user
    else
	echo "ERROR: $user_root/share/mariadb/.adminer missing"
	exit 1
    fi
fi

cat << EOF > $user_root/$user/home/default/public/index.html
<html>
  <head>
    <title>$vhost</title>
    <style type="text/css">
      body {
	font:70%/1.5em Verdana, Tahoma, arial, sans-serif;
	font-size: 10px;
	color: black;
      }
      a {
	font-size: 11px;
	font-weight: bold;
	color: #09f;
	text-decoration: none;
      }
      a:hover {
	font-size: 11px;
	font-weight: bold;
	color: #09f;
	text-decoration: underline;
      }
      .hostname {
	font-size: 18px;
	font-weight: bold;
	color: white;
	background: #09f;
	text-decoration: none;
      }
      .content {
	font-size: 12px;
	font-weight: bold;
	color: #666;
	text-decoration: none;
      }
      .footer {
	font-size: 10px;
	font-weight: bold;
	color: #aaa;
	text-decoration: none;
      }
      .displaynone {
	display:none;
      }
    </style>
  </head>
  <body>
    <center>
      <table cellpadding="10" cellspacing="10">
	<tr>
	  <td align="center" class="hostname">$vhost</td>
        </tr>
	<tr>
	  <td class="content" align="center">
	      Future web presence.
	  </td>
	</tr>
	<tr>
	  <td class="footer" align="center">
	    hosted by<br /><a href="http://www.zootzone.com">zootzone.com</a>
	  </td>
	</tr>
      </table>
    </center>
  </body>
</html>
EOF

chown $user:$user $user_root/$user/home/default/public/index.html

cat << EOF > $user_root/$user/home/README.txt
Introduction
------------

Support: help@zootzone.com

This service uses the nginx web server,
so Apache .htaccess files will not work. 
Request support to have equivalent
conditions configured.

Each account has its own pool of PHP
processes with strict resource allocation.
Request support for configuration changes.

The default host's document root is
./home/default/public

Additional hosts can be served from a single
web hosting account. Example ./home/host2/public

The web based file manager has access to
everything from the home directory onwards

SFTP access is required in order to see the
etc, log, run and tmp directories.

.
|-- etc
|   \`-- php
|       |-- php.conf
|       |-- php.ini
|       \`-- version
|-- home
|   \`-- default
|       |-- log
|       |   |-- access.log
|       |   \`-- error.log
|       |-- private
|       \`-- public
|           \`-- index.html
|-- log
|   \`-- php
|       \`-- php.log
\`-- tmp
    \`-- php
        |-- sessions
	    \`-- uploads
EOF

https://nalibali.org/post-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/page-sitemap.xml 2026-11-18T09:24:11+00:00 https://nalibali.org/stories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/stories-sitemap2.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/audio_stories-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/story_cards-sitemap.xml 2025-06-06T10:27:48+00:00 https://nalibali.org/story_seeds-sitemap.xml 2025-05-19T07:35:43+00:00 https://nalibali.org/rhymes-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/activity_sheets-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/team_member-sitemap.xml 2025-05-28T09:40:43+00:00 https://nalibali.org/video_stories-sitemap.xml 2025-06-23T08:48:28+00:00 https://nalibali.org/guides-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/story_supplements-sitemap.xml 2025-09-16T12:22:20+00:00 https://nalibali.org/vacancies-sitemap.xml 2026-09-17T07:05:01+00:00 https://nalibali.org/category-sitemap.xml 2026-11-20T09:00:00+00:00 https://nalibali.org/post_tag-sitemap.xml 2026-11-06T00:00:00+00:00 https://nalibali.org/test-sitemap.xml 2025-06-13T09:36:28+00:00 https://nalibali.org/story_categories-sitemap.xml 2026-05-05T06:48:38+00:00 https://nalibali.org/activity_sheets_categories-sitemap.xml 2025-05-16T09:16:43+00:00 https://nalibali.org/printables_categories-sitemap.xml 2025-05-16T09:28:40+00:00 https://nalibali.org/posters_bookmarks_categories-sitemap.xml 2025-05-16T10:20:22+00:00 https://nalibali.org/single_audio-sitemap.xml 2026-03-27T06:53:13+00:00 https://nalibali.org/rhyme_categories-sitemap.xml 2025-06-17T07:43:10+00:00 https://nalibali.org/guide_categories-sitemap.xml 2025-06-17T09:38:41+00:00 https://nalibali.org/author-sitemap.xml 2026-01-22T07:26:07+00:00