bin/vpnmaker in vpnmaker-1.0.10 vs bin/vpnmaker in vpnmaker-1.0.11
- old
+ new
@@ -1,38 +1,23 @@
#!/usr/bin/env ruby
require_relative '../lib/vpnmaker.rb'
#require 'micro-optparse'
#require 'highline'
+require 'ya_email_validator'
require 'highline/import'
require 'main'
+# This validates email addresses
+class String; include YaEmailValidator; end
+
#TODO: use ~/.vpnmaker .vpnmaker and /etc/vpnmaker | maybe vpnmakerrc
module VPNMaker
module CLI
- module RFC822
- EmailAddress = begin
- qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'
- dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'
- atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-' +
- '\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'
- quoted_pair = '\\x5c[\\x00-\\x7f]'
- domain_literal = "\\x5b(?:#{dtext}|#{quoted_pair})*\\x5d"
- quoted_string = "\\x22(?:#{qtext}|#{quoted_pair})*\\x22"
- domain_ref = atom
- sub_domain = "(?:#{domain_ref}|#{domain_literal})"
- word = "(?:#{atom}|#{quoted_string})"
- domain = "#{sub_domain}(?:\\x2e#{sub_domain})*"
- local_part = "#{word}(?:\\x2e#{word})*"
- addr_spec = "#{local_part}\\x40#{domain}"
- pattern = /\A#{addr_spec.force_encoding('ASCII-8BIT')}\z/
- end
- end
-
class Options
# main DSL
Main do
- version '0.0.1'
+ version File.read(File.expand_path("../..", __FILE__) + "/VERSION")
author 'Copyleft(cl) VoipScout - No rights reserved'
mode('init') {
mode('cli') {
argument('country') {
@@ -72,11 +57,11 @@
}
argument('email') {
required
cast :string
arity 1
- validate {|e| e =~ RFC822::EmailAddress}
+ validate {|e| e.email?}
}
} #mode 'cli'
argument('conf_name') {
@@ -88,50 +73,13 @@
required
cast :string
arity 1
validate {|dir| File.directory?(File.expand_path(dir))}
}
- def run
- name = params['conf_name'].value
- dir = params['new_dir_path'].value
- VPNMaker.generate name, dir
-
- data_dir = (File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + "_data")
- template_dir = (File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + "_templates")
- client_config_dir = (File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + "_client_configs")
-
- [data_dir, template_dir, client_config_dir].each {|dir| FileUtils.mkdir_p(dir)}
- lib_dir = File.dirname(File.expand_path __FILE__).gsub('/bin', '/lib')
- FileUtils.cp Dir.glob(lib_dir + "/*.haml"), template_dir
-
- if params['email'].given?
- initial_config = {
- :key_properties => {
- :country => params['country'].value,
- :province => params['province'].value,
- :city => params['city'].value,
- :organization => params['organization'].value,
- :organization_unit => params['organization_unit'].value,
- :common_name => params['common_name'].value,
- :name => params['key_name'].value,
- :email => params['email'].value
- },
- :site => {
- :data_dir => data_dir.split('/').last,
- :template_dir => template_dir.split('/').last,
- :client_conf_dir => client_config_dir.split('/').last
- }
- }
- example_config = YAML.load_file(lib_dir + "/example_vpnmaker_site.config.yaml").to_yaml.gsub(/\n|---/, "\n#")
- File.open((File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + ".config.yaml"), 'w') {|f| f.write(initial_config.to_yaml + example_config)}
- mgr = VPNMaker::Manager.new((File.expand_path(dir) + "/" + name + ".vpn"))
- mgr.build_ca
- say("Please edit files in #{template_dir} and #{dir}/#{name}.vpn/#{name}.config.yaml before proceeding further")
- else
- say('Time to mod yaml files')
- end
+ def run
+ get_init_config
end
}
mode('server') {
mode('build') {
@@ -292,26 +240,58 @@
puts "client run"
end
}
- # Global run() is overwritten by specific mode run
- def run
- puts "Hitting global run()"
- params.each {|p| pp "#{p.class} - #{p.name} => #{p.value}"}
- @opts = params
- pp @opts
- end
-
def db
VPNMaker::Manager.new params['dir'].value
end
+ def get_init_config
+ name = params['conf_name'].value
+ dir = params['new_dir_path'].value
- end #
+ VPNMaker.generate name, dir
- end #class Options
+ data_dir = (File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + "_data")
+ template_dir = (File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + "_templates")
+ client_config_dir = (File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + "_client_configs")
+ [data_dir, template_dir, client_config_dir].each {|dir| FileUtils.mkdir_p(dir)}
+ lib_dir = File.dirname(File.expand_path __FILE__).gsub('/bin', '/lib')
+ FileUtils.cp Dir.glob(lib_dir + "/*.haml"), template_dir
+
+ if params['email'].given?
+ initial_config = {
+ :key_properties => {
+ :country => params['country'].value,
+ :province => params['province'].value,
+ :city => params['city'].value,
+ :organization => params['organization'].value,
+ :organization_unit => params['organization_unit'].value,
+ :common_name => params['common_name'].value,
+ :name => params['key_name'].value,
+ :email => params['email'].value
+ },
+ :site => {
+ :data_dir => data_dir.split('/').last,
+ :template_dir => template_dir.split('/').last,
+ :client_conf_dir => client_config_dir.split('/').last
+ }
+ }
+
+ example_config = YAML.load_file(lib_dir + "/example_vpnmaker_site.config.yaml").to_yaml.gsub(/\n|---/, "\n#")
+ File.open((File.expand_path(dir) + "/" + name + ".vpn" + "/" + name + ".config.yaml"), 'w') {|f| f.write(initial_config.to_yaml + example_config)}
+ mgr = VPNMaker::Manager.new((File.expand_path(dir) + "/" + name + ".vpn"))
+ mgr.build_ca
+ say("Please edit files in #{template_dir} and #{dir}/#{name}.vpn/#{name}.config.yaml before proceeding further")
+ else
+ say('Time to mod yaml files')
+ end
+ end
+
+ end # Main {}
+ end #class Options
end #module CLI
end #module VPNMaker
VPNMaker::CLI::Options.new