1 # Mwamko Copyright (C) 2007 Aleksandr O. Levchuk
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # Constants of Mwamko are defined here. This includes:
17 # * Paths to External Configuration
21 # * Network Configuration
22 # * Safety/Strength contracts
24 # Mwamko has to be restarted when this file is changed
25 # Run: ./script/mwamko restart
27 # Path to External Configuration
28 EXTERNAL_CONFIGURATION_DIR = '/etc/mwamko'
29 ALLOWED_EMAILS_FILE = "#{EXTERNAL_CONFIGURATION_DIR}/allowed_emails.list"
30 require "#{EXTERNAL_CONFIGURATION_DIR}/available_ip_addresses.range.rb"
31 require "#{EXTERNAL_CONFIGURATION_DIR}/available_local_ip_addresses.range.rb"
32 require "#{EXTERNAL_CONFIGURATION_DIR}/dns.settings.rb"
34 # The directory path and the file name of this script
35 module MwamkoConstants
36 SCRIPT_DIR = File.dirname(File.expand_path(__FILE__))
37 SCRIPT_NAME = $0.split('/')[-1]
40 # The path to all files of Mwamko
41 RAILS_ROOT = File.expand_path("#{MwamkoConstants::SCRIPT_DIR}/..")
43 # The user that is running Mwamko
44 WHOAMI = `whoami`.chomp
47 VZTOOLS_PATH = '/usr/sbin'
48 GIT = '/usr/local/bin/git'
49 RUBY_PATH = '/usr/bin/env ruby'
50 SUDO = '/usr/bin/sudo'
51 TOUCH = '/usr/bin/touch'
57 TAIL = '/usr/bin/tail'
59 LIGHTTPD = '/usr/bin/env lighttpd'
60 SPAWNER_PATH = '"/usr/bin/env spawn-fcgi"' # comes with Lighttpd
67 "-o StrictHostKeyChecking=yes",
68 "-o UserKnownHostsFile=#{RAILS_ROOT}/tmp/ssh_known_hosts ",
69 "-i #{RAILS_ROOT}/tmp/ssh_id"
72 if !ENV.has_key? "RAILS_ENV"
73 raise "ENV['RAILS_ENV'] is not set!"
77 if ![:development, :test, :production].include? ENV['RAILS_ENV'].to_sym
78 raise "ENV['RAILS_ENV'] is #{ENV['RAILS_ENV'].inspect}.\n" +
79 "That's not a valid Rails Environment."
82 # Network Configuration
83 # To learn more run: ./script/process/spawner --help
84 SPAWNER_PLATFORM = 'fcgi'
85 RESPAWN_PERIOD = 100000000 # Repeat spawn attempts every 3 years
87 # The following can be configured differently per environment
89 lighttpd_port[:development] = 7000
90 lighttpd_port[:test] = 8000
91 lighttpd_port[:production] = 1024
94 lighttpd_bind[:development] = '0.0.0.0'
95 lighttpd_bind[:test] = '0.0.0.0'
96 lighttpd_bind[:production] = '0.0.0.0'
98 DISPATCHER_URL = '/dispatch.fcgi'
99 DISPATCHER_BIND = '0.0.0.0'
100 dispatcher_starting_port = {}
101 dispatcher_starting_port[:development] = 7001
102 dispatcher_starting_port[:test] = 8001
103 dispatcher_starting_port[:production] = 9001
105 dispatcher_num_instances = {}
106 dispatcher_num_instances[:development] = 5
107 dispatcher_num_instances[:test] = 5
108 dispatcher_num_instances[:production] = 5
110 AJAXTERM_BIND = '0.0.0.0'
111 ajaxterm_starting_port = {}
112 ajaxterm_starting_port[:development] = 7001
113 ajaxterm_starting_port[:test] = 8001
114 ajaxterm_starting_port[:production] = 9000
115 # The number of instances will be the total number of available ips
116 # See: /etc/mwamko/available_ip_addresses.range
118 # The following code will form Constants out of the development/test/production
119 # triple local hashes according to the current environment
120 local_variables.each do |name|
123 finger_print = [var.has_key?(:development),
125 var.has_key?(:production)]
126 if finger_print == [false, false, false] # This is not the Hash the we need
128 elsif finger_print == [true, true, true] # This is the one
129 new_constant = name.upcase
130 eval "#{new_constant}=#{name}[ENV['RAILS_ENV'].to_sym]"
132 STDERR.puts "There is possibly a spelling error in the keys of #{name}:"
133 STDERR.puts " #{var.keys.inspect}"
141 # Mwamko is not yet able to manage multiple templates
142 # that is why this code block returns an array of only ONE element
143 GET_TEMPLATES = Proc.new {["debian-4.0-i386-minimal"]}
147 SAFE_PASSWORD = /\A([a-zA-Z0-9%!@$&*()^# ])+\Z/
148 SAFE_EMAIL = /\A[[:alnum:]\+\._]+@[[:alnum:]\-\.]+\Z/
149 SAFE_USERNAME = /\A[a-z0-9_]+\Z/
150 SAFE_VEID = /\A[0-9]+\Z/
151 SAFE_UID = /\A[0-9]+\Z/
152 SAFE_IP4 = /\A\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\Z/
153 SAFE_NETIF_NAME = /\A[a-z0-9]+\Z/
158 def PASSWORD_IS_STRONG(password)
161 extract_alpha = password.scan(/[[:alpha:]]/).join('')
162 cmd = "grep -i \"^#{extract_alpha}$\" #{MwamkoConstants::SCRIPT_DIR}" +
167 has_nonalpha = password =~ /[^[:alpha:]]/
168 long = (password.size >= 8)
169 has_alpha = password =~ /[[:alpha:]]/
171 return(not_a_word and has_nonalpha and long and has_alpha)