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:     
115:       if (info and info['Server Specification'])
116:         port = info['Server Specification']['port'].to_i if info['Server Specification']['port']
117:         min_worker = info['Server Specification']['min_worker'].to_i if info['Server Specification']['min_worker']
118:         max_worker = info['Server Specification']['max_worker'].to_i if info['Server Specification']['max_worker']
119:         log_level = info['Server Specification']['log_level'] if info['Server Specification']['log_level']
120:         access_log = info['Server Specification']['access_log'].capitalize if info['Server Specification']['access_log']
121:         if info['Server Specification']['SSL Specification']
122:           ssl_support = info['Server Specification']['SSL Specification']['ssl_support'] if info['Server Specification']['SSL Specification']['ssl_support']
123:           ssl_port = info['Server Specification']['SSL Specification']['ssl_port'] if info['Server Specification']['SSL Specification']['ssl_port']
124:           certificate = info['Server Specification']['SSL Specification']['certificate_file'] if info['Server Specification']['SSL Specification']['certificate_file']
125:           key = info['Server Specification']['SSL Specification']['key_file'] if info['Server Specification']['SSL Specification']['key_file']
126:         end
127:       end
128:       return port, min_worker, max_worker, log_level, ssl_support, ssl_port, certificate, key, access_log
129:     end

[Source]

     # File app/models/server_specification.rb, line 131
131:     def get_hash      
132:       port, min_worker, max_worker, log_level, ssl_support, ssl_port, certificate, key, access_log = get_fields
133:       
134:       if ssl_support.length < 1
135:         server_specification = Hash['port'=>port,'min_worker'=>min_worker,'max_worker'=>max_worker,'log_level'=>log_level,'access_log'=>access_log.downcase]
136:       elsif ssl_support == "enabled"
137:         ssl_specification = Hash['ssl_support'=>'enabled','certificate_file'=>certificate,'key_file'=>key,'ssl_port'=>ssl_port]
138:         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]
139:       else
140:         ssl_specification = Hash['ssl_support'=>'disabled','certificate_file'=>certificate,'key_file'=>key,'ssl_port'=>ssl_port]
141:         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]
142:       end
143:       
144:       return server_specification
145:     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.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.to_i > 0 and data.to_i <= 20 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.to_i > 0 and data.to_i <= 20 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.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]