1 class AdminController < ApplicationController
2 before_filter :only_for_admin
3 before_filter :set_page_title
4 before_filter :set_mode
8 redirect_to :action => "global_table"
13 @order_list = (@params['order_list']||'').split('/').collect {|i| i.to_sym}
14 @order_directions = (@params['order_directions']||'').split('/')
18 @order_list = [:is_admin, :veid]
19 @order_directions = ['ASC', 'DESC']
24 @user_columns = [:name, :institution, :is_admin, :labels]
25 @ve_columns = [:status, :veid, :ip, :label]
27 virtual_environments = VirtualEnvironment.find(:all)
28 users = User.find(:all)
30 # Building the @rows array
32 virtual_environments.each do |ve|
33 user = User.find_user_by_id(users, ve.uid)
36 @user_columns.each do |c|
37 @rows.last[c] = case c
39 # user[:email] =~ SAFE_EMAIL
47 @ve_columns.each do |c|
48 @rows.last[c] = case c
58 # Sorting the @rows array
60 def comparison(first, second)
61 human2digit = {'ASC' => 1, 'DESC' => -1}
63 @order_list.each_with_index do |o, i|
64 human_direction = @order_directions[i]
66 formated_first, formated_second = * case o
68 m = {true=>1, false=>0}
85 # This will be 1, -1, or 0
86 cmp = (formated_first <=> formated_second)
89 return cmp * human2digit[human_direction]
93 return 0 # Elements are equal
96 @rows.sort!{ |f,s| comparison(f,s) }
103 flash[:notices] ||= []
104 has_selection = false
106 params.each_pair do |key, val|
107 if key =~ /checkbox_for_([a-z]+)_([0-9a-z_\-.]+)/ and val == "on"
111 ve = VirtualEnvironment.find_by_veid($2.to_i)
113 name = User.find_by_name($2)
117 session[:workers] ||= {}
118 if 'destroy'== params[:selected_action]
119 if ve.status == 'stopped'
120 session[:workers][ve.veid] =
121 Nucleus.new.destroy(ve.veid), 'destroying'
123 flash[:notices] << "Error Destroy: VE #{ve.veid} is not stopped"
125 elsif 'stop' == params[:selected_action]
126 if ve.status == 'started'
127 session[:workers][ve.veid] = Nucleus.new.stop(ve.veid), 'stopping'
129 flash[:notices] << "Error Stop: VE #{ve.veid} is not started"
131 elsif 'start' == params[:selected_action]
132 if ve.status == 'stopped'
133 session[:workers][ve.veid] = Nucleus.new.start(ve.veid), 'starting'
135 flash[:notices] << "Error Start: VE #{ve.veid} is not stopped"
137 elsif 'disable' == params[:selected_action]
140 "Error Disable: #{name.name} is already disabled."
142 name.is_disabled = true
146 elsif 'enable' == params[:selected_action]
148 flash[:notices] << "Error Enable: #{name.name} is already enabled."
150 name.is_disabled = false
152 #code here to stop all virtual machines by the user
155 render (:inline => "<%=simple_message('Action was not selected.')%>",
156 :layout => 'application')
164 render (:inline => "<%=simple_message('No VEs were selected.')%>",
165 :layout => 'application')
168 redirect_to :controller => 'admin', :action => params[:come_back_to]
174 def account_management
175 @names = User.find_all.collect{|u| u.name}.sort
180 @body = `cat /home/alevchuk/sstats/aggregatedsstats.txt`
187 @page_title1 = "Mwamko Administration"
188 @page_title2 = params[:action].gsub('_', ' ').titleize
192 #set mwamko to normal mode
193 session[:mwamko_mode] = ['normal', 'gadget'][0]