| adduser - warvox - VoIP based wardialing tool, forked from rapid7/warvox. | |
| git clone git://jay.scot/warvox | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| adduser (2116B) | |
| --- | |
| 1 #!/usr/bin/env ruby | |
| 2 | |
| 3 ENV['RAILS_ENV'] ||= 'production' | |
| 4 | |
| 5 # bundler/setup just sets up the $LOAD_PATHs, the gems aren't automatica… | |
| 6 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile',File.dirname(__F… | |
| 7 require 'bundler/setup' | |
| 8 | |
| 9 # rails/all must be required explicitly to get the railties that pro/ui/… | |
| 10 require 'rails/all' | |
| 11 # require all the gems in the current environment | |
| 12 Bundler.require(*Rails.groups(assets: %w(development test cucumber))) | |
| 13 | |
| 14 APP_PATH = File.expand_path('../../config/application', __FILE__) | |
| 15 require File.expand_path('../../config/boot', __FILE__) | |
| 16 require APP_PATH | |
| 17 Rails.application.require_environment! | |
| 18 | |
| 19 def generate_password | |
| 20 set = ( [*(0x21 .. 0x2f)] + [*(0x3a .. 0x3F)] + [*(0x5b .. 0x60)] + [*… | |
| 21 set << "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | |
| 22 str = '' | |
| 23 cnt = 0 | |
| 24 while not (str.length >= 8 and str =~ /[A-Za-z]/ and str =~ /[0-9]/ an… | |
| 25 if str.length > 12 | |
| 26 str = str[0,4] | |
| 27 next | |
| 28 end | |
| 29 str << set[ rand(set.length), 1] | |
| 30 cnt += 1 | |
| 31 end | |
| 32 str | |
| 33 end | |
| 34 | |
| 35 | |
| 36 username = ARGV.shift | |
| 37 password = ARGV.shift | |
| 38 | |
| 39 user = username ? User.find_by_login(username) : nil | |
| 40 | |
| 41 if not user | |
| 42 | |
| 43 if ! username | |
| 44 $stdout.write "[*] Please enter a username: " | |
| 45 $stdout.flush | |
| 46 username = $stdin.readline.strip | |
| 47 end | |
| 48 | |
| 49 if ! (username and username.strip.length > 0) | |
| 50 $stdout.puts "[-] Invalid username specified" | |
| 51 exit(0) | |
| 52 end | |
| 53 | |
| 54 if not password | |
| 55 randpass = generate_password | |
| 56 $stdout.puts "" | |
| 57 $stdout.puts "[*] Creating user '#{username}' with password '#{randp… | |
| 58 $stdout.puts "" | |
| 59 password = randpass | |
| 60 end | |
| 61 | |
| 62 user = User.new() | |
| 63 user.login = username | |
| 64 user.password = password | |
| 65 user.password_confirmation = password | |
| 66 user.save! | |
| 67 | |
| 68 $stdout.puts "[*] User #{user.login} has been created, please change y… | |
| 69 else | |
| 70 $stdout.puts "[*] That user account already exists, please try 'resetp… | |
| 71 end |