Update temp_files.

This commit is contained in:
BoHung Chiu 2022-10-04 13:27:32 +08:00
parent 394304bd17
commit c3a42efabf
9 changed files with 175 additions and 31 deletions

View File

@ -192,6 +192,6 @@ class Admin::PlaygroundController < OrbitAdminController
end end
def check_for_testers def check_for_testers
render_401 if !current_user.beta_tester && current_user.user_name != "rulingcom" render_401 if !current_user.beta_tester
end end
end end

View File

@ -1,7 +1,19 @@
class Admin::SitesController < OrbitAdminController class Admin::SitesController < OrbitAdminController
before_filter :set_git_branch, :only=>[:check_updates, :update_orbit] before_filter :set_git_branch, :only=>[:check_updates, :update_orbit]
include Admin::GmailHelper include Admin::GmailHelper
begin
include BundlerHelper include BundlerHelper
rescue
def bundler_with_clean_env
if block_given?
if Bundler.respond_to?(:with_unbundled_env)
Bundler.with_unbundled_env(&Proc.new)
else
Bundler.with_clean_env(&Proc.new)
end
end
end
end
helper_method :GeneratePermissionUrl helper_method :GeneratePermissionUrl
def get_all_databases def get_all_databases
nginx_exe = %x[ps -o args -C nginx| grep 'daemon'| awk '{print $4}'].split("\n")[0] nginx_exe = %x[ps -o args -C nginx| grep 'daemon'| awk '{print $4}'].split("\n")[0]
@ -156,9 +168,9 @@ class Admin::SitesController < OrbitAdminController
@params = params @params = params
search_grep = params[:keywords].blank? ? nil : "|grep '#{params[:keywords]}'" search_grep = params[:keywords].blank? ? nil : "|grep '#{params[:keywords]}'"
system_head = search_grep ? "-n #{@max_system_page*limit_num} #{search_grep} | head -n #{@system_page*limit_num||limit_num}" : "-n #{@system_page*limit_num}" system_head = search_grep ? "-n #{@max_system_page*limit_num} #{search_grep} | head -n #{@system_page*limit_num||limit_num}" : "-n #{@system_page*limit_num}"
@system_logs = Kaminari.paginate_array(%x[journalctl -x --no-pager -r -o json #{system_head} | tail -#{limit_num}].split("\n").collect{|v| JSON.parse(v)}).page(1).per(limit_num) if @system_page != 0 @system_logs = Kaminari.paginate_array(%x[journalctl -x --no-pager -r -o json #{system_head} | tail -#{limit_num}].encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => '').split("\n").collect{|v| JSON.parse(v)}).page(1).per(limit_num) if @system_page != 0
@mongo_logs = Kaminari.paginate_array(%x[cat /var/log/mongodb/mongod.log*|grep error#{search_grep}|tac].split("\n").collect{|v| v.scan(/^((?:(?! ).)*) (.*)/)[0]}).page(@mongo_page).per(limit_num) if @mongo_page != 0 @mongo_logs = Kaminari.paginate_array(%x[cat /var/log/mongodb/mongod.log*|grep error#{search_grep}|tac].encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => '').split("\n").collect{|v| v.scan(/^((?:(?! ).)*) (.*)/)[0]}).page(@mongo_page).per(limit_num) if @mongo_page != 0
@nginx_logs = Kaminari.paginate_array(%x[cat /var/log/nginx/error.log#{search_grep}|tac].split("\n").collect{|v| v.scan(/^((?:(?!\[).)*)\[error\] (.*)/)[0]}.compact).page(@nginx_page).per(limit_num) if @nginx_page != 0 @nginx_logs = Kaminari.paginate_array(%x[cat /var/log/nginx/error.log#{search_grep}|tac].encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => '').split("\n").collect{|v| v.scan(/^((?:(?!\[).)*)\[error\] (.*)/)[0]}.compact).page(@nginx_page).per(limit_num) if @nginx_page != 0
@mail_crons = Email.can_deliver.desc(:created_at) @mail_crons = Email.can_deliver.desc(:created_at)

View File

@ -8,17 +8,24 @@ class SessionsController < ApplicationController
def new def new
if session[:user_id] if session[:user_id]
redirect_to get_referer_from_params(current_site) and return redirect_to get_referer_from_params(@site) and return
elsif @site.privileged_ip_login_only && !(@site.check_ip_is_privileged?(request.remote_ip, current_user))
render(:plain => t('privileged_ip_login_only'), :status => 403) and return
end end
end end
def show def show
user_name = [] user_name = []
if params["_method"].present? if params["_method"].present?
render :text => "Invalid format", :status => 403 flash.now.alert = "Invalid format"
render "new" and return
end end
begin begin
if @site.privileged_ip_login_only && !(@site.check_ip_is_privileged?(request.remote_ip, current_user))
render(:plain => t('privileged_ip_login_only'), :status => 403) and return
end
if params[:user_name].blank? if params[:user_name].blank?
render(:text => "Invalid format", :status => 403) and return flash.now.alert = "Invalid format"
render "new" and return
end end
if !params[:user_name].include?('@') if !params[:user_name].include?('@')
user = User.where(:user_name=>params['user_name']).first user = User.where(:user_name=>params['user_name']).first
@ -37,7 +44,7 @@ class SessionsController < ApplicationController
end end
else else
user_email = params[:user_name] user_email = params[:user_name]
members = MemberProfile.where(:email=>params[:user_name]).take_while{true} members = MemberProfile.where(:email=>params[:user_name]).to_a
members.each do |member_profile| members.each do |member_profile|
user = User.where(:member_profile_id=>member_profile.id).first user = User.where(:member_profile_id=>member_profile.id).first
if user if user
@ -56,7 +63,7 @@ class SessionsController < ApplicationController
headers["Content-Disposition"] = "form-data; name=\"JsonString\"" headers["Content-Disposition"] = "form-data; name=\"JsonString\""
respond_to do |format| respond_to do |format|
format.json { render :json => params } format.json { render :json => params }
format.any { render :text => "Invalid format", :status => 403 } format.any { render :plain => "Invalid format", :status => 403 }
end end
rescue rescue
render :json => params,:status=>403 render :json => params,:status=>403
@ -83,8 +90,12 @@ class SessionsController < ApplicationController
params = params || request.params params = params || request.params
session = session || request.session session = session || request.session
flash = flash || request.flash flash = flash || request.flash
if @site.privileged_ip_login_only && !(@site.check_ip_is_privileged?(request.remote_ip, current_user))
render(:plain => t('privileged_ip_login_only'), :status => 403) and return
end
if params[:user_name].blank? if params[:user_name].blank?
render(:text => "Invalid format", :status => 403) and return flash.now.alert = "Invalid format"
render "new" and return
end end
if !params[:user_name].include?('@') if !params[:user_name].include?('@')
user = User.find_by(user_name: params[:user_name]) rescue nil user = User.find_by(user_name: params[:user_name]) rescue nil
@ -95,9 +106,10 @@ class SessionsController < ApplicationController
user = User.find_by(user_name: params[:user_name]) rescue nil user = User.find_by(user_name: params[:user_name]) rescue nil
end end
end end
site = ApplicationHelper::CurrentSite site = @site
if UserLoginLog.where(user_name: params[:user_name],status: false,:created_at.gte => Time.now-(site.password_failed_lock_time.minutes rescue 1.minutes)).count>=(site.password_failed_lock_num rescue 5) if UserLoginLog.where(user_name: params[:user_name],status: false,:created_at.gte => Time.now-(site.password_failed_lock_time.minutes rescue 1.minutes)).count>=(site.password_failed_lock_num rescue 5)
render :text => I18n.t('account_lock_note',time: (site.password_failed_lock_time rescue 1),num: (site.password_failed_lock_num rescue 5)),:status=> 403 and return flash.now.alert = I18n.t('account_lock_note',time: (site.password_failed_lock_time rescue 1),num: (site.password_failed_lock_num rescue 5))
render "new" and return
end end
user_login_log = UserLoginLog.create(user_name: params[:user_name]) user_login_log = UserLoginLog.create(user_name: params[:user_name])
login_flag = false login_flag = false
@ -204,7 +216,7 @@ class SessionsController < ApplicationController
connection_successful = connect_account(auth) connection_successful = connect_account(auth)
else else
if login_user(user,auth) if login_user(user,auth)
redirect_to get_referer_from_params(current_site) and return redirect_to get_referer_from_params(@site) and return
end end
end end
end end
@ -229,7 +241,7 @@ class SessionsController < ApplicationController
end end
def update def update
render(:text => "Invalid request", :status => 403) and return render(:plain => "Invalid request", :status => 403) and return
end end
def connect_sign_up_account(auth, user) def connect_sign_up_account(auth, user)
@ -288,14 +300,14 @@ class SessionsController < ApplicationController
private private
def check_for_rulingcom(ldap_flag = !(defined? LdapLogin).nil?) def check_for_rulingcom(ldap_flag = !(defined? LdapLogin).nil?)
if !ldap_flag if !ldap_flag || @site.privileged_ip_login_only
if params[:user_name] == "rulingcom" && params[:alternative_login].present? if params[:user_name] == "rulingcom" && params[:alternative_login].present?
if ["118.163.60.152", "127.0.0.1"].include?(request.remote_ip) if ["118.163.60.152", "127.0.0.1"].include?(request.remote_ip)
user = User.where(:user_name => "rulingcom").first user = User.where(:user_name => "rulingcom").first
if (user && user.authenticate(params[:password]) && user.is_confirmed?.eql?(true)) if (user && user.authenticate(params[:password]) && user.is_confirmed?.eql?(true))
session[:user_id] = user.id session[:user_id] = user.id
session[:login_referer] = nil session[:login_referer] = nil
redirect_to get_referer_from_params(current_site) and return redirect_to get_referer_from_params(@site) and return
else else
@server_connected = false @server_connected = false
@login_referer = params[:referer_url] @login_referer = params[:referer_url]
@ -321,7 +333,7 @@ class SessionsController < ApplicationController
user = User.where(:user_name => "rulingcom").first user = User.where(:user_name => "rulingcom").first
session[:user_id] = user.id session[:user_id] = user.id
session[:login_referer] = nil session[:login_referer] = nil
redirect_to get_referer_from_params(current_site) and return redirect_to get_referer_from_params(@site) and return
else else
@login_referer = params[:referer_url] @login_referer = params[:referer_url]
flash.now.alert = "Invalid username or password" flash.now.alert = "Invalid username or password"

View File

@ -16,7 +16,7 @@ module OrbitBackendHelper
{"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}}, {"$group" => {"_id" => group_id_fields,"count" => {"$sum" => 1}}},
{"$sort" => {"created_at"=>-1}} {"$sort" => {"created_at"=>-1}}
] ]
tmp = Impression.collection.aggregate(pipeline) tmp = Impression.collection.aggregate(pipeline).to_a
if tmp.count < day_limit if tmp.count < day_limit
tmp1 = tmp tmp1 = tmp
tmp = (0...day_limit).collect do |i| tmp = (0...day_limit).collect do |i|
@ -141,7 +141,22 @@ module OrbitBackendHelper
elsif @current_user_is_sub_manager && !create_user.nil? elsif @current_user_is_sub_manager && !create_user.nil?
return ( @user_authenticated_categories.include?(obj.category_id) rescue (create_user == current_user.id.to_s)) return ( @user_authenticated_categories.include?(obj.category_id) rescue (create_user == current_user.id.to_s))
else else
@user_authenticated_categories.include?obj.category_id rescue (current_user.is_manager?(@module_app) rescue false) tmp = false
if @changed_module_app
if obj.class == Page
if obj.tmp_root_page_id
obj = Page.find(obj.tmp_root_page_id)
end
if obj.bind_model.present?
new_obj = obj.bind_model.constantize.where(:uid=>obj.bind_uid).first rescue nil
obj = new_obj if new_obj
end
end
tmp = @user_authenticated_categories.include?obj.category_id rescue (current_user.is_manager?(@changed_module_app) rescue false)
else
tmp = @user_authenticated_categories.include?obj.category_id rescue (current_user.is_manager?(@module_app) rescue false)
end
tmp
end end
end end
@ -159,9 +174,9 @@ module OrbitBackendHelper
def check_store_permissions #checks with the store if it has proper access and rights to access store def check_store_permissions #checks with the store if it has proper access and rights to access store
store_permission = {} store_permission = {}
store_token = current_site.store_token rescue nil store_token = @site.store_token rescue nil
if !store_token.nil? if !store_token.nil?
params_to_send = {'store_token' => current_site.store_token} params_to_send = {'store_token' => @site.store_token}
uri = URI.parse(OrbitStore::URL) uri = URI.parse(OrbitStore::URL)
http = Net::HTTP.new(uri.host,uri.port) http = Net::HTTP.new(uri.host,uri.port)
http.read_timeout =1 #seconds http.read_timeout =1 #seconds
@ -192,8 +207,8 @@ module OrbitBackendHelper
if !data["success"] if !data["success"]
case data["error"] case data["error"]
when "INVALID_SITE_TOKEN" when "INVALID_SITE_TOKEN"
current_site.store_token = nil @site.store_token = nil
current_site.save @site.save
end end
store_permission["permission_granted"] = false store_permission["permission_granted"] = false
store_permission["error"] = data["error"] store_permission["error"] = data["error"]

View File

@ -1,5 +1,6 @@
class Multithread class Multithread
include Mongoid::Document include Mongoid::Document
include Mongoid::Timestamps
field :key field :key
field :status field :status
end end

View File

@ -1,5 +1,3 @@
<script src="/assets/lib/jquery-ui-1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="/assets/lib/jquery-ui-1.12.1/jquery-ui.min.css">
<script type="text/javascript"> <script type="text/javascript">
function see_detail(i){ function see_detail(i){
$(".detail-only-content-"+i).dialog("option", "width", $(window).width()*0.8); $(".detail-only-content-"+i).dialog("option", "width", $(window).width()*0.8);

View File

@ -20,6 +20,13 @@ if Rails.version.to_i>4
end end
end end
end end
module ActionView::Helpers::AssetTagHelper
alias_method :org_image_tag, :image_tag
def image_tag(source, options={})
tmp_source = path_to_image(source)
org_image_tag(tmp_source, options)
end
end
class ActionController::Parameters class ActionController::Parameters
BSON_TYPE = Hash.new.bson_type BSON_TYPE = Hash.new.bson_type
def bson_type def bson_type
@ -42,6 +49,14 @@ if Rails.version.to_i>4
super super
end end
end end
def to_h #Migrate from rails 4 to rails 5, avoid unpermitted parameters
to_unsafe_hash
end
def update_values(&block)
each_pair do |key, value|
store(key, block[value])
end
end
def to_bson_key(validating_keys = BSON::Config.validating_keys?) def to_bson_key(validating_keys = BSON::Config.validating_keys?)
self.to_s self.to_s
end end
@ -223,6 +238,92 @@ class CssPostProcessor
end end
module Orbit module Orbit
class ExceptionController < ActionDispatch::PublicExceptions
require 'action_dispatch/http/request'
require 'action_dispatch/middleware/exception_wrapper'
require 'action_dispatch/routing/inspector'
require 'action_dispatch/middleware/debug_exceptions'
RESCUES_TEMPLATE_PATH = ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
Is_Rails5 = (Rails.version.to_i>4)
alias_method :org_call, :call
def call(env)
request = ActionDispatch::Request.new(env)
request_path = env["REQUEST_PATH"].to_s.sub(/^\/#{I18n.locale}\//, '/')
session = env["rack.session"]
if Rails.env != "production" && request_path.start_with?('/admin') && (@current_user = (session[:user_id] ? User.find(session[:user_id]) : nil) rescue nil)
exception = env['action_dispatch.exception']
@routes_app = env["action_dispatch.routes"]
if Is_Rails5
backtrace_cleaner = request.get_header("action_dispatch.backtrace_cleaner")
wrapper = ActionDispatch::ExceptionWrapper.new(backtrace_cleaner, exception)
traces = wrapper.traces
trace_to_show = "Application Trace"
if traces[trace_to_show].empty? && wrapper.rescue_template != "routing_error"
trace_to_show = "Full Trace"
end
if source_to_show = traces[trace_to_show].first
source_to_show_id = source_to_show[:id]
end
template = ActionDispatch::DebugExceptions::DebugView.new([RESCUES_TEMPLATE_PATH],
request: request,
exception: wrapper.exception,
traces: traces,
show_source_idx: source_to_show_id,
trace_to_show: trace_to_show,
routes_inspector: routes_inspector(wrapper.exception),
source_extracts: wrapper.source_extracts,
line_number: wrapper.line_number,
file: wrapper.file
)
else
wrapper = ActionDispatch::ExceptionWrapper.new(env, exception)
template = ActionView::Base.new([RESCUES_TEMPLATE_PATH],
request: request,
exception: wrapper.exception,
application_trace: wrapper.application_trace,
framework_trace: wrapper.framework_trace,
full_trace: wrapper.full_trace,
routes_inspector: routes_inspector(exception),
source_extract: wrapper.source_extract,
line_number: wrapper.line_number,
file: wrapper.file
)
end
file = "rescues/#{wrapper.rescue_template}"
if request.xhr?
body = template.render(template: file, layout: false, formats: [:text])
format = "text/plain"
else
body = template.render(template: file, layout: 'rescues/layout')
format = "text/html"
end
render_body(wrapper.status_code, body, format)
else
org_call(env)
end
end
def render_html(status, override_public_path=nil)
override_public_path = public_path if override_public_path.nil?
path = "#{public_path}/#{status}.#{I18n.locale}.html"
path = "#{public_path}/#{status}.html" unless (found = File.exist?(path))
if found || File.exist?(path)
render_format(status, 'text/html', File.read(path))
else
[404, { "X-Cascade" => "pass" }, []]
end
end
def render_body(status, body, format)
[status, {'Content-Type' => "#{format}; charset=#{ActionDispatch::Response.default_charset}", 'Content-Length' => body.bytesize.to_s}, [body]]
end
def routes_inspector(exception)
if @routes_app && @routes_app.respond_to?(:routes) && (exception.is_a?(ActionController::RoutingError) || exception.is_a?(ActionView::Template::Error))
ActionDispatch::Routing::RoutesInspector.new(@routes_app.routes.routes)
end
end
end
class Application < Rails::Application class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here. # Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers # Application configuration should go into files in config/initializers
@ -271,5 +372,6 @@ module Orbit
env.cache = ActiveSupport::Cache.lookup_store(:memory_store,{ size: 128.megabytes }) env.cache = ActiveSupport::Cache.lookup_store(:memory_store,{ size: 128.megabytes })
env.register_postprocessor 'text/css', CssPostProcessor.new env.register_postprocessor 'text/css', CssPostProcessor.new
end end
config.exceptions_app = ExceptionController.new("#{Rails.root}/app/views/errors")
end end
end end

View File

@ -6,10 +6,14 @@ rails_env = ENV['RAILS_ENV'] || 'production'
cpu_cores = %x(cat /proc/cpuinfo | grep processor | wc -l).sub("\n",'').to_i * 3 / 4 rescue 2 cpu_cores = %x(cat /proc/cpuinfo | grep processor | wc -l).sub("\n",'').to_i * 3 / 4 rescue 2
default_cpu_cores = cpu_cores default_cpu_cores = cpu_cores
begin if File.exists?("#{rails_root}/cpu_cores.txt")
cpu_cores = File.read("#{rails_root}/cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i rescue default_cpu_cores
else
begin
cpu_cores = File.read("#{rails_root}/../cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i if (File.exists?("#{rails_root}/../cpu_cores.txt") rescue false) cpu_cores = File.read("#{rails_root}/../cpu_cores.txt").force_encoding('utf-8').sub("\n",'').to_i if (File.exists?("#{rails_root}/../cpu_cores.txt") rescue false)
rescue => e rescue => e
cpu_cores = default_cpu_cores cpu_cores = default_cpu_cores
end
end end
cpu_cores = 1 if (cpu_cores < 1) cpu_cores = 1 if (cpu_cores < 1)
worker_processes (rails_env == 'production' ? cpu_cores : 1) worker_processes (rails_env == 'production' ? cpu_cores : 1)