Skip to content

Instantly share code, notes, and snippets.

@cleitonfco
Created November 26, 2010 18:44
Show Gist options
  • Save cleitonfco/717075 to your computer and use it in GitHub Desktop.
Save cleitonfco/717075 to your computer and use it in GitHub Desktop.
Scripts usados para criar um subdomínio com usuário novo no Linux
#!/usr/bin/expect -f
# Password change shell script, tested on Linux and FreeBSD
# ----------------------------------
# Copyright (c) 2006 nixCraft project
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# display usage
if {$argc!=2} {
send_user "usage: $argv0 username password \n"
exit
}
# script must be run by root user
set whoami [exec id -u]
if {$whoami!=0} {
send_user "You must be a root user to run this script\n"
exit
}
set timeout -1
match_max 100000
set password [lindex $argv 1]
# set user [lindex $argv 0]
spawn passwd [lindex $argv 0]
# send -- "passwd $user\r"
expect "assword:"
send -- "$password\r"
expect "assword:"
send -- "$password\r"
# send -- "\r"
expect eof
<VirtualHost IP_SERVIDOR:80>
ServerAdmin %usersub%@%domain%
ServerName %usersub%.%domain%
DocumentRoot /home/%userdomain%/subdomains/%usersub%
<Directory /home/%userdomain%/subdomains/%usersub%/>
Options FollowSymLinks
AllowOverride All
</Directory>
LogLevel notice
CustomLog /home/%userdomain%/logs/%usersub%_access_log combined
ErrorLog /home/%userdomain%/logs/%usersub%_error_log
ServerSignature On
</VirtualHost>
#!/usr/bin/ruby
require 'fileutils'
if ARGV.length > 0
usersub = ARGV[0]
passuser = ARGV[1]
else
print "Username: "
usersub = gets.chomp
print "Password: "
passuser = gets.chomp
end
domain = "se7ima.com.br"
userdomain = "se7ima"
FileUtils.mkdir_p "/home/#{userdomain}/subdomains/#{usersub}"
system("useradd -p senha-criptografada-ou-nao-afinal-de-contas-vai-ser-alterada-mesmo -g www-data -d /home/#{userdomain}/subdomains/#{usersub}/ #{usersub}")
FileUtils.chown_R usersub, 'www-data', "/home/#{userdomain}/subdomains/#{usersub}"
f = File.open('sub.conf')
lines = f.readlines
copy = ''
lines.each do |l|
copy << l.gsub(/%userdomain%/sm, userdomain).gsub(/%domain%/, domain).gsub(/%usersub%/, usersub)
end
File.open("/etc/apache2/sites-available/#{userdomain}.#{usersub}", 'w') { |f| f.write(copy) }
system("a2ensite #{userdomain}.#{usersub}")
system("./change_pass #{usersub} #{passuser}")
system("/etc/init.d/apache2 reload")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment