#-- # WebROaR - Ruby Application Server - http://webroar.in/ # Copyright (C) 2009 WebROaR # # This file is part of WebROaR. # # WebROaR is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # WebROaR is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with WebROaR. If not, see . #++ # Methods added to this helper will be available to all view files for the admin controller. module AdminHelper #This method is used to populate the rows of application data in the configuration page. #This method is called from configuration.html.erb. def application_list(start = 0) i = start list_array = Array.new index = 1 if (@info['Application Specification']) while(@info['Application Specification'][i] and i < start+5) application = ApplicationSpecification.get_hash(i) if index == 1 bg_class = "BG_dark_gray" index = 0 else bg_class = "BG_white" index = 1 end str = " #{h(application[:name])} #{h(application[:resolver])} #{h(application[:type1])} #{h(application[:analytics])} #{h(application[:environment])} #{h(application[:min_worker])} #{h(application[:max_worker])}
#{link_to 'Edit', :controller => 'application_specification', :action => 'edit_application_form', :id => i}
#{link_to_remote 'Delete', {:url => {:controller => 'application_specification', :action=>'delete_application', :id => i}, :before => "show_busy_div()", :complete => "hide_busy_div(request)", :update => "dummy_div", :confirm=>DELETE_APPLICATION_ALERT_MESSAGE, :oncontextmenu => 'return false;' }}
#{link_to_remote 'Restart', {:url => {:controller => 'application_specification', :action => 'restart_application', :id => i}, :before => "show_busy_div()", :complete => "hide_busy_div(request)", :update => "dummy_div", :confirm=>RESTART_APPLICATION_ALERT_MESSAGE, :oncontextmenu => 'return false;'}}
" list_array[i] = str i += 1 end end return list_array.join("\n") end #This method is used to populate the rows of application data on the Home page. #This method is called from home.html.erb. def application_list_home i = 0 list_array = Array.new index = 1 if (@info['Application Specification']) while(@info['Application Specification'][i]) application = ApplicationSpecification.get_hash(i) if @apps_resource_usage[application[:name]] cpu_usage = @apps_resource_usage[application[:name]][0].to_s memory_usage = format("%.2f",@apps_resource_usage[application[:name]][1]/1024).to_f else cpu_usage = 0.0.to_s memory_usage = 0.0.to_s end if index == 1 bg_class = "BG_dark_gray" index = 0 else bg_class = "BG_white" index = 1 end exception_count = get_exceptions(application[:name]).size || 0 if exception_count > 0 link_text = "Yes (#{exception_count})" exception_td_data = "#{link_to link_text, :controller => 'exceptions', :action => 'get_exceptions_list', :application_name => application[:name]}" else exception_td_data = "No" end list_array[i] = " #{h application[:name]} #{h cpu_usage} % #{h memory_usage} MB #{h application[:min_worker]} #{h application[:max_worker]}" if application[:type1].downcase == 'rails' list_array[i] = list_array[i]+ " #{exception_td_data}" else list_array[i] = list_array[i]+ "--" end i += 1 end end return list_array.join("\n") end #This method is used to old values in the server specification in configuration page. #This method is called from add_div partial. def get_old_value_for_div(div_id) port, min_worker, max_worker, log_level, ssl_support, ssl_port, certificate, key, access_log = ServerSpecification.get_fields if params[:div_id] == 'port_div' old_value = port elsif params[:div_id] == 'min_pro_div' old_value = min_worker elsif params[:div_id] == 'max_pro_div' old_value = max_worker elsif params[:div_id] == 'ssl_port_div' old_value = ssl_port elsif params[:div_id] == 'certificate_div' old_value = certificate elsif params[:div_id] == 'key_div' old_value = key elsif params[:div_id] == 'log_div' old_value = log_level elsif params[:div_id] == 'access_log_div' old_value = access_log end return old_value end #To help the configuration page to display the ssl information. def ssl_block(info, ssl_port, certificate, key) if info['Server Specification']['SSL Specification'] block = "
SSL Support
" block = block + "
SSL Port    #{link_to_function('Help', :onclick => 'addHelp("ssl_port");')}
#{ssl_port}
#{link_to_remote 'Edit', :update => 'ssl_port_div', :url => {:action => 'add_text_box', :div_id => 'ssl_port_div'}}
SSL Certificate Path    #{link_to_function('Help', :onclick => 'addHelp("ssl_certificate");')}
#{certificate}
#{link_to_remote 'Edit', :update => 'certificate_div', :url => {:action => 'add_text_box', :div_id => 'certificate_div'}}
Machine key path    #{link_to_function('Help', :onclick => 'addHelp("ssl_key");')}
#{key}
#{link_to_remote 'Edit', :update => 'key_div', :url => {:action => 'add_text_box', :div_id => 'key_div'}}
" else block = block + "#{link_to_remote 'Enable', :update => 'ssl_div', :url => {:controller => 'server_specification', :action => 'ssl_support_form', :id => 1}}" block = block + " " end block = block + "
#{if flash[:ssl_errors] render :partial => 'server_specification/ssl_support_form' end}


" end return block end #To help the configuration page to display the mail configuration. def mail_config_block() if File.exist?(MAIL_FILE_PATH) info = YAML::load_file(MAIL_FILE_PATH) if info['smtp'] block = "
Server #{info['smtp']['address']} Port #{info['smtp']['port']}
Domain #{info['smtp']['domain']} Authenitcation #{info['smtp']['authentication']}
User Name #{info['smtp']['user_name']} Password **************
Sender's Email Address #{info['smtp']['from']} Recipient Email Addresses #{info['smtp']['recipients']}


" elsif info['sendmail'] block = "
Location #{info['sendmail']['location']}
Sender's Email Address #{info['sendmail']['from']}
Recipient Email Addresses #{info['sendmail']['recipients']}


" end else block = "


" end return block end end