Your IP : 216.73.216.21


Current Path : /pkg/zweb/1.0/bin/
Upload File :
Current File : //pkg/zweb/1.0/bin/zweb-create~

#!/bin/bash

# TODO
# chown w57:nginx w57/sys

# 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

usage() {
    echo "usage: $0 <host> <user> <memory>"
    exit 1
}

if (( $# != 3 )); then
    usage
fi


errors=0

# global settings
cd /etc/zweb
web_root=$(head -1 web_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"
else
    vhost_nginx="$vhost"
fi

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

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

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

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

mkdir -p $web_root/$user

cd $web_root/$user

mkdir -p {etc/{notify,php,panel},home/default/{log,private,public},log/panel,log/php,tmp/php/{sessions,uploads},tmp/panel/{sessions,uploads},.svc/php/multilog,.svc/panel/multilog,sys}
chown -R $user:$user etc home log tmp
chown $user:$http_user home tmp log sys
chown log:log .svc/php/multilog
chown log:log .svc/panel/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

for p in panel php; do

    if [ "$p" == 'panel' ]; then
        php_memory='256'
	http_post='100'
    fi

    cat << EOF > .svc/$p/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="$web_root/\$user/etc/$p"
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/$p/log
#!/bin/ash
exec setuidgid log /cmd/multilog t ./multilog
EOF

    chmod 755 .svc/$p/{run,log}

    echo $php_version > etc/$p/version

    cat << EOF > etc/$p/php.conf
[global]
daemonize = no
error_log = $web_root/$user/log/$p/php.log
[$user]
user = $user
group = $http_user
listen = $web_root/$user/.svc/$p/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
# admin configurable options
# php_admin_flag[var] = on/off (boolean)
# php_admin_value[var] = string
#   user cannot configure these via PHP code
php_admin_flag[log_errors] = on
php_admin_flag[display_errors] = off
php_admin_flag[display_startup_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_admin_value[sendmail_path] = /cmd/sendmail -t -i -f noreply
php_admin_value[error_log] = $web_root/$user/log/$p/php.log
# open_base_dir restricts scripts' write path to this parent folder
php_admin_value[sys_temp_dir] = $web_root/$user/tmp/$p
#php_admin_value[open_base_dir] = $web_root/$user/tmp/$p
php_admin_value[upload_tmp_dir] = $web_root/$user/tmp/$p/uploads
php_admin_value[session.save_path] = $web_root/$user/tmp/$p/sessions
# user confgurable options
#   php_flag[var] = on/off (boolean)
#   php_value[var] = string
#   user can change these via PHP code
php_value[date.timezone] = "Africa/Johannesburg"
EOF

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

    cd /svc

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

    svstat "/svc/$user-$p"

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

done

cat << EOF > /etc/nginx/hosts/$user
server {
    listen $host_ip:80;
    server_name $vhost_nginx;

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

    access_log $web_root/$user/home/default/log/access.log combined;
    error_log $web_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:$web_root/$user/.svc/php/sock;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        fastcgi_param  TMPDIR $web_root/$user/tmp/php;
        fastcgi_read_timeout 60;
    }
}
EOF

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

[[ ! -d /etc/nginx/auth/$user ]] && mkdir -p /etc/nginx/auth/$user

zweb-htpasswd $user $user_passwd > /etc/nginx/auth/$user/panel

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

# TODO: generate and test new letsencrypt cert

cat << EOF > /etc/nginx/panel/$user
server {
    listen $host_ip:80;
    server_name $user.zootzone.net;
    rewrite ^/(.*)$ https://$user.zootzone.net/\$1 permanent;
}
server {
    listen $host_ip:443;
    server_name $user.zootzone.net;

    ssl on;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_dhparam /etc/ssl/crt/dhparam.pem;

    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA';

    ssl_prefer_server_ciphers on;
    ssl_certificate /etc/ssl/crt/${user}_zootzone_net.chain;
    ssl_certificate_key /etc/ssl/key/${user}_zootzone_net.key;

    access_log /srv/web/$user/log/panel/access.log combined;
    error_log /srv/web/$user/log/panel/error.log error;

    client_max_body_size 100m;

    root /srv/web/panel;

    index index.php index.html;

    error_page 401 =401 /error/401.html;
    error_page 404 =404 /error/404.html;

    location ^~ /error/ {
        internal;
    }

    location / {
        auth_basic "Panel";
        auth_basic_user_file /etc/nginx/auth/$user/panel;
    }
    location /files/home {
        alias /srv/web/$user/home;
    }
    location /files/log {
        alias /srv/web/$user/log;
    }
    location /files/sys {
        alias /srv/web/$user/sys;
    }
    location ~* \.php {
        fastcgi_pass   unix:/srv/web/$user/.svc/panel/sock;
        fastcgi_index  index.php;
        include        fastcgi_params;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param  TMPDIR /srv/web/$user/tmp/panel;
        fastcgi_param  HOME_ROOT /srv/web/$user/home;
        fastcgi_param  LOG_ROOT /srv/web/$user/log;
        fastcgi_param  SYS_ROOT /srv/web/$user/sys;
    }
}
EOF

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

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

cat << EOF > $web_root/$user/home/default/public/index.html
<html>
  <head>
    <title>$vhost</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <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 $web_root/$user/home/default/public/index.html

cat << EOF > $web_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