2009-05-07 16:53:18 +00:00
|
|
|
class ApplicationController < ActionController::Base
|
2009-06-01 06:20:15 +00:00
|
|
|
protect_from_forgery
|
2010-03-08 08:04:05 +00:00
|
|
|
|
2011-03-02 09:28:33 +00:00
|
|
|
include Parser
|
|
|
|
|
2010-03-08 08:04:05 +00:00
|
|
|
helper :all
|
2011-05-13 01:08:42 +00:00
|
|
|
before_filter :set_locale, :set_site
|
2011-04-13 10:19:51 +00:00
|
|
|
|
|
|
|
# Find the parent for the given item
|
|
|
|
def find_parent_item
|
|
|
|
@parent_item = Item.first(:conditions => { :id => BSON::ObjectId(params[:parent_id]) }) rescue nil
|
|
|
|
end
|
2009-06-19 09:31:10 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Check if the current_user is admin
|
|
|
|
def is_admin?
|
|
|
|
redirect_to root_url unless current_user.admin?
|
|
|
|
end
|
|
|
|
|
2011-03-02 09:28:33 +00:00
|
|
|
# Render the page
|
2011-02-22 08:00:13 +00:00
|
|
|
def render_page
|
2011-05-25 06:50:56 +00:00
|
|
|
if @item
|
|
|
|
render :text => parse_page(@item)
|
2009-06-01 06:20:15 +00:00
|
|
|
else
|
|
|
|
render :text => '404 Not Found'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-08-18 05:43:33 +00:00
|
|
|
protected
|
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Set I18n.locale
|
2009-06-19 09:31:10 +00:00
|
|
|
def set_locale
|
|
|
|
# update session if passed
|
2011-04-13 10:19:51 +00:00
|
|
|
session[:locale] = params[:locale] if params[:locale]
|
|
|
|
|
2009-06-19 09:31:10 +00:00
|
|
|
# set locale based on session or default
|
2011-04-13 10:19:51 +00:00
|
|
|
begin
|
|
|
|
# check if locale is valid for non site pages
|
|
|
|
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
|
|
|
|
I18n.locale = I18n.default_locale
|
|
|
|
else
|
|
|
|
I18n.locale = session[:locale]
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
I18n.locale = I18n.default_locale
|
|
|
|
end
|
2010-01-11 09:09:50 +00:00
|
|
|
end
|
2010-03-08 08:04:05 +00:00
|
|
|
|
2011-04-13 10:19:51 +00:00
|
|
|
# Set the site variables
|
|
|
|
def set_site
|
|
|
|
# set site if exist or create site
|
2011-03-02 09:28:33 +00:00
|
|
|
@site = Site.first || Site.create({:valid_locales => [], :in_use_locales => []})
|
|
|
|
session[:site] = @site.id
|
|
|
|
@site_in_use_locales = @site.in_use_locales
|
|
|
|
@site_valid_locales = @site.valid_locales
|
2011-04-13 10:19:51 +00:00
|
|
|
end
|
2011-05-13 01:08:42 +00:00
|
|
|
|
|
|
|
def set_current_item
|
2011-05-25 06:50:56 +00:00
|
|
|
session[:current_page] = params[:id] || @item.id rescue nil
|
2011-05-13 01:08:42 +00:00
|
|
|
end
|
2011-08-18 05:43:33 +00:00
|
|
|
|
|
|
|
def decrypt_data(encrypted_data, encrypted_key, encrypted_iv)
|
|
|
|
site = Site.find(session[:site])
|
|
|
|
if encrypted_data
|
|
|
|
private_key = OpenSSL::PKey::RSA.new(site.private_key)
|
|
|
|
cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
|
|
|
cipher.decrypt
|
|
|
|
cipher.key = private_key.private_decrypt(encrypted_key)
|
|
|
|
cipher.iv = private_key.private_decrypt(encrypted_iv)
|
|
|
|
|
|
|
|
decrypted_data = cipher.update(encrypted_data)
|
|
|
|
decrypted_data << cipher.final
|
|
|
|
else
|
|
|
|
''
|
|
|
|
end
|
|
|
|
end
|
2011-04-13 10:19:51 +00:00
|
|
|
|
2009-05-07 16:53:18 +00:00
|
|
|
end
|