adduser - warvox - VoIP based wardialing tool, forked from rapid7/warvox.
 (HTM) git clone git://jay.scot/warvox
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) 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 automatically required...
            6 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile',File.dirname(__FILE__))
            7 require 'bundler/setup'
            8 
            9 # rails/all must be required explicitly to get the railties that pro/ui/config/application.rb uses
           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)] + [*(0x7b .. 0x7e)] ).flatten.pack("C*")
           21   set << "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
           22   str = ''
           23   cnt = 0
           24   while not (str.length >= 8 and str =~ /[A-Za-z]/ and str =~ /[0-9]/ and str =~ /[\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x3a\x3b\x3c\x3d\x3e\x3f\x5b\x5c\x5d\x5e\x5f\x60\x7b\x7c\x7d\x7e]/)
           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 '#{randpass}' ..."
           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 your password on login."
           69 else
           70   $stdout.puts "[*] That user account already exists, please try 'resetpw' script"
           71 end