Class ServerSpecification
In: app/models/server_specification.rb
Parent: Object

Methods

Public Class methods

[Source]

     # File app/models/server_specification.rb, line 103
103:     def get_fields
104:       info = YAML::load_file(CONFIG_FILE_PATH) rescue nil
105:       port = SERVER_PORT
106:       min_worker = MIN_WORKERS
107:       max_worker = MAX_WORKERS                                                          
108:       log_level = LOG_LEVEL
109:       access_log = ACCESS_LOG
110:       ssl_support = ""
111:       ssl_port = ""
112:       certificate = ""
113:       key = ""
114:       if (info and info['Server Specification'])
115:         port = info['Server Specification']['port'].to_i if info['Server Specification']['port']
116:         min_worker = info['Server Specification']['min_worker'].to_i if info['Server Specification']['min_worker']
117:         max_worker = info['Server Specification']['max_worker'].to_i if info['Server Specification']['max_worker']
118:         log_level = info['Server Specification']['log_level'] if info['Server Specification']['log_level']
119:         access_log = info['Server Specification']['access_log'].capitalize if info['Server Specification']['access_log']
120:         if info['Server Specification']['SSL Specification']
121:           ssl_support = info['Server Specification']['SSL Specification']['ssl_support'] if info['Server Specification']['SSL Specification']['ssl_support']
122:           ssl_port = info['Server Specification']['SSL Specification']['ssl_port'] if info['Server Specification']['SSL Specification']['ssl_port']
123:           certificate = info['Server Specification']['SSL Specification']['certificate_file'] if info['Server Specification']['SSL Specification']['certificate_file']
124:           key = info['Server Specification']['SSL Specification']['key_file'] if info['Server Specification']['SSL Specification']['key_file']
125:         end
126:       end
127:       return port, min_worker, max_worker, log_level, ssl_support, ssl_port, certificate, key, access_log
128:     end

[Source]

     # File app/models/server_specification.rb, line 130
130:     def get_hash      
131:       port, min_worker, max_worker, log_level, ssl_support, ssl_port, certificate, key, access_log = get_fields
132:       
133:       if ssl_support.length < 1
134:         server_specification = Hash['port' => port, 'min_worker' => min_worker, 'max_worker' => max_worker, 'log_level' => log_level, 'access_log' => access_log.downcase]
135:       elsif ssl_support == "enabled"
136:         ssl_specification = Hash['ssl_support' => 'enabled' , 'certificate_file' => certificate, 'key_file' => key, 'ssl_port' => ssl_port]
137:         server_specification = Hash['port' => port, 'min_worker' => min_worker, 'max_worker' => max_worker, 'log_level' => log_level, 'access_log' => access_log.downcase, 'SSL Specification' => ssl_specification]
138:       else
139:         ssl_specification = Hash['ssl_support' => 'disabled', 'certificate_file' => certificate, 'key_file' => key, 'ssl_port' => ssl_port]
140:         server_specification = Hash['port' => port, 'min_worker' => min_worker, 'max_worker' => max_worker, 'log_level' => log_level, 'access_log' => access_log.downcase, 'SSL Specification' => ssl_specification]
141:       end      
142:       return server_specification
143:     end

[Source]

    # File app/models/server_specification.rb, line 24
24:     def validate_and_write(field, data)
25:       port, min_worker, max_worker, log_level, ssl_support, ssl_port, certificate, key, access_log = ServerSpecification.get_fields
26:       info = YAML::load_file(CONFIG_FILE_PATH) rescue nil      
27:       error_message = ''
28:       case field
29:       when 'port_div'
30:         if data =~ /^\d+$/ and data.to_i > 0 and data.to_i < 65535
31:           port = data.to_i
32:         else
33:           error_message = SERVER_PORT_VALIDATION
34:         end
35:         text = port
36:       when 'min_pro_div'
37:         if data =~ /^\d+$/ and data.to_i > 0 and data.to_i <= ALLOWED_MAX_WORKERS and data.to_i <= info['Server Specification']['max_worker'].to_i
38:           min_worker = data.to_i
39:         else
40:           error_message = MINIMUM_WORKERS_VALIDATION
41:         end
42:         text = min_worker
43:       when 'max_pro_div'
44:         if data =~ /^\d+$/ and data.to_i > 0 and data.to_i <= ALLOWED_MAX_WORKERS and data.to_i >= info['Server Specification']['min_worker'].to_i
45:           max_worker = data.to_i
46:         else
47:           error_message = MAXIMUM_WORKERS_VALIDATION
48:         end
49:         text = max_worker
50:       when 'ssl_port_div'
51:         if data =~ /^\d+$/ and data.to_i > 0 and data.to_i < 65535
52:           ssl_port = data.to_i
53:         else
54:           error_message = SSL_PORT_VALIDATION
55:         end
56:         text = ssl_port
57:       when 'certificate_div'
58:         if data.length > 0 and /^\/.*(\.crt)$/.match(data) and File.file?(data)
59:           certificate = data    
60:         else
61:           error_message = SSL_CERTIFICATE_FILE_PATH_VALIDATION1
62:         end
63:         text = certificate
64:       when 'key_div'
65:         if data.length > 0 and /^\/.*(\.key)$/.match(data) and File.file?(data)
66:           key = data
67:         else
68:           error_message = SSL_KEY_FILE_PATH_VALIDATION1
69:         end
70:         text = key
71:       when 'log_div'
72:         log_level = data
73:         text = log_level
74:       when 'access_log_div'
75:         access_log = data
76:         text = access_log
77:       end       
78:       if ssl_support.length < 1
79:         server_specification = Hash['port' => port, 'min_worker' => min_worker, 'max_worker' => max_worker, 'log_level' => log_level, 'access_log' => access_log.downcase]
80:       elsif ssl_support == "enabled"
81:         ssl_specification = Hash['ssl_support' => 'enabled', 'certificate_file' => certificate, 'key_file' => key, 'ssl_port' => ssl_port]
82:         server_specification = Hash['port' => port, 'min_worker' => min_worker, 'max_worker' => max_worker, 'log_level' => log_level, 'access_log' => access_log.downcase, 'SSL Specification' => ssl_specification]
83:       else
84:         ssl_specification = Hash['ssl_support' => 'disabled' , 'certificate_file' => certificate, 'key_file' => key, 'ssl_port' => ssl_port]
85:         server_specification = Hash['port' => port, 'min_worker' => min_worker, 'max_worker' => max_worker, 'log_level' => log_level, 'access_log' => access_log.downcase, 'SSL Specification' => ssl_specification]
86:       end
87:       ServerSpecification.write(info, server_specification) if error_message.length == 0
88:       return text, error_message
89:     end

Method is use to write server specification into the config file

[Source]

     # File app/models/server_specification.rb, line 93
 93:     def write(info, server_specification)
 94:       if info and info['Application Specification']
 95:         application_specification = info['Application Specification']
 96:         data = Hash['Server Specification' => server_specification, 'Application Specification' => application_specification]
 97:       else
 98:         data = Hash['Server Specification' => server_specification]
 99:       end
100:       YAMLWriter.write(data,CONFIG_FILE_PATH, "config")
101:     end

[Validate]