Changeset 5796

Show
Ignore:
Timestamp:
06/12/08 18:29:21 (3 months ago)
Author:
uta
Message:

2008/06/12 sync

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • rubricks_core/trunk/app/controllers/application.rb

    r5781 r5796  
    118118    return if performed? 
    119119    before_request_store_common_data 
    120     before_request_refuse_guest 
    121120    before_request_protection_for_session_fixation_attack 
    122121    RubricksLib.load_lang 
     
    146145      cookies[:rmp] = {:value => '0', :path => RubricksLib.cookie_path} 
    147146      reset_session 
    148     end 
    149   end 
    150  
    151   def before_request_refuse_guest 
    152     if guest? && !RubricksConfig.get('user_guest_available') 
    153       unless RubricksLib::GUEST_AVAILABLE_CONTROLLER.include?(params[:controller]) 
    154         jump_page(url_for(:controller => '/system/login', :action => 'login_page')) 
    155       end 
    156147    end 
    157148  end 
  • rubricks_core/trunk/app/controllers/test_controller.rb

    r5557 r5796  
    2929    raise RubricksError::User::UnauthorizedException unless RubricksLib.test_mode? 
    3030  end 
    31  
    32   ################################################################### 
    33   #  Old 
    34   ################################################################### 
    35   def clear_components_dir 
    36     clear_dirs = ['components', 'install'] 
    37     public_dirs = ['images', 'javascripts', 'stylesheets'] 
    38     target_components = Dir["#{RAILS_ROOT}/test/rzips/*.rzip"] 
    39     clear_dirs.each do |target_dir| 
    40       target_components.each do |target_component_path| 
    41         target_component = target_component_path.sub(%r(^.*/([^/]*)\.rzip$), '\1') 
    42         clear_dirs.each do |dir| 
    43           dir_name  = "#{RAILS_ROOT}/#{dir}/#{target_component}" 
    44           rzip_name = "#{dir_name}.rzip" 
    45           RubricksLib.rm(dir_name) 
    46           RubricksLib.rm(rzip_name) 
    47         end 
    48         public_dirs.each do |dir| 
    49           dir_name = "#{RAILS_ROOT}/public/#{dir}/components/#{target_component}" 
    50           RubricksLib.rm(dir_name) 
    51         end 
    52       end 
    53     end 
    54     scripts = ['before_install', 'after_install', 'before_uninstall', 'after_uninstall', 'before_update', 'after_update'] 
    55     scripts.each do |script| 
    56       RubricksLib.rm("#{RAILS_ROOT}/test/#{script}.txt") 
    57     end 
    58     render :text => 'clear components directory.' 
    59   end 
    60    
    61   def clear_skin_dirs(skin_name) 
    62     targets = ['javascripts', 'images', 'stylesheets'] 
    63     targets.each do |target| 
    64       RubricksLib.rm("#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}") 
    65     end 
    66     RubricksLib.rm("#{RAILS_ROOT}/dashboard/widgets/#{skin_name}") 
    67   end 
    68  
    69   def clear_skin_files 
    70     skin_name = params[:skin_name] || 'test' 
    71     clear_skin_dirs(skin_name) 
    72     render :text => "clear_skin_files. (#{skin_name})" 
    73   end 
    74  
    75   def clear_skin_testdirs 
    76     skin_testdirs = [ 
    77       'skin32characters0000000000000000',  
    78       'skinblue', 
    79       'skingreen', 
    80       'skin33characters00000000000000000', 
    81       'skin6', 
    82       'skin7', 
    83       'skin8', 
    84       'skin(_marks)', 
    85     ] 
    86     skin_testdirs.each do |dir| 
    87       clear_skin_dirs(dir) 
    88     end 
    89     render :text => "clear_skin_testdirs." 
    90   end 
    91  
    92   def clear_theme_dirs(theme_name) 
    93     targets = ['images', 'javascripts', 'stylesheets'] 
    94     targets.each do |target| 
    95       RubricksLib.rm("#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}") 
    96     end 
    97     RubricksLib.rm("#{RAILS_ROOT}/themes/#{theme_name}") 
    98   end 
    99  
    100   def clear_theme_files 
    101     theme_name = params[:theme_name] || 'test' 
    102     clear_theme_dirs(theme_name) 
    103     render :text => "clear_theme_files. (#{theme_name})" 
    104   end 
    105  
    106   def clear_theme_testdirs 
    107     theme_testdirs = [ 
    108       'theme32characters000000000000000',  
    109       'themeblue', 
    110       'themegreen', 
    111       'theme33characters0000000000000000', 
    112       'theme3', 
    113       'theme4', 
    114       'theme5', 
    115       'theme(_marks)', 
    116     ] 
    117     theme_testdirs.each do |dir| 
    118       clear_theme_dirs(dir) 
    119     end 
    120     render :text => "clear_theme_testdirs." 
    121   end 
    122  
    123   def confirm_delivery_mail 
    124     if ActionMailer::Base.deliveries.blank? 
    125       render :text => 'No Mail' 
    126     else 
    127       text = '<meta http-equiv="content-type" content="text/html; charset=UTF-8" />' 
    128       ActionMailer::Base.deliveries.each do |mail| 
    129         text << "To: #{mail[:recipient]}<br>" 
    130         text << "Cc: #{mail[:cc]}<br>" 
    131         text << "Bcc: #{mail[:bcc]}<br>" 
    132         text << "From: #{mail[:from]}<br>" 
    133         text << "Subject: #{mail[:subject]}<br>" 
    134         text << "Template: #{mail[:template]}<br>" 
    135       end 
    136       ActionMailer::Base.deliveries.clear 
    137       render :text => text 
    138     end 
    139   end 
    140  
    141   def confirm_permission 
    142     ru = current_user 
    143     render :text => (guest?) ? 'Guest' : current_user.login_name 
    144   end 
    145  
    146   def confirm_skin_files_exist 
    147     skin_name = params[:skin_name] 
    148     skin_flag = true 
    149     targets = ['images', 'stylesheets'] 
    150     targets.each do |target| 
    151       if target == 'stylesheets' 
    152         from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/#{target}/sample.css" 
    153         copy_path = "#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}/sample.css" 
    154       else 
    155         from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/#{target}/from.txt" 
    156         copy_path = "#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}/from.txt" 
    157       end 
    158       skin_flag = false unless File.exists?(from_path) 
    159       skin_flag = false unless File.exists?(copy_path) 
    160     end 
    161     render :text => (skin_flag) ? 'ok' : 'ng' 
    162   end 
    163  
    164   def confirm_theme_files_exist 
    165     theme_name = params[:theme_name] 
    166     theme_flag = true 
    167     targets = ['images', 'javascripts', 'stylesheets'] 
    168     targets.each do |target| 
    169       if target == 'stylesheets' 
    170         from_path = "#{RAILS_ROOT}/themes/#{theme_name}/#{target}/common.css" 
    171         copy_path = "#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}/style.css" 
    172       else 
    173         from_path = "#{RAILS_ROOT}/themes/#{theme_name}/#{target}/from.txt" 
    174         copy_path = "#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}/from.txt" 
    175       end 
    176       theme_flag = false unless File.exists?(from_path) 
    177       theme_flag = false unless File.exists?(copy_path) 
    178     end 
    179     render :text => (theme_flag) ? 'ok' : 'ng' 
    180   end 
    181  
    182   def drop_table 
    183     table_name = params[:table] 
    184     begin 
    185       ActiveRecord::Migration.execute("drop table if exists #{table_name};") 
    186     rescue Exception 
    187       render :text => 'failed to drop table.' 
    188     else 
    189       render :text => "drop table '#{table_name}'." 
    190     end 
    191   end 
    192  
    193   def init_skin_files 
    194     skin_name = params[:skin_name] || 'test' 
    195     clear_skin_dirs(skin_name) 
    196     targets = ['images', 'stylesheets'] 
    197     targets.each do |target| 
    198       from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/#{target}" 
    199       to_path   = "#{RAILS_ROOT}/public/#{target}/dashboard/widgets/#{skin_name}" 
    200       RubricksLib.mkdir(from_path) 
    201       RubricksLib.mkdir(to_path) 
    202       if target == 'stylesheets' 
    203         File.open("#{from_path}/sample.css", 'w') do |file| 
    204           file.puts 'body{color:#cccccc;}' 
    205         end 
    206       else 
    207         File.open("#{from_path}/from.txt", 'w') do |file| 
    208           file.puts 'test' 
    209         end 
    210         File.open("#{to_path}/to.txt", 'w') do |file| 
    211           file.puts 'test' 
    212         end 
    213       end 
    214     end 
    215     render :text => "initialize_skin_dir. (#{skin_name})" 
    216   end 
    217  
    218   def init_skin_images 
    219     skin_name = params[:skin_name] || 'test' 
    220     image_name = params[:image_name] || 'screenshot.jpg' 
    221     from_path = "#{RAILS_ROOT}/dashboard/widgets/#{skin_name}/images" 
    222     to_path   = "#{RAILS_ROOT}/public/images/dashboard/widgets/#{skin_name}" 
    223     File.open("#{from_path}/#{image_name}", 'w') do |file| 
    224     end 
    225     File.open("#{to_path}/#{image_name}", 'w') do |file| 
    226     end 
    227     render :text => "initialize_image. (#{image_name})" 
    228   end 
    229  
    230   def init_theme_files 
    231     theme_name = params[:theme_name] || 'test' 
    232     clear_theme_dirs(theme_name) 
    233     targets = ['images', 'javascripts', 'stylesheets'] 
    234     targets.each do |target| 
    235       from_path = "#{RAILS_ROOT}/themes/#{theme_name}/#{target}" 
    236       to_path   = "#{RAILS_ROOT}/public/#{target}/themes/#{theme_name}" 
    237       RubricksLib.mkdir(from_path) 
    238       RubricksLib.mkdir(to_path) 
    239       if target == 'stylesheets' 
    240         File.open("#{from_path}/stylesheet.rb", 'w') do |file| 
    241           file.puts 'def css_list ' 
    242           file.puts '  {' 
    243           file.puts ':style    => [:common],' 
    244           file.puts '  }' 
    245           file.puts 'end' 
    246         end 
    247         File.open("#{from_path}/common.css", 'w') do |file| 
    248           file.puts 'body{color:#cccccc;}' 
    249         end 
    250       else 
    251         File.open("#{from_path}/from.txt", 'w') do |file| 
    252           file.puts 'test' 
    253         end 
    254         File.open("#{to_path}/to.txt", 'w') do |file| 
    255           file.puts 'test' 
    256         end 
    257       end 
    258     end 
    259     render :text => "initialize_theme_dir. (#{theme_name})" 
    260   end 
    261  
    262   def init_theme_images 
    263     theme_name = params[:theme_name] || 'test' 
    264     image_name = params[:image_name] || 'screenshot.jpg' 
    265     from_path = "#{RAILS_ROOT}/themes/#{theme_name}/images" 
    266     to_path   = "#{RAILS_ROOT}/public/images/themes/#{theme_name}" 
    267     File.open("#{from_path}/#{image_name}", 'w') do |file| 
    268     end 
    269     File.open("#{to_path}/#{image_name}", 'w') do |file| 
    270     end 
    271     render :text => "initialize_image. (#{image_name})" 
    272   end 
    273  
    274   def install 
    275     component_name = params[:component_name] || 'dummy002' 
    276     from_path = "#{RAILS_ROOT}/test/rzips/#{component_name}.rzip" 
    277     to_path   = "#{RAILS_ROOT}/install/#{component_name}.rzip" 
    278     RubricksLib.cp(from_path, to_path) 
    279     RubricksComponent.component_install(component_name) 
    280     render :text => "install #{component_name}" 
    281   end 
    282  
    283   def setup_install_rzip 
    284     component_name = params[:rzip] || 'dummy002' 
    285     from_path = "#{RAILS_ROOT}/test/rzips/#{component_name}.rzip" 
    286     to_path   = "#{RAILS_ROOT}/install/#{component_name}.rzip" 
    287     RubricksLib.cp(from_path, to_path) 
    288     render :text => "setup RZIP. (#{component_name}.rzip)" 
    289   end 
    290  
    291   def setup_update_rzip 
    292     component_name = params[:rzip]   || 'dummy002' 
    293     prefix         = params[:prefix] || 'update' 
    294     from_path = "#{RAILS_ROOT}/test/rzips/#{prefix}_#{component_name}.rzip" 
    295     to_path   = "#{RAILS_ROOT}/install/#{component_name}.rzip" 
    296     RubricksLib.cp(from_path, to_path) 
    297     render :text => "setup RZIP. (#{component_name}.rzip)" 
    298   end 
    299  
    300   def truncate_table 
    301     table_name = params[:table] 
    302     begin 
    303       ActiveRecord::Migration.execute("TRUNCATE TABLE #{table};") 
    304       ActiveRecord::Migration.execute("ALTER TABLE #{table} AUTO_INCREMENT=1;") 
    305     rescue Exception 
    306       render :text => 'failed to truncate table.' 
    307     else 
    308       render :text => "truncate table '#{table_name}'." 
    309     end 
    310   end 
    311  
    312   def uninstall 
    313     component_name = params[:component_name] || 'dummy002' 
    314     rc = RubricksComponent.find_by_name(component_name) 
    315     if rc 
    316       rc.active = false 
    317       rc.save! 
    318       messages = RubricksComponent.component_uninstall(rc.id, rc.display_name) 
    319       if messages.empty? 
    320         render :text => "install #{component_name}" 
    321       else 
    322         render :text => 'failed to uninstall.' 
    323       end 
    324     else 
    325       render :text => 'failed to uninstall.' 
    326     end 
    327   end 
    328   ################################################################### 
    329   #  Old 
    330   ################################################################### 
    33131end 
    33232 
  • rubricks_core/trunk/app/models/rubricks_lib.rb

    r5781 r5796  
    2020      :ruby => %r<^[-a-zA-Z0-9!#\$%&'*+/=?_^`{|}~]+(?:\.[-a-zA-Z0-9!#\$%&'*+/=?_^`{|}~]+)*@(?:[-a-zA-Z0-9]+\.)+[a-zA-Z]{2,}$>, 
    2121    } 
    22     GUEST_AVAILABLE_CONTROLLER  = ['system/account', 'system/error', 'system/login', 'system/mobile', 'test'] 
    2322    IMAGE_FILE_EXTENSION        = /\.(?:gif|jpeg|jpg|png)$/i 
    2423    IMAGE_FILE_SIGNATURE        = { 
  • rubricks_core/trunk/components/system/account_controller.rb

    r5781 r5796  
    33  user_management 
    44  uses_component_template_root 
     5  include Rubricks::Authorize::InvalidateRefuseGuest 
    56  authorize :login,  :except => [:user_edit] 
    67  authorize :access, :only   => [:user_edit] 
  • rubricks_core/trunk/components/system/mobile_controller.rb

    r5744 r5796  
    77 
    88  def index 
    9     ident = request.mobile.ident 
     9    ident = request.mobile.ident rescue nil 
    1010    if ident 
    1111      case RubricksConfig.get('mobile_login_with_ident') 
     
    2020 
    2121  def login(ru = nil) 
     22    ident = request.mobile.ident rescue nil 
    2223    options = { 
    2324      :login_id     => (ru.nil?) ? params[:login][:login_name] : nil, 
    2425      :login_pw     => (ru.nil?) ? params[:login][:raw_password] : nil, 
    25       :mobile_ident => (ru.nil?) ? request.mobile.ident : nil, 
     26      :mobile_ident => (ru.nil?) ? ident : nil, 
    2627      :ru           => ru, 
    2728    } 
     
    5152  private 
    5253  def dispatch_pc 
    53     if request.mobile? 
    54       if !RubricksLib.test_mode? && !request.mobile.valid_ip? 
    55         jump_page(url_for(:controller => '/system/error', :action => 'e401'), {:status => 401}) 
     54    unless RubricksLib.test_mode? 
     55      if request.mobile? 
     56        jump_page(url_for(:controller => '/system/error', :action => 'e401'), {:status => 401}) unless request.mobile.valid_ip? 
     57      else 
     58        redirect_to :controller => '/' 
    5659      end 
    57     else 
    58       redirect_to :controller => '/' 
    5960    end 
    6061  end 
  • rubricks_core/trunk/vendor/plugins/rubricks/lib/authorize_filter.rb

    r5759 r5796  
    1212        before_filter               :authorize_component_access_filter 
    1313        before_filter               :authorize_component_block_filter 
     14        before_filter               :refuse_guest_filter 
    1415        before_filter               :initial_login_filter 
    1516      end 
     
    6869        options = { 
    6970          :actions  => [], 
     71          :function => :access, 
    7072          :scheme   => :basic, 
    7173        }.merge(options) 
     
    153155    end 
    154156 
     157    module InvalidateRefuseGuest 
     158      def refuse_guest_filter 
     159      end 
     160    end 
     161 
    155162    module InvalidateAuthorize 
    156163      include InvalidateDefaultAuthorize 
    157164      include InvalidateInitialLoginAuthorize 
     165      include InvalidateRefuseGuest 
    158166 
    159167      def authorize_component_block_filter 
     
    214222      end 
    215223 
     224      def refuse_guest_filter 
     225        jump_page(url_for(:controller => '/system/login', :action => 'login_page')) if guest? && RubricksConfig.get('user_guest_available').blank? 
     226      end 
     227 
    216228      def server_authorize_filter 
    217229        return true if server_authorize_options.nil? 
     230        return true if RubricksLib.permitted_current_component_function?(server_authorize_options[:function].to_sym) 
    218231        actions = server_authorize_options[:actions].to_a.map{|action| action.to_s} rescue [] 
    219232        if actions.empty? || actions.include?(params[:action])