Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # Informations a completer
- pass_mysql_ftp="MYSQL-FTP-PASS"
- pass_mysql_root="MYSQL-ROOT-PASS"
- pass_mysql_postfix="MYSQL-POSTFIX-PASS"
- # On demande la saisie d-un nom d'utilisateur et du mot de passe (2 fois)
- DATE=`date "+%Y-%m-%d %H:%M:%S"`
- DOC='$document_root$fastcgi_script_name'
- try_files='try_files $uri $uri/ /index.html;'
- echo -n "Nom d'utilisateur : "
- read nom
- echo "Mot de passe : "
- read pass
- echo "Mot de passe (le retour) : "
- read pass2
- hashedpassword=`openssl passwd -1 $pass`
- user="$nom@MONDOMAIN.TLD"
- # On verifie que les 2 mots de passe soient identiques
- if test $pass = $pass2 ; then
- # On verifie qu-il n'existe pas un autre utilisateur du meme nom
- if test -d /home/$nom ; then
- echo "L'utilisateur existe deja"
- else
- # On creer les dossiers et on fixe les droits
- mkdir /DATA/WEB/$nom
- mkdir /DATA/WEB/$nom/www
- # On ajoute l'utilisateur dans la bdd ftp
- mysql -u ftp -p"$pass_mysql_ftp" -D ftp -e "INSERT INTO utilisateurs (User ,Password ,Uid ,Gid ,Dir) VALUES ('$nom', MD5( '$pass' ) , '33',
- '33', '/DATA/WEB/$nom');"
- # On creer une base de donneees ou l'utilisateur est tout-puissant
- mysql -u root -p"$pass_mysql_root" -e "CREATE USER '$nom'@'localhost' IDENTIFIED BY '$pass';GRANT USAGE ON *.* TO '$nom'@'localhost' IDENTIFIED BY '$pass' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;CREATE DATABASE IF NOT EXISTS $nom;GRANT ALL PRIVILEGES ON $nom.* TO '$nom'@'localhost';"
- # On crée le fichier de configuration pour vsFTPd
- echo "anon_world_readable_only=NO" > /etc/vsftpd/vsftpd_user_conf/$nom
- echo "local_root=/DATA/WEB/$nom" >> /etc/vsftpd/vsftpd_user_conf/$nom
- echo "write_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
- echo "anon_upload_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
- echo "anon_mkdir_write_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
- echo "anon_other_write_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
- echo "hide_file=(none)" >> /etc/vsftpd/vsftpd_user_conf/$nom
- echo "force_dot_files=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
- # On ajoute l'utilisateur dans la bdd postfixadmin
- mysql -u postfix -p"$pass_mysql_postfix" -D postfix -e "INSERT INTO mailbox (username ,password ,name ,maildir ,quota ,local_part ,domain ,created ,modified ,active) VALUES ('$nom@MONDOMAIN.TLD', '$hashedpassword', '$nom', 'MONDOMAIN.TLD/$nom/', '2048000000', '$nom', 'MONDOMAIN.TLD', 'DATE' ,'DATE' ,'1');"
- mysql -u postfix -p"$pass_mysql_postfix" -D postfix -e "INSERT INTO alias (address ,goto ,domain ,created ,modified ,active) VALUES ('$nom@MONDOMAIN.TLD', '$nom@MONDOMAIN.TLD', 'MONDOMAIN.TLD', 'DATE' ,'DATE' ,'1');"
- #on ajoute l'utilisateur a nextcloud
- export OC_PASS=$pass
- su -s /bin/sh www-data -c 'php /DATA/WEB/cloud/occ user:add --password-from-env --display-name="$nom" --group=users '$user''
- #on creer le vhost nginx
- cat >/etc/nginx/sites-available/$nom.conf <<EOF
- ##
- # You should look at the following URL's in order to grasp a solid understanding
- # of Nginx configuration files in order to fully unleash the power of Nginx.
- # http://wiki.nginx.org/Pitfalls
- # http://wiki.nginx.org/QuickStart
- # http://wiki.nginx.org/Configuration
- #
- # Generally, you will want to move this file somewhere, and start with a clean
- # file but keep this around for reference. Or just disable in sites-enabled.
- #
- # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
- ##
- # Default server configuration
- #
- server {
- listen 80;
- listen [::]:80;
- access_log /var/log/nginx/$nom.log;
- error_log /var/log/nginx/$nom.err;
- root /DATA/WEB/$nom/www;
- # Add index.php to the list if you are using PHP
- index index.php index.html index.htm index.nginx-debian.html;
- server_name $nom.MONDOMAIN.TLD www.$nom.MONDOMAIN.TLD;
- # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
- #
- #location ~ \.php$ {
- # include snippets/fastcgi-php.conf;
- #
- # # With php5-cgi alone:
- # fastcgi_pass 127.0.0.1:9000;
- # # With php5-fpm:
- # fastcgi_pass unix:/var/run/php5-fpm.sock;
- #}
- location / {
- # First attempt to serve request as file, then
- # as directory, then fall back to displaying a 404.
- $try_files
- # Uncomment to enable naxsi on this location
- # include /etc/nginx/naxsi.rules
- }
- location ~ \.php$ {
- fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;}
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME $DOC;
- include fastcgi_params;
- fastcgi_split_path_info ^(.+\.php)(/.+)$;
- # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
- location ~ /\.ht {
- deny all;
- }
- # deny access to .htaccess files, if Apache's document root
- # concurs with nginx's one
- #
- #location ~ /\.ht {
- # deny all;
- #}
- }
- #server {
- # listen 443 ssl http2;
- # listen [::]:443 ssl http2;
- #
- # auth_basic "Restricted";
- # auth_basic_user_file /usr/share/nginx/www/.htpasswd;
- # root /DATA/WEB/$nom/www;
- # index index.php index.html index.htm;
- # try_files $uri $uri/ /;
- #access_log /var/log/nginx/$nom.log;
- #error_log /var/log/nginx/$nom.err;
- # # Make site accessible from http://localhost/
- # server_name $nom.MONDOMAIN.TLD www.$nom.MONDOMAIN.TLD;
- ##
- ##SSL
- #include /etc/nginx/ssl/params.conf;
- # ssl_certificate /etc/letsencrypt/live/$nom.MONDOMAIN.TLD/fullchain.pem;
- # ssl_certificate_key /etc/letsencrypt/live/$nom.MONDOMAIN.TLD/privkey.pem;
- #
- # location / {
- # # First attempt to serve request as file, then
- # # as directory, then fall back to displaying a 404.
- # try_files $uri $uri/ /index.html;
- # # Uncomment to enable naxsi on this location
- # # include /etc/nginx/naxsi.rules
- # }
- #
- #location ~ \.php$ {
- # fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;}
- # fastcgi_index index.php;
- # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- # include fastcgi_params;
- # fastcgi_split_path_info ^(.+\.php)(/.+)$;
- # # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
- #
- #location ~ /\.ht {
- # deny all;
- #}
- #}
- EOF
- ln -s /etc/nginx/sites-available/$nom.conf /etc/nginx/sites-enabled/$nom.conf
- #on crer un fichier index.php de base
- cat >/DATA/WEB/$nom/www/index.php<<EOF
- <!DOCTYPE html>
- <html>
- <head>
- <title>Bienvenue sur l'espace web de $nom</title>
- <style>
- body {
- width: 35em;
- margin: 0 auto;
- font-family: Tahoma, Verdana, Arial, sans-serif;
- }
- </style>
- </head>
- <body>
- <h1>Bienvenue sur l'espace web de $nom</h1>
- <p>Si vous voyez cette page, le serveur Web nginx est installé avec succès et
- fonctionne.</p>
- <p>
- <a href="../info.php">info php</a>.</p>
- </p>
- <!-- IPv6-test.com button BEGIN -->
- <a href='http://ipv6-test.com/validate.php?url=https://$nom.MONDOMAIN.TLD'><img src='http://ipv6-test.com/button-ipv6-big.png' alt='ipv6 ready' title='ipv6 ready' border='0' /></a>
- <!-- IPv6-test.com button END -->
- </body>
- </html>
- EOF
- echo "<?php phpinfo(); ?>" >> /DATA/WEB/$nom/www/info.php
- chown -R www-data.www-data /DATA/WEB/$nom
- chmod -R 744 /DATA/WEB/$nom/www
- service vsftpd restart
- service postfix restart
- service mysql restart
- service nginx restart
- service vsftpd restart
- echo "Utilisateur ajoute avec succes"
- fi
- else
- echo "Les 2 mots de passe ne sont pas identiques"
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement