Advertisement
Guest User

superjey-mutu

a guest
Apr 16th, 2017
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 7.82 KB | None | 0 0
  1. #!/bin/sh
  2. # Informations a completer
  3. pass_mysql_ftp="MYSQL-FTP-PASS"
  4. pass_mysql_root="MYSQL-ROOT-PASS"
  5. pass_mysql_postfix="MYSQL-POSTFIX-PASS"
  6. # On demande la saisie d-un nom d'utilisateur et du mot de  passe (2 fois)
  7. DATE=`date "+%Y-%m-%d %H:%M:%S"`
  8. DOC='$document_root$fastcgi_script_name'
  9. try_files='try_files $uri $uri/ /index.html;'
  10. echo -n "Nom d'utilisateur : "
  11. read nom
  12. echo "Mot de passe : "
  13. read pass
  14. echo "Mot de passe (le retour) : "
  15. read pass2
  16. hashedpassword=`openssl passwd -1 $pass`
  17. user="$nom@MONDOMAIN.TLD"
  18. # On verifie que les 2 mots de passe soient identiques
  19. if test $pass = $pass2 ; then
  20.         # On verifie qu-il n'existe pas un autre utilisateur du meme nom
  21.         if test -d /home/$nom ; then
  22.                 echo "L'utilisateur existe deja"
  23.         else
  24.                 # On creer les dossiers et on fixe les droits
  25.                 mkdir /DATA/WEB/$nom
  26.                 mkdir /DATA/WEB/$nom/www
  27.  
  28.                 # On ajoute l'utilisateur dans la bdd ftp
  29.                 mysql -u ftp -p"$pass_mysql_ftp" -D ftp -e "INSERT INTO utilisateurs (User ,Password ,Uid ,Gid ,Dir) VALUES ('$nom', MD5( '$pass' ) , '33',
  30. '33', '/DATA/WEB/$nom');"
  31.                 # On creer une base de donneees ou l'utilisateur est tout-puissant
  32.                 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';"
  33.  
  34.                 # On crée le fichier de configuration pour vsFTPd
  35.  
  36.                 echo "anon_world_readable_only=NO" > /etc/vsftpd/vsftpd_user_conf/$nom
  37.                 echo "local_root=/DATA/WEB/$nom" >> /etc/vsftpd/vsftpd_user_conf/$nom
  38.                 echo "write_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
  39.                 echo "anon_upload_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
  40.                 echo "anon_mkdir_write_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
  41.                 echo "anon_other_write_enable=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
  42.                 echo "hide_file=(none)" >> /etc/vsftpd/vsftpd_user_conf/$nom
  43.                 echo "force_dot_files=YES" >> /etc/vsftpd/vsftpd_user_conf/$nom
  44.  
  45.         # On ajoute l'utilisateur dans la bdd postfixadmin
  46.         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');"
  47.         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');"
  48.  
  49.                 #on ajoute l'utilisateur a nextcloud
  50.  
  51.                 export OC_PASS=$pass
  52.                 su -s /bin/sh www-data -c 'php /DATA/WEB/cloud/occ user:add --password-from-env --display-name="$nom" --group=users '$user''
  53.  
  54.                 #on creer le vhost nginx
  55.                 cat >/etc/nginx/sites-available/$nom.conf <<EOF
  56. ##
  57. # You should look at the following URL's in order to grasp a solid understanding
  58. # of Nginx configuration files in order to fully unleash the power of Nginx.
  59. # http://wiki.nginx.org/Pitfalls
  60. # http://wiki.nginx.org/QuickStart
  61. # http://wiki.nginx.org/Configuration
  62. #
  63. # Generally, you will want to move this file somewhere, and start with a clean
  64. # file but keep this around for reference. Or just disable in sites-enabled.
  65. #
  66. # Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
  67. ##
  68.  
  69. # Default server configuration
  70. #
  71. server {
  72.     listen 80;
  73.     listen [::]:80;
  74.  
  75.     access_log /var/log/nginx/$nom.log;
  76.     error_log /var/log/nginx/$nom.err;
  77.     root /DATA/WEB/$nom/www;
  78.  
  79.     # Add index.php to the list if you are using PHP
  80.     index index.php index.html index.htm index.nginx-debian.html;
  81.  
  82.     server_name $nom.MONDOMAIN.TLD www.$nom.MONDOMAIN.TLD;
  83.  
  84.     # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  85.     #
  86.     #location ~ \.php$ {
  87.     #   include snippets/fastcgi-php.conf;
  88.     #
  89.     #   # With php5-cgi alone:
  90.     #   fastcgi_pass 127.0.0.1:9000;
  91.     #   # With php5-fpm:
  92.     #   fastcgi_pass unix:/var/run/php5-fpm.sock;
  93.     #}
  94.         location / {
  95.                 # First attempt to serve request as file, then
  96.                 # as directory, then fall back to displaying a 404.
  97.                 $try_files
  98.                 # Uncomment to enable naxsi on this location
  99.                 # include /etc/nginx/naxsi.rules
  100.         }
  101. location ~ \.php$ {
  102.         fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;}
  103.         fastcgi_index index.php;
  104.         fastcgi_param SCRIPT_FILENAME $DOC;
  105.         include fastcgi_params;
  106.       fastcgi_split_path_info ^(.+\.php)(/.+)$;
  107.       # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  108.  
  109. location ~ /\.ht {
  110.         deny all;
  111. }
  112.  
  113.     # deny access to .htaccess files, if Apache's document root
  114.     # concurs with nginx's one
  115.     #
  116.     #location ~ /\.ht {
  117.     #   deny all;
  118.     #}
  119. }
  120.  
  121. #server {
  122. #        listen 443 ssl http2;
  123. #        listen [::]:443 ssl http2;
  124. #
  125. #       auth_basic "Restricted";
  126. #       auth_basic_user_file /usr/share/nginx/www/.htpasswd;
  127. #        root /DATA/WEB/$nom/www;
  128. #        index index.php index.html index.htm;
  129. #        try_files $uri $uri/ /;
  130. #access_log /var/log/nginx/$nom.log;
  131. #error_log /var/log/nginx/$nom.err;
  132. #        # Make site accessible from http://localhost/
  133. #        server_name $nom.MONDOMAIN.TLD www.$nom.MONDOMAIN.TLD;
  134. ##
  135. ##SSL
  136. #include /etc/nginx/ssl/params.conf;
  137. #        ssl_certificate /etc/letsencrypt/live/$nom.MONDOMAIN.TLD/fullchain.pem;
  138. #        ssl_certificate_key /etc/letsencrypt/live/$nom.MONDOMAIN.TLD/privkey.pem;
  139. #
  140. #        location / {
  141. #                # First attempt to serve request as file, then
  142. #                # as directory, then fall back to displaying a 404.
  143. #                try_files $uri $uri/ /index.html;
  144. #                # Uncomment to enable naxsi on this location
  145. #                # include /etc/nginx/naxsi.rules
  146. #        }
  147. #
  148. #location ~ \.php$ {
  149. #        fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;}
  150. #        fastcgi_index index.php;
  151. #        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  152. #        include fastcgi_params;
  153. #      fastcgi_split_path_info ^(.+\.php)(/.+)$;
  154. #      # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
  155. #
  156. #location ~ /\.ht {
  157. #        deny all;
  158. #}
  159. #}
  160. EOF
  161.  
  162.                 ln -s /etc/nginx/sites-available/$nom.conf /etc/nginx/sites-enabled/$nom.conf
  163.  
  164.                 #on crer un fichier index.php de base
  165.                 cat >/DATA/WEB/$nom/www/index.php<<EOF
  166. <!DOCTYPE html>
  167. <html>
  168. <head>
  169. <title>Bienvenue sur l'espace web de $nom</title>
  170. <style>
  171.     body {
  172.         width: 35em;
  173.         margin: 0 auto;
  174.         font-family: Tahoma, Verdana, Arial, sans-serif;
  175.     }
  176. </style>
  177. </head>
  178. <body>
  179. <h1>Bienvenue sur l'espace web de $nom</h1>
  180. <p>Si vous voyez cette page, le serveur Web nginx est installé avec succès et
  181. fonctionne.</p>
  182. <p>
  183. <a href="../info.php">info php</a>.</p>
  184. </p>
  185. <!-- IPv6-test.com button BEGIN -->
  186. <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>
  187. <!-- IPv6-test.com button END -->
  188. </body>
  189. </html>
  190. EOF
  191.                
  192.  
  193.                 echo "<?php phpinfo(); ?>" >> /DATA/WEB/$nom/www/info.php
  194.                 chown -R www-data.www-data /DATA/WEB/$nom
  195.                 chmod -R 744 /DATA/WEB/$nom/www
  196.                 service vsftpd restart
  197.         service postfix restart
  198.         service mysql restart
  199.         service nginx restart
  200.         service vsftpd restart
  201.  
  202.         echo "Utilisateur ajoute avec succes"
  203.         fi
  204. else
  205.         echo "Les 2 mots de passe ne sont pas identiques"
  206. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement