After Width: | Height: | Size: 179 B |
After Width: | Height: | Size: 180 B |
After Width: | Height: | Size: 178 B |
After Width: | Height: | Size: 114 B |
After Width: | Height: | Size: 121 B |
After Width: | Height: | Size: 105 B |
After Width: | Height: | Size: 111 B |
After Width: | Height: | Size: 101 B |
After Width: | Height: | Size: 123 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 4.3 KiB |
|
@ -1 +1,19 @@
|
|||
// site progress javascript is here
|
||||
$(document).ready(function() {
|
||||
var config = {}
|
||||
config.autoGrow_minHeight = 50;
|
||||
config.toolbar = [
|
||||
{ name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
|
||||
{ name: 'editing', items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] },
|
||||
|
||||
{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'CopyFormatting', 'RemoveFormat' ] },
|
||||
'/',
|
||||
{ name: 'insert', items: [ 'SpecialChar'] },
|
||||
{ name: 'styles', items: [ 'Font' ] },
|
||||
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] }
|
||||
];
|
||||
var ckeditor_reduce = $('.ckeditor_reduce')
|
||||
ckeditor_reduce.each(function(i,v){
|
||||
CKEDITOR.replace(v,config);
|
||||
})
|
||||
});
|
|
@ -37,11 +37,9 @@ class Admin::RegisterApiController < ApplicationController
|
|||
end
|
||||
def send_store_token
|
||||
site = RegisteredSite.where(:site_domain => params[:site_domain]).first
|
||||
if !site.nil?
|
||||
render :json => {'store_token'=>site.uid}
|
||||
else
|
||||
render :json => {'store_token'=>nil}
|
||||
end
|
||||
uid = site.uid if !site.nil?
|
||||
|
||||
render :json => {'store_token'=>uid,}
|
||||
end
|
||||
def send_confirmation_email(email, confirmation_token, site_token)
|
||||
url = "#{request.protocol}#{request.host_with_port}/register/confirm_email?confirmation=#{confirmation_token}&site=#{site_token}"
|
||||
|
@ -64,7 +62,22 @@ class Admin::RegisterApiController < ApplicationController
|
|||
if !site.nil?
|
||||
site.site_domain = params[:site_domain]
|
||||
site.save
|
||||
render :json => {"success" => true}.to_json
|
||||
watch_list_save_flag = (params['user']!= 'rulingcom' && params['user'].to_s != '')
|
||||
user_name = params['user']
|
||||
puts ['user_name',user_name]
|
||||
site_anncs = SiteAnnc
|
||||
.where(visible: true)
|
||||
.select{|v| v.send_all || v.recieve_sites.include?(site)}.collect do |v|
|
||||
if watch_list_save_flag
|
||||
watch_list = v.watch_list
|
||||
if watch_list.select{|v| v[0]==site.id && v[1]==user_name}.count == 0
|
||||
watch_list << [site.id,user_name]
|
||||
end
|
||||
v.update_attributes(watch_list: watch_list)
|
||||
end
|
||||
{title: v.title,content: v.content,see_more_link: v.see_more_link}
|
||||
end
|
||||
render :json => {"success" => true,'site_anncs'=>site_anncs}.to_json
|
||||
else
|
||||
render :json => {"success" => false}.to_json
|
||||
end
|
||||
|
|
|
@ -15,7 +15,446 @@ class Admin::RegisteredSitesController < OrbitAdminController
|
|||
render :partial => "index"
|
||||
end
|
||||
end
|
||||
def get_watch_list
|
||||
site_annc = SiteAnnc.find(params['data'])
|
||||
lists = site_annc.watch_list.group_by{|v| v[0]}.map{|k,v| [k,v.collect{|v1| v1[1]}]}
|
||||
res = lists.collect do |v|
|
||||
site = RegisteredSite.find(v[0]) rescue nil
|
||||
par1 = site.nil? ? ['not found',''] : [site.show_name,site.site_domain]
|
||||
par2 = v[1].join(', ')
|
||||
[par1,par2]
|
||||
end
|
||||
render :json => res
|
||||
end
|
||||
def show
|
||||
end
|
||||
def announcement
|
||||
@site_anncs = SiteAnnc.all.desc(:craete_at).page(params[:page]).per(10)
|
||||
end
|
||||
def edit_annc
|
||||
@site_annc = SiteAnnc.find(params['site_annc_id']) rescue SiteAnnc.new
|
||||
end
|
||||
def update_annc
|
||||
site_annc = SiteAnnc.find(params['site_annc_id']) rescue SiteAnnc.create
|
||||
site_annc.update_attributes(title: params['title'],
|
||||
see_more_link: params['see_more_link'],
|
||||
content: params['content'],
|
||||
recieve_sites: params['recieve_sites'],
|
||||
visible: params['visible']=='true',
|
||||
send_all: params['send_all']=='true')
|
||||
redirect_to '/admin/registered_sites/announcement'
|
||||
end
|
||||
def get_select_box
|
||||
tags = @module_app.tags.map{|v| v}
|
||||
categories = @module_app.categories.enabled.map{|v| v}
|
||||
sites = RegisteredSite.all.collect{|v1| [v1,v1.tags,v1.category]}
|
||||
@sites_order_by_tags = tags.map{|v| {v=>sites.select{|v1| v1[1].include? v}.map{|v2| v2[0]}}}
|
||||
@sites_order_by_tags << {'no_tag'=>sites.select{|v1| v1[1]== []}.map{|v2| v2[0]}}
|
||||
@sites_order_by_cats = categories.map{|v| {v=>sites.select{|v1| v1[2]== v}.map{|v2| v2[0]}}}
|
||||
@sites_order_by_cats << {'no_category'=>sites.select{|v1| v1[2].nil?}.map{|v2| v2[0]}}
|
||||
end
|
||||
def delete_annc
|
||||
site_annc = SiteAnnc.find(params['site_annc_id']) rescue nil
|
||||
if !site_annc.nil?
|
||||
site_annc.destroy
|
||||
end
|
||||
redirect_to '/admin/registered_sites/announcement'
|
||||
end
|
||||
def update_status(site)
|
||||
tp1 = site.site_statuses.first
|
||||
tp1 = site.site_statuses.create if tp1.nil?
|
||||
if site.site_domain.to_s.blank?
|
||||
urls = nil
|
||||
else
|
||||
urls = site.self_test
|
||||
end
|
||||
if urls.nil?
|
||||
tp1.status = 'domain is blank'
|
||||
tp1.can_login = false
|
||||
elsif urls == [nil,nil]
|
||||
tp1.status = 'domain not found'
|
||||
tp1.href = 'http://'+site.site_domain
|
||||
tp1.can_login = false
|
||||
elsif !urls[0].to_s.empty? || !urls[1].to_s.empty?
|
||||
tp1.status = 'ok'
|
||||
if !urls[0].empty?
|
||||
root_url = urls[0]
|
||||
else
|
||||
root_url = urls[1]
|
||||
end
|
||||
tp1.href = root_url
|
||||
uri = URI(root_url)
|
||||
Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',open_timeout: 30,read_timeout: 30,verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
||||
r3 = login_reomote(http,root_url)
|
||||
if r3.code != '200'
|
||||
tp1.can_login = true
|
||||
else
|
||||
tp1.can_login = false
|
||||
end
|
||||
r4 = get_website(uri,http,r3)
|
||||
uri2 = URI ("#{root_url}/admin/playground")
|
||||
r5 = get_website(uri2,http,r4)
|
||||
if r5.code.to_s == '200'
|
||||
uri3 = URI ("#{root_url}/admin/playground/command")
|
||||
doc = Nokogiri::HTML(r5.body) rescue nil
|
||||
csrf_data = doc.search("meta[name='csrf-token']")[0].attributes['content'].value rescue nil
|
||||
r6 = post_website(uri3,http,r5,{'command' => "ip addr | grep \"inet \" | grep -v 127.0.0.1 | awk '{print $2}'| xargs | awk '{print $1}'"},csrf_data)
|
||||
res = JSON.parse(r6.body) rescue ''
|
||||
if (res == {"success"=>true} || r6.code.to_s != '200')
|
||||
uri4 = URI ("#{root_url}/admin/playground/console_output")
|
||||
count = 0
|
||||
while count < 5
|
||||
r7 = get_website(uri4,http,r6,{'count' => '0'},csrf_data)
|
||||
if (r7.code.to_s == '200' rescue false)
|
||||
r6 = r7
|
||||
response = JSON.parse(r6.body)['response'] rescue nil
|
||||
end
|
||||
if Array(response).count != 0
|
||||
real_ip = Array(response)[0].to_s.split(/\//)[0].scan(/\d+.\d+.\d+.\d+/)[0]
|
||||
tp1.status = tp1.status + " ,ip: #{real_ip}"
|
||||
if !real_ip.to_s.empty?
|
||||
site.real_ip = real_ip
|
||||
site.save
|
||||
end
|
||||
break
|
||||
end
|
||||
count = count + 1
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
tp1.href = 'http://'+site.site_domain
|
||||
tp1.status = 'bad gateway'
|
||||
tp1.can_login = false
|
||||
end
|
||||
tp1.save!
|
||||
end
|
||||
def get_check_log
|
||||
tp = CheckSiteTemp.first
|
||||
tp_all_ids = tp.all_ids
|
||||
count = tp_all_ids.index(params['data'])
|
||||
count = count.nil? ? 0 : (count+1)
|
||||
all_ids = tp_all_ids[count..-1]
|
||||
item = RegisteredSite.find(all_ids).collect do |v|
|
||||
site_status = v.site_statuses.first
|
||||
site_name = v.title.nil? ? v.site_domain : v.title
|
||||
{ id: v.id.to_s,
|
||||
can_login: site_status.can_login,
|
||||
href: site_status.href,
|
||||
site_name: site_name,
|
||||
status: site_status.status}
|
||||
end
|
||||
render :json =>{status: tp.status,item:item,now_id:params['data']}.to_json
|
||||
end
|
||||
def check_site
|
||||
site = RegisteredSite.find(params['item_id'])
|
||||
update_status(site)
|
||||
render :text => "ip: #{site.real_ip}"
|
||||
end
|
||||
def check_all_site
|
||||
tp = CheckSiteTemp.first
|
||||
tp = CheckSiteTemp.create() if tp.nil?
|
||||
tp.all_ids = []
|
||||
tp.status = 'running'
|
||||
tp.save
|
||||
Thread.new do
|
||||
count = RegisteredSite.where(:is_hidden.ne=>true).count
|
||||
batch_l = (count/50.0).ceil
|
||||
(1..batch_l).each do |v|
|
||||
sites = RegisteredSite.where(:is_hidden.ne=>true).sort_by{|v| v.id}[(v-1)*50..(v*50)]
|
||||
sites.each do |site|
|
||||
begin
|
||||
update_status(site)
|
||||
system('sleep 0.5')
|
||||
tp.all_ids << site.id.to_s
|
||||
tp.save
|
||||
rescue => e
|
||||
puts e.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
tp.status = 'finish'
|
||||
tp.save
|
||||
end
|
||||
render :text => ''
|
||||
end
|
||||
def request_website(type,uri,http,pre_req,data,csrf_data)
|
||||
req = (type =='get' ? Net::HTTP::Get.new(uri) : Net::HTTP::Post.new(uri))
|
||||
req.set_form_data(data)
|
||||
req['Cookie'] = pre_req['set-cookie'].to_s.gsub(' path=/; HttpOnly','') rescue ''
|
||||
req['X-CSRF-Token'] = csrf_data
|
||||
req['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
|
||||
http.request req
|
||||
end
|
||||
def get_website(uri,http,pre_req=nil,data={},csrf_data=nil)
|
||||
request_website('get',uri,http,pre_req,data,csrf_data)
|
||||
end
|
||||
def post_website(uri,http,pre_req=nil,data={},csrf_data=nil)
|
||||
request_website('post',uri,http,pre_req,data,csrf_data)
|
||||
end
|
||||
def login_reomote(http,root_url)
|
||||
uri = URI(root_url)
|
||||
r1 = get_website(uri,http)
|
||||
r2 = get_website(uri,http,r1)
|
||||
doc = Nokogiri::HTML(r2.body)
|
||||
checkvalue = doc.css('.login-body').css('input[name=authenticity_token]')[0].attr('value') rescue nil
|
||||
if checkvalue.nil?
|
||||
puts [root_url,r2,doc.css('.login-body').css('input[name=authenticity_token]')]
|
||||
end
|
||||
uri1 = URI("#{root_url}/sessions")
|
||||
data = {'authenticity_token' => checkvalue,'user_name' => 'rulingcom', 'password' =>'orbit_is_great_1','referer_url'=>root_url}
|
||||
r3 = post_website(uri1,http,r2,data)
|
||||
end
|
||||
def bundle_update_remote(site)
|
||||
root_url,log = site.fetch_web_url_and_log
|
||||
tp = BundleUpdateTemp.first
|
||||
tp.now_id = site.id.to_s
|
||||
tp.save
|
||||
timeout_flag = false
|
||||
sel_flag = false
|
||||
not_login_flag = false
|
||||
not_accept_flag = false
|
||||
timeout_count = 0
|
||||
if !root_url.nil?
|
||||
uri = URI(root_url)
|
||||
puts 'starting'
|
||||
begin
|
||||
Net::HTTP.start(uri.host, uri.port,:use_ssl => uri.scheme == 'https',open_timeout: 30,read_timeout: 30,verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
||||
r3 = login_reomote(http,root_url)
|
||||
r4 = get_website(uri,http,r3)
|
||||
uri2 = URI ("#{root_url}/admin/playground")
|
||||
r5 = get_website(uri2,http,r4)
|
||||
if r5.code.to_s != '200'
|
||||
not_login_flag = true
|
||||
end
|
||||
if !not_login_flag
|
||||
not_accept_flag = true
|
||||
uri3 = URI ("#{root_url}/admin/playground/command")
|
||||
doc = Nokogiri::HTML(r5.body) rescue nil
|
||||
csrf_data = doc.search("meta[name='csrf-token']")[0].attributes['content'].value rescue nil
|
||||
r6 = post_website(uri3,http,r5,{'command' => 'bundle'},csrf_data)
|
||||
count = 0
|
||||
flag = false
|
||||
res = JSON.parse(r6.body) rescue ''
|
||||
if (res == {"success"=>true} || r6.code.to_s != '200')
|
||||
not_accept_flag = false
|
||||
last_length = 0
|
||||
while 1
|
||||
uri4 = URI ("#{root_url}/admin/playground/console_output")
|
||||
r7 = get_website(uri4,http,r6,{'count' => '0'},csrf_data)
|
||||
message = log.message
|
||||
timeout_count = timeout_count + 1
|
||||
if timeout_count > 30
|
||||
timeout_flag = true
|
||||
end
|
||||
if (r7.code.to_s == '200' rescue false)
|
||||
r6 = r7
|
||||
response = JSON.parse(r6.body)['response'] rescue nil
|
||||
last_message = nil
|
||||
else
|
||||
response = ''
|
||||
message << "code:#{r7.code.to_s}"
|
||||
last_message = "code:#{r7.code.to_s}"
|
||||
if flag
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
array_res = Array(response).clone
|
||||
res = array_res[-1]
|
||||
if !res.blank?
|
||||
flag = true
|
||||
end
|
||||
if array_res.length > last_length
|
||||
message << array_res[last_length..-1]
|
||||
elsif array_res.length < last_length
|
||||
message << array_res
|
||||
end
|
||||
message = message.flatten 1
|
||||
if res.blank? && flag
|
||||
message << res.inspect
|
||||
count = count + 1
|
||||
elsif res.blank?
|
||||
count = count + 0.3
|
||||
else
|
||||
count = 0
|
||||
last_message = last_message || res
|
||||
if last_message != log.last_message
|
||||
timeout_count = 0
|
||||
end
|
||||
end
|
||||
last_length = array_res.length
|
||||
log.message = message
|
||||
log.last_message = last_message
|
||||
log.save!
|
||||
if message.length >= 5
|
||||
message[-5..-1].each do |v|
|
||||
if v.to_s.downcase.scan(/bundle.*update|run `bundle clean --force`|bundle.*complete!/).length>0 || v.to_s=='finish'
|
||||
sel_flag = true
|
||||
end
|
||||
end
|
||||
end
|
||||
if count>30
|
||||
timeout_flag = true
|
||||
end
|
||||
if sel_flag || timeout_flag
|
||||
break
|
||||
end
|
||||
system('sleep 1')
|
||||
end
|
||||
else
|
||||
log.status = 'failed'
|
||||
log.message << r6.body rescue 'no response'
|
||||
log.last_message = r6.body rescue 'no response'
|
||||
log.save
|
||||
end
|
||||
end
|
||||
#r6 = post_website(uri3,http,r6,{'command' => 'restart_server'},csrf_data)
|
||||
#if (JSON.parse(r6.body) == {"success"=>true} rescue false)
|
||||
# log.last_message += "<br>restart success"
|
||||
#else
|
||||
# log.last_message += "<br>restart failed"
|
||||
#end
|
||||
#log.message[-1] = log.last_message
|
||||
#log.save!
|
||||
end
|
||||
rescue => e
|
||||
timeout_flag = true
|
||||
puts e
|
||||
end
|
||||
if not_accept_flag || not_login_flag
|
||||
log.status = 'failed'
|
||||
log.last_message = "can't login to admin"
|
||||
elsif !timeout_flag
|
||||
system('sleep 5')
|
||||
if sel_flag || site.is_alive?
|
||||
log.status = 'finish'
|
||||
else
|
||||
log.status = 'failed'
|
||||
end
|
||||
else
|
||||
system('sleep 10')
|
||||
if site.is_alive?
|
||||
log.status = 'finish'
|
||||
else
|
||||
log.status = 'failed'
|
||||
#update_flags = UpdateFlags.first
|
||||
#update_flags.bundle_update_flag = false
|
||||
#update_flags.save!
|
||||
end
|
||||
end
|
||||
log.last_time = Time.now
|
||||
log.save!
|
||||
end
|
||||
end
|
||||
def stop_bundle_update
|
||||
update_flags = UpdateFlags.first
|
||||
update_flags.bundle_update_flag = false
|
||||
update_flags.save
|
||||
render :text => ''
|
||||
end
|
||||
def get_detail
|
||||
site = RegisteredSite.find(params['item_id']) rescue nil
|
||||
message = ''
|
||||
if !site.nil?
|
||||
message = site.bundle_update_logs.first.message.join('<br>') rescue ''
|
||||
end
|
||||
render :text => message
|
||||
end
|
||||
def destroy_bundle_temp
|
||||
render :text => (BundleUpdateTemp.first.destroy.inspect rescue '')
|
||||
end
|
||||
def bundle_update
|
||||
update_flags = UpdateFlags.first.nil? ? UpdateFlags.new() : UpdateFlags.first
|
||||
update_flags.bundle_update_flag = true
|
||||
update_flags.save
|
||||
if BundleUpdateTemp.first.nil?
|
||||
if params['item_ids'][0] == 'all'
|
||||
item_ids = RegisteredSite.all.collect(&:id).map{|v| v.to_s}.reverse
|
||||
else
|
||||
item_ids = params['item_ids']
|
||||
end
|
||||
BundleUpdateTemp.create(all_ids: item_ids,now_id: nil)
|
||||
Thread.new do
|
||||
clone_item_ids = item_ids.clone
|
||||
clone_item_ids.each do |site_id|
|
||||
if !UpdateFlags.first.bundle_update_flag
|
||||
tp = BundleUpdateTemp.first
|
||||
tp.now_id = 'terminated'
|
||||
tp.save
|
||||
Thread.current.terminate!
|
||||
end
|
||||
site = RegisteredSite.find(site_id) rescue nil
|
||||
if !site.nil? && (site.site_statuses.first.can_login rescue true)
|
||||
bundle_update_remote(site)
|
||||
system('sleep 5')
|
||||
elsif !site.nil?
|
||||
if site.bundle_update_logs.first.nil?
|
||||
log = site.bundle_update_logs.create()
|
||||
else
|
||||
log = site.bundle_update_logs.first
|
||||
end
|
||||
log.status = 'failed'
|
||||
log.last_message = "can't login"
|
||||
log.save
|
||||
end
|
||||
end
|
||||
tp = BundleUpdateTemp.first
|
||||
tp.now_id = 'finish'
|
||||
tp.save
|
||||
end
|
||||
render :json => {status: 'success'}
|
||||
elsif BundleUpdateTemp.first.all_ids == params['item_ids']
|
||||
render :json => {status: 'success'}
|
||||
else
|
||||
render :json => {status: 'failed'}
|
||||
end
|
||||
end
|
||||
def get_message
|
||||
tp = BundleUpdateTemp.first.now_id
|
||||
if tp.nil?
|
||||
render :json => {status: 'initializing'}
|
||||
elsif tp=='terminated'
|
||||
BundleUpdateTemp.first.destroy
|
||||
render :json => {status: tp}
|
||||
else
|
||||
site_id = (tp=='finish' ? BundleUpdateTemp.first.all_ids.last : tp)
|
||||
if tp=='finish'
|
||||
BundleUpdateTemp.first.destroy
|
||||
end
|
||||
site = RegisteredSite.find(site_id) rescue nil
|
||||
if !site.nil?
|
||||
status = tp=='finish' ? 'finish' : 'running'
|
||||
log = site.bundle_update_logs.first
|
||||
render :json => {status: status,
|
||||
item: {item_id: site_id,
|
||||
status: log.status,
|
||||
last_time: log.last_time,
|
||||
last_message: log.last_message}}
|
||||
else
|
||||
render :json => {status: 'not found',
|
||||
item: {item_id: site_id,
|
||||
status: 'not found',
|
||||
last_time: 'not found',
|
||||
last_message: 'not found'}}
|
||||
end
|
||||
end
|
||||
end
|
||||
def bundle_update_remote_show
|
||||
@registeredsites = RegisteredSite.all.order_by(sort)
|
||||
.with_categories(filters("category"))
|
||||
.with_tags(filters("tag")).desc(:created_at)
|
||||
@table_fields = table_fields_for_bundle_update
|
||||
@tags = @module_app.tags
|
||||
@categories = @module_app.categories.enabled
|
||||
@filter_fields = filter_fields_without_status(@categories, @tags)
|
||||
@registeredsites = search_data(@registeredsites,[:title,:site_domain]).page(params[:page]).per(RegisteredSite.all.count)#.per(10)
|
||||
|
||||
if request.xhr?
|
||||
render :partial => "bundle_update_remote_show"
|
||||
end
|
||||
end
|
||||
def edit
|
||||
@registered_site = RegisteredSite.find(params[:id])
|
||||
if can_edit_or_delete?(@registered_site)
|
||||
|
@ -75,7 +514,9 @@ class Admin::RegisteredSitesController < OrbitAdminController
|
|||
def table_fields
|
||||
[:domain, :admin_email, :status, :category, :tags, :permission]
|
||||
end
|
||||
|
||||
def table_fields_for_bundle_update
|
||||
[:domain, 'registered_sites.bundle_update', 'registered_sites.bundle_update_status', :category, 'registered_sites.last_message']
|
||||
end
|
||||
def registered_site_params
|
||||
params.require(:registered_site).permit!
|
||||
end
|
||||
|
|
|
@ -8,4 +8,14 @@ class RegisteredSitesController < ApplicationController
|
|||
}
|
||||
}
|
||||
end
|
||||
def git_auth
|
||||
user_ip = params['user_ip']
|
||||
all_ips = RegisteredSite.all.collect{|v| [v.ip,v.real_ip]}.flatten.compact
|
||||
puts user_ip
|
||||
if all_ips.include?(user_ip) || user_ip == '118.163.60.152' || user_ip == '163.19.249.14' || user_ip == '203.72.2.177'
|
||||
render :text=>'hello',:status=> 200
|
||||
else
|
||||
render :text=>'forbidden',:status=> 500
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
class BundleUpdateLog
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :last_time, default: Time.now
|
||||
field :status, type: String, default: 'running'
|
||||
field :last_message, type: String, default: ''
|
||||
field :message, type: Array, default: []
|
||||
belongs_to :registered_site
|
||||
def last_time
|
||||
self['last_time'].in_time_zone.strftime('%Y/%m/%d %H:%M')
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class BundleUpdateTemp
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :all_ids
|
||||
field :now_id
|
||||
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class CheckSiteTemp
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
|
||||
field :all_ids
|
||||
field :status
|
||||
end
|
|
@ -4,7 +4,8 @@ class RegisteredSite
|
|||
include OrbitTag::Taggable
|
||||
include OrbitCategory::Categorizable
|
||||
include Slug
|
||||
|
||||
field :ip
|
||||
field :real_ip
|
||||
field :site_domain
|
||||
field :title, as: :slug_title, localize: true
|
||||
field :description, localize: true
|
||||
|
@ -12,18 +13,31 @@ class RegisteredSite
|
|||
field :admin_email
|
||||
field :site_confirmed, type: Boolean, :default => false
|
||||
field :confirmation_token
|
||||
|
||||
field :is_hidden,type: Boolean,:default => false
|
||||
has_many :bundle_update_logs
|
||||
has_many :site_logs
|
||||
has_many :installed_modules
|
||||
has_many :tickets
|
||||
has_many :site_statuses
|
||||
|
||||
before_save :generate_ip
|
||||
after_create do
|
||||
self.bundle_update_logs.create
|
||||
end
|
||||
index({ confirmation_token: 1}, { unique: true })
|
||||
scope :active, ->{where(:access_granted => true,:site_confirmed => true)}
|
||||
|
||||
def generate_ip
|
||||
self[:ip] = %x[dig +short '#{self[:site_domain]}'].split("\n")
|
||||
if self[:ip].count==0
|
||||
self[:ip] = self[:site_domain]
|
||||
end
|
||||
end
|
||||
def site_token
|
||||
self.uid
|
||||
end
|
||||
|
||||
def show_name
|
||||
self.title.nil? ? self.site_domain : self.title
|
||||
end
|
||||
def generate_confirmation_token
|
||||
self.confirmation_token = SecureRandom.hex(5)
|
||||
self.save
|
||||
|
@ -32,4 +46,64 @@ class RegisteredSite
|
|||
def active?
|
||||
return self.access_granted && self.site_confirmed
|
||||
end
|
||||
def is_alive?
|
||||
urls = self.self_test
|
||||
if !urls[0].to_s.empty? || !urls[1].to_s.empty?
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
def self_test
|
||||
domain = self.site_domain
|
||||
types = ['http','https']
|
||||
urls = types.collect do |type|
|
||||
root_url = "#{type}://#{domain}"
|
||||
uri0 = URI(root_url)
|
||||
r = Net::HTTP.start(uri0.host, uri0.port,:use_ssl => uri0.scheme == 'https',open_timeout: 20,read_timeout: 20,verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
|
||||
req = Net::HTTP::Get.new(uri0)
|
||||
req['User-Agent'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36'
|
||||
http.request req
|
||||
end rescue nil
|
||||
code = r.code.to_s rescue nil
|
||||
if code == '200'
|
||||
root_url
|
||||
elsif code.nil?
|
||||
nil
|
||||
else
|
||||
''
|
||||
end
|
||||
end
|
||||
end
|
||||
def fetch_web_url_and_log
|
||||
if self.bundle_update_logs.first.nil?
|
||||
log = self.bundle_update_logs.create()
|
||||
else
|
||||
log = self.bundle_update_logs.first
|
||||
end
|
||||
urls = self.self_test
|
||||
log.last_time = Time.now
|
||||
if urls == [nil,nil]
|
||||
log.message = ['domain not found']
|
||||
log.last_message = 'domain not found'
|
||||
log.status = 'failed'
|
||||
root_url = nil
|
||||
elsif !urls[0].to_s.empty? || !urls[1].to_s.empty?
|
||||
if !urls[0].empty?
|
||||
root_url = urls[0]
|
||||
else
|
||||
root_url = urls[1]
|
||||
end
|
||||
log.message = ["open the web by #{root_url}"]
|
||||
log.status = 'running'
|
||||
log.last_message = "open the web by #{root_url}"
|
||||
else
|
||||
log.message = ['Maybe the web need to restart']
|
||||
log.last_message = 'Maybe the web need to restart'
|
||||
log.status = 'failed'
|
||||
root_url = nil
|
||||
end
|
||||
log.save!
|
||||
[root_url,log]
|
||||
end
|
||||
end
|
|
@ -0,0 +1,17 @@
|
|||
class SiteAnnc
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
field :title,type: Hash, default: {en:'',zh_tw:''}
|
||||
field :visible, type: Boolean, default: true
|
||||
field :content,type: Hash, default: {en:'',zh_tw:''}
|
||||
field :see_more_link
|
||||
field :recieve_sites,type: Array, default: []
|
||||
field :watch_list,type: Array, default: []
|
||||
field :send_all,type: Boolean,default: false
|
||||
def recieve_sites
|
||||
RegisteredSite.find(self[:recieve_sites]) rescue []
|
||||
end
|
||||
def recieve_sites=(value)
|
||||
self[:recieve_sites] = Array(value).uniq
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class SiteStatus
|
||||
include Mongoid::Document
|
||||
include Mongoid::Timestamps
|
||||
field :status
|
||||
field :can_login,default: false
|
||||
field :href, type: String ,default: ''
|
||||
belongs_to :registered_site
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class UpdateFlags
|
||||
include Mongoid::Document
|
||||
|
||||
field :bundle_update_flag, type: Boolean, default: true
|
||||
|
||||
end
|
|
@ -0,0 +1,79 @@
|
|||
|
||||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<th class="s0" style="width: 5%;">
|
||||
<input type="checkbox">
|
||||
</th>
|
||||
<% @table_fields.zip(['20%','10%','15%','15%']).each do |f| %>
|
||||
<th style="width:<%= f[1] %>;"><%= t(f[0]) %></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @registeredsites.each_with_index do |site,index1| %>
|
||||
<% status = site.is_hidden == true ? 'is_hidden' : site.bundle_update_logs.first.status
|
||||
if status == 'failed'
|
||||
status = 'error'
|
||||
elsif status == 'finish'
|
||||
status = 'success'
|
||||
end
|
||||
%>
|
||||
<tr id="<%= site.id %>" class="<%= status %>">
|
||||
<td class="s0" style="">
|
||||
<% if site.is_hidden != true %>
|
||||
<input type="checkbox" class='checkbox_site'>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<a href="http://<%= site.site_domain %>/" target="_blank"><%= site.title.nil? ? site.site_domain : site.title %></a>
|
||||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills">
|
||||
<% if can_edit_or_delete?(site) %>
|
||||
<li><a href="/admin/registered_sites/<%= site.id.to_s %>/edit"><%= t(:edit) %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button onclick="bundle_update('<%= site.id %>')">
|
||||
<%= t("registered_sites.update") %>
|
||||
</button>
|
||||
<button onclick="get_detail('<%= site.id %>')">
|
||||
<%= t("registered_sites.get_detail") %>
|
||||
</button>
|
||||
<button onclick="check_site('<%= site.id %>')">
|
||||
check site
|
||||
</button>
|
||||
</td>
|
||||
<td class="bundle_update_logs">
|
||||
<% if !site.site_confirmed %>
|
||||
<span class="badge badge-important"><%= t("registered_sites.site_inactive") %></span><br />
|
||||
<%= t("registered_sites.email_not_confirmed") %>
|
||||
<% elsif !site.access_granted %>
|
||||
<span class="badge badge-important"><%= t("registered_sites.site_inactive") %></span><br />
|
||||
<%= t("registered_sites.site_permission_revoked") %>
|
||||
<% else %>
|
||||
<span class="badge badge-success"><%= t("registered_sites.site_active") %></span><br />
|
||||
<% end %>
|
||||
<% ['last_time','status'].each do |log_t| %>
|
||||
<span>
|
||||
<a class="<%= log_t %>" title='<%= t("registered_sites.#{log_t}") %>'><%= site.bundle_update_logs.first.send(log_t) rescue '' %></a>
|
||||
</span>
|
||||
<br>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= site.category.nil? ? "Category not assigned." : "<span class='label label-info'>#{site.category.title}</span>".html_safe %></td>
|
||||
<td>
|
||||
<span class="last_message"><%=site.bundle_update_logs.first.last_message.html_safe rescue '' %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<%=
|
||||
content_tag :div, class: "bottomnav clearfix" do
|
||||
content_tag :div, paginate(@registeredsites), class: "pagination pagination-centered"
|
||||
end
|
||||
%>
|
|
@ -51,7 +51,12 @@
|
|||
<%= f.text_field :admin_email %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label muted">hidden</label>
|
||||
<div class="controls">
|
||||
<%= f.check_box :is_hidden,{},'true','false' %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tag Module -->
|
||||
|
|
|
@ -0,0 +1,99 @@
|
|||
<% content_for :page_specific_javascript do -%>
|
||||
<%= javascript_include_tag "select2/select2.min" %>
|
||||
<%= javascript_include_tag "lib/jquery.nanoscroller" %>
|
||||
<% end -%>
|
||||
<% content_for :page_specific_css do -%>
|
||||
<%= stylesheet_link_tag "member_select" %>
|
||||
<% end %>
|
||||
|
||||
<div id="selected_email_users" class="selected_users">
|
||||
<% recieve_sites.each do |recieve_site| %>
|
||||
<span class="alert alert-info selected_user" id="<%= recieve_site.id %>">
|
||||
<span class='close remove_user' onclick='removeUser($(this))'>x</span>
|
||||
<%= recieve_site.title.nil? ? recieve_site.site_domain : recieve_site.title %>
|
||||
<%= hidden_field_tag field, recieve_site.id %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<a class="btn btn-primary btn-small" onclick="delete_all_sites()">delete all</a>
|
||||
<a class="btn btn-primary btn-small select_user_modal"><%= t(:add) %></a>
|
||||
<script type="text/javascript">
|
||||
var mail_users = Array();
|
||||
function delete_all_sites(){
|
||||
$('.alert.alert-info.selected_user').remove()
|
||||
}
|
||||
$(function(){
|
||||
$.each($(".selected_user"),function(){
|
||||
mail_users.push($(this).attr("id"));
|
||||
});
|
||||
|
||||
$(".select_user_modal").click(function(){
|
||||
if($("#select_user").length==0) {
|
||||
$("#main-wrap").after("<span id='select_user'></span>");
|
||||
}
|
||||
$.get("<%= get_select_box_admin_registered_sites_path %>",function(modal){
|
||||
$("#select_user").html(modal);
|
||||
$('#member-filter').ready(function(){
|
||||
updateModal();
|
||||
$("#member-filter").modal();
|
||||
$('#member-filter').on('shown', function() {
|
||||
$(".nano").nanoScroller();
|
||||
});
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
var addByRole = function(role){
|
||||
$.each($("#r_"+role+" .check-item"), function(){
|
||||
mail_users.push($(this).find("input[type='checkbox']").val());
|
||||
});
|
||||
}
|
||||
|
||||
var removeUser = function(user){
|
||||
mail_users = $.grep(mail_users, function(value) {return value != $(user).parent().attr('id');});
|
||||
$(user).parent().remove();
|
||||
}
|
||||
|
||||
var updateUsers = function(){
|
||||
$.each($(".role_field input:checked"), function(){
|
||||
addByRole($(this).val());
|
||||
});
|
||||
|
||||
$("#selected_email_users").html("");
|
||||
mail_users = $.unique(mail_users);
|
||||
|
||||
$.each(mail_users, function(i, user_id){
|
||||
var username = $("input[value='"+user_id+"']").parent().find(".user-name").html();
|
||||
$("#selected_email_users").append(
|
||||
" <span class='alert alert-info selected_user' id='"+user_id+"'>"+
|
||||
"<span class='close remove_user' onclick='removeUser($(this))'>x</span>"+
|
||||
username+
|
||||
"<input type='hidden' name='<%= field %>' value='"+user_id+"' >"+
|
||||
"</span>"
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
var updateModal = function(){
|
||||
$.each($("#selected_email_users .selected_user"),function(){
|
||||
var user_id = $(this).attr('id');
|
||||
$("input[value='"+user_id+"']").parent("li").hide();
|
||||
});
|
||||
|
||||
$('.check-item').click(function(e){
|
||||
var user_id = $(e.target).find("input[type='checkbox']").val();
|
||||
if (user_id==undefined){
|
||||
user_id = $(e.target).val()
|
||||
}
|
||||
$(e.target).toggleClass("active");
|
||||
if($(e.target).hasClass("active")){
|
||||
mail_users.push(user_id);
|
||||
}else{
|
||||
mail_users = $.grep(mail_users, function(value) {return value != user_id;});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,100 @@
|
|||
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
|
||||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
|
||||
<script type="text/javascript">
|
||||
$('div#index_table').ready(function(){
|
||||
$("#detail_div").dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
show: "blind",
|
||||
hide: "explode",
|
||||
maxHeight: 500,
|
||||
width: '50em',
|
||||
close:function(){
|
||||
see_flag = false
|
||||
},
|
||||
buttons: {
|
||||
Ok: function() {
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
}
|
||||
});
|
||||
})
|
||||
function get_watch_list(item) {
|
||||
$.ajax({
|
||||
url : "<%= get_watch_list_admin_registered_sites_path %>",
|
||||
dataType : "json",
|
||||
data: {data: item},
|
||||
type : "post",
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
var html_data = '<table><tbody>'
|
||||
$(data).each(function(i,v){
|
||||
var par1;
|
||||
if (v[0][1] == ''){
|
||||
par1 = v[0][0]
|
||||
}else{
|
||||
par1 = '<a target="_blank" href="http://' + v[0][1]+'">'+v[0][0]+'</a> :'
|
||||
}
|
||||
html_data = html_data + "<tr><td>"+ par1+"</td><td>"+v[1]+"</td></tr>"
|
||||
})
|
||||
html_data = html_data + '</tbody></table'
|
||||
$("#detail_div").html(html_data)
|
||||
$("#detail_div").dialog("open")
|
||||
}
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<div id="index_table">
|
||||
<div id="detail_div">
|
||||
|
||||
</div>
|
||||
<button style="margin-bottom: 1em;" onclick="window.location.href='/admin/registered_sites/new/edit_annc'">
|
||||
<%= t('site_annc.new') %>
|
||||
</button>
|
||||
<table class="table main-list">
|
||||
<thead>
|
||||
<tr class="sort-header">
|
||||
<th style="width: 50%;">
|
||||
<%= t('site_annc.title') %>(中文/英文)
|
||||
</th>
|
||||
<th style="width: 20%;">
|
||||
<%= t('site_annc.watch_list_count') %>
|
||||
</th>
|
||||
<th style="width: 30%;">
|
||||
<%= t('site_annc.see_more_link') %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @site_anncs.each do |site_annc| %>
|
||||
<tr>
|
||||
<td>
|
||||
<%= site_annc[:title][:zh_tw].to_s.html_safe %>
|
||||
/
|
||||
<%= site_annc[:title][:en].to_s.html_safe %>
|
||||
<div class="quick-edit" style="display: flex;">
|
||||
<a href="/admin/registered_sites/<%= site_annc.id.to_s %>/edit_annc" style="margin-right: 1em;">
|
||||
<%= t(:edit) %></a>
|
||||
<a href="/admin/registered_sites/<%= site_annc.id.to_s %>/delete_annc">delete</a>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<a style="cursor: pointer;" onclick="get_watch_list('<%= site_annc.id %>')">
|
||||
<%= site_annc.watch_list.count %>
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to site_annc.see_more_link.to_s,site_annc.see_more_link.to_s %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<%=
|
||||
content_tag :div, class: "bottomnav clearfix" do
|
||||
content_tag :div, paginate(@site_anncs), class: "pagination pagination-centered"
|
||||
end
|
||||
%>
|
||||
</div>
|
|
@ -0,0 +1,348 @@
|
|||
<script src="https://code.jquery.com/ui/1.11.1/jquery-ui.min.js"></script>
|
||||
<link rel="stylesheet" href="https://code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css" />
|
||||
<% if !BundleUpdateTemp.first.nil? %>
|
||||
<% tp = BundleUpdateTemp.first %>
|
||||
全部:
|
||||
<%= tp.all_ids.count %>
|
||||
目前:
|
||||
<% now_index = tp.all_ids.index(tp.now_id) %>
|
||||
<% if tp.now_id=='finish'
|
||||
now_index = tp.all_ids.count - 1
|
||||
end
|
||||
%>
|
||||
<%= now_index.nil? ? "unprocess" : now_index+1 %>
|
||||
<br>
|
||||
失敗(僅確認可登入):
|
||||
<%= now_index.nil? ? 0 : RegisteredSite.where(:id.in => Array(tp.all_ids[0..now_index])).select{|v| (v.site_statuses.first.can_login rescue true) && v.bundle_update_logs.first.status=='failed'}.collect{|v| "<a href=\"http://#{v.site_domain}\">#{v.show_name}</a> :#{v.bundle_update_logs.first.last_message}"}.join('<br>').html_safe %>
|
||||
<% end %>
|
||||
<%= render_filter @filter_fields, "index_table" %>
|
||||
<button onclick="bundle_update('select')">
|
||||
<%= t("registered_sites.update_select") %>
|
||||
</button>
|
||||
<button onclick="bundle_update('all')">
|
||||
update all
|
||||
</button>
|
||||
<input type="checkbox" id='select_behind'>
|
||||
select all behind
|
||||
<button onclick="stop_bundle_update()">
|
||||
<%= t("registered_sites.stop_bundle_update") %>
|
||||
</button>
|
||||
<button onclick="destroy_bundle_temp()">
|
||||
<%= t("registered_sites.destroy_bundle_temp") %>
|
||||
</button>
|
||||
<button onclick="check_all_site()">
|
||||
check all site
|
||||
</button>
|
||||
<button onclick="check_log()">
|
||||
check log
|
||||
</button>
|
||||
<input type="radio" name="show_opt" value="show_all">
|
||||
show_all
|
||||
<input type="radio" name="show_opt" value="show_ok_only">
|
||||
ok only
|
||||
<input type="radio" name="show_opt" value="show_fail_only">
|
||||
fail only
|
||||
<div id="status"></div>
|
||||
<div id="detail_div" class="show_ok show_fail">
|
||||
</div>
|
||||
<style type="text/css">
|
||||
tr.idle td {
|
||||
background: #f8f5a4;
|
||||
}
|
||||
td {
|
||||
font-weight: bold;
|
||||
}
|
||||
#status{
|
||||
font-size: 2em;
|
||||
margin-bottom: 0.3em;
|
||||
}
|
||||
#detail_div{
|
||||
overflow: auto;
|
||||
max-height:500px;
|
||||
}
|
||||
.can_login, .can_not_login{
|
||||
display: none;
|
||||
}
|
||||
.can_login{
|
||||
color: #468847;
|
||||
}
|
||||
.can_not_login{
|
||||
color: #fe0a07;
|
||||
}
|
||||
.show_ok .can_login{
|
||||
display: block;
|
||||
}
|
||||
.show_fail .can_not_login{
|
||||
display: block;
|
||||
}
|
||||
.is_hidden > td {
|
||||
background: #979797;
|
||||
}
|
||||
<%# 'success'=> green, 'error' => 'red' %>
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var item_id1
|
||||
var see_flag = true
|
||||
$.fn.get_select_ids = function(){
|
||||
var ids = $.map(this,function(item, index) {
|
||||
return $(item).attr('id');
|
||||
});
|
||||
return ids;
|
||||
}
|
||||
function check_site(item_id){
|
||||
alert("checking")
|
||||
$.ajax({
|
||||
url : "<%= check_site_admin_registered_sites_path %>",
|
||||
dataType : "text",
|
||||
data: {item_id: item_id},
|
||||
type : "post",
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
alert(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
function destroy_bundle_temp(){
|
||||
$.ajax({
|
||||
url : "<%= destroy_bundle_temp_admin_registered_sites_path %>",
|
||||
dataType : "text",
|
||||
type : "post",
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
console.log(data)
|
||||
}
|
||||
})
|
||||
}
|
||||
function check_log(){
|
||||
see_flag = true
|
||||
$("#detail_div").dialog("open");
|
||||
get_check_log('all')
|
||||
}
|
||||
function get_check_log(item){
|
||||
$.ajax({
|
||||
url : "<%= get_check_log_admin_registered_sites_path %>",
|
||||
dataType : "json",
|
||||
data: {data: item},
|
||||
type : "post",
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
var html_data = $('#detail_div').html()
|
||||
var class_item;
|
||||
var now_id = data['now_id'];
|
||||
$(data['item']).each(function(i,v){
|
||||
if (v['can_login']){
|
||||
class_item = 'can_login'
|
||||
}
|
||||
else{
|
||||
class_item = 'can_not_login'
|
||||
}
|
||||
now_id = v['id']
|
||||
html_data = html_data + "<div class='"+class_item+"'><a target='_blank' href='" +v['href']+"'>"+v['site_name']+"</a>:<span>"+v['status']+"</span></div>"
|
||||
})
|
||||
$('#detail_div').html(html_data)
|
||||
if (data['status']!='finish' && see_flag){
|
||||
window.setTimeout(function(){get_check_log(now_id)},1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
function check_all_site(){
|
||||
$.ajax({
|
||||
url : "<%= check_all_site_admin_registered_sites_path %>",
|
||||
dataType : "text",
|
||||
type : "post",
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(){
|
||||
alert('start to check')
|
||||
}
|
||||
})
|
||||
}
|
||||
function stop_bundle_update(){
|
||||
$.ajax({
|
||||
url : "<%= stop_bundle_update_admin_registered_sites_path %>",
|
||||
dataType : "text",
|
||||
type : "post",
|
||||
data: {item_ids: item_id1},
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
}
|
||||
})
|
||||
}
|
||||
function bundle_update(item_id){
|
||||
if (item_id=='select'){
|
||||
item_id1 = $('tr.idle').get_select_ids()
|
||||
}else{
|
||||
$('tr#'+item_id).addClass('idle')
|
||||
item_id1 = Array(item_id)
|
||||
}
|
||||
$.ajax({
|
||||
url : "<%= bundle_update_admin_registered_sites_path %>",
|
||||
dataType : "json",
|
||||
type : "post",
|
||||
data: {item_ids: item_id1},
|
||||
error: function(){
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
if (item_id != 'all'){
|
||||
if (data['status']=='success'){
|
||||
window.setTimeout(function(){get_message(item_id1)},100)
|
||||
}
|
||||
else{
|
||||
alert('there may be still a process proccessing,please try again later')
|
||||
}
|
||||
}else{
|
||||
alert("the update information can only update at refresh the page")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
$.fn.change_item = function(item){
|
||||
$(this).find('.last_message').html(item['last_message'])
|
||||
$(this).find('.status').text(item['status'])
|
||||
$(this).attr('class','')
|
||||
if (item['status']=='failed'){
|
||||
$(this).addClass('error')
|
||||
}else if (item['status']=='finish'){
|
||||
$(this).addClass('success')
|
||||
}else{
|
||||
$(this).addClass('idle')
|
||||
}
|
||||
$(this).find('.last_time').text(item['last_time'])
|
||||
}
|
||||
function get_detail(item_id){
|
||||
$.ajax({
|
||||
url : "<%= get_detail_admin_registered_sites_path %>",
|
||||
dataType : "text",
|
||||
type : "post",
|
||||
data: {item_id: item_id},
|
||||
error: function(data){
|
||||
console.log(data)
|
||||
alert('init upload process failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
$('#detail_div').html(data)
|
||||
$("#detail_div").dialog("open");
|
||||
}
|
||||
})
|
||||
}
|
||||
function get_message(item_id){
|
||||
$.ajax({
|
||||
url : "<%= get_message_admin_registered_sites_path %>",
|
||||
dataType : "json",
|
||||
type : "post",
|
||||
data: {item_ids: item_id},
|
||||
error: function(){
|
||||
alert('get status failed, please try again later.')
|
||||
},
|
||||
success: function(data){
|
||||
console.log(data)
|
||||
$('#status').text(data['status'])
|
||||
if (data['status']=='terminated' || data['status']=='not found'){
|
||||
$('#status').css('color','#fe0a07')
|
||||
if (data['status']=='terminated'){
|
||||
alert('terminated by user')
|
||||
}
|
||||
else{
|
||||
var item = data['item']
|
||||
var tr_tag = $('tr#'+item['item_id'])
|
||||
tr_tag.removeClass('idle')
|
||||
tr_tag.addClass('error')
|
||||
tr_tag.change_item(item)
|
||||
window.setTimeout(function(){get_message(item_id1)},1000)
|
||||
}
|
||||
}
|
||||
else if (data['status']=='finish'){
|
||||
var item = data['item']
|
||||
var tr_tag = $('tr#'+item['item_id'])
|
||||
tr_tag.removeClass('idle')
|
||||
tr_tag.addClass('success')
|
||||
tr_tag.change_item(item)
|
||||
$('#status').css('color','#468847')
|
||||
}
|
||||
else{
|
||||
if (data['status']=='running'){
|
||||
var item = data['item']
|
||||
var tr_tag = $('tr#'+item['item_id'])
|
||||
tr_tag.change_item(item)
|
||||
$('#status').css('color','#468847')
|
||||
}else{
|
||||
$('#status').css('color','#b5b15d')
|
||||
}
|
||||
window.setTimeout(function(){get_message(item_id1)},1000)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
$('div#index_table').ready(function(){
|
||||
$('.checkbox_site').click(function(){
|
||||
if ($('#select_behind').prop('checked')){
|
||||
var click_index = $(this).index('.checkbox_site')
|
||||
for (var i=click_index+1;i<$('.checkbox_site').length;i++){
|
||||
$('.checkbox_site').eq(i).prop('checked',true)
|
||||
$('.checkbox_site').eq(i).trigger('change')
|
||||
}
|
||||
}
|
||||
})
|
||||
$("#detail_div").dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
show: "blind",
|
||||
hide: "explode",
|
||||
maxHeight: 500,
|
||||
width: '50em',
|
||||
close:function(){
|
||||
see_flag = false
|
||||
},
|
||||
buttons: {
|
||||
Ok: function() {
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
}
|
||||
});
|
||||
$('input[name=show_opt]').change(function(){
|
||||
var val = $(this).val()
|
||||
if (val=='show_all'){
|
||||
$('#detail_div').attr('class','show_ok show_fail')
|
||||
$('.table tr').show()
|
||||
}else if (val=='show_ok_only'){
|
||||
$('#detail_div').attr('class','show_ok')
|
||||
$('.table tr.success').show()
|
||||
$('.table tr.error').hide()
|
||||
}else{
|
||||
$('#detail_div').attr('class','show_fail')
|
||||
$('.table tr.success').hide()
|
||||
$('.table tr.error').show()
|
||||
}
|
||||
})
|
||||
$('th.s0 > input[type=checkbox]').change(function(){
|
||||
if ($(this).prop('checked')){
|
||||
$('td:visible.s0 > input[type=checkbox]').prop('checked',true)
|
||||
$('td:visible.s0 > input[type=checkbox]').parents('tr').addClass('idle')
|
||||
}
|
||||
else{
|
||||
$('td:visible.s0 > input[type=checkbox]').prop('checked',false)
|
||||
$('td:visible.s0 > input[type=checkbox]').parents('tr').removeClass('idle')
|
||||
}
|
||||
})
|
||||
$('td.s0 > input[type=checkbox]').change(function(){
|
||||
if ($(this).prop('checked'))
|
||||
$(this).parents('tr').addClass('idle')
|
||||
else
|
||||
$(this).parents('tr').removeClass('idle')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
</script>
|
||||
<div id="index_table">
|
||||
<%= render 'bundle_update_remote_show'%>
|
||||
</div>
|
|
@ -0,0 +1,76 @@
|
|||
<% content_for :page_specific_css do %>
|
||||
<%= stylesheet_link_tag "lib/main-forms" %>
|
||||
<%= stylesheet_link_tag "lib/main-list" %>
|
||||
<%= stylesheet_link_tag "member_select" %>
|
||||
<% end %>
|
||||
<% content_for :page_specific_javascript do %>
|
||||
<%= javascript_include_tag "lib/module-area" %>
|
||||
<%= javascript_include_tag "registered_site_progress" %>
|
||||
<% end %>
|
||||
<style type="text/css">
|
||||
.col-sm-10.controls{
|
||||
margin-left:0px;
|
||||
}
|
||||
.input-append input{
|
||||
width: 150px;
|
||||
}
|
||||
</style>
|
||||
<form action="/admin/registered_sites/<%= @site_annc.id.to_s %>/update_annc" method="post">
|
||||
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
|
||||
<!-- Input Area -->
|
||||
<div class="input-area">
|
||||
<div class="control-group big-group">
|
||||
<label class="control-label muted"><%= t("site_annc.recieve_sites") %></label>
|
||||
<div class="controls">
|
||||
<%= render partial: 'admin/registered_sites/site_selection_box', locals: {field: 'recieve_sites[]', recieve_sites:(@site_annc.recieve_sites || [])} %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label><%= t('site_annc.visible') %></label>
|
||||
<%= check_box_tag 'visible', 'true', @site_annc.visible %>
|
||||
</div>
|
||||
<div class="controls">
|
||||
<label>Send to all site:</label>
|
||||
<%= check_box_tag 'send_all', 'true', @site_annc.send_all %>
|
||||
</div>
|
||||
<!-- Language Tabs -->
|
||||
<div class="nav-name"><strong><%= t(:language) %></strong></div>
|
||||
<ul class="nav nav-pills language-nav">
|
||||
<% I18n.available_locales.each_with_index do |locale, i| %>
|
||||
<li class="<%= 'active' if i == 0 %>">
|
||||
<a data-toggle="tab" href=".<%= locale %>"><%= t(locale) %></a>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
<!-- Language -->
|
||||
<div class="tab-content module-area">
|
||||
<% I18n.available_locales.each_with_index do |locale, i| %>
|
||||
<div class="<%= locale %> tab-pane fade <%= ( i == 0 ) ? "in active" : '' %>">
|
||||
<!-- Title-->
|
||||
<div class="control-group input-title">
|
||||
<label class="control-label muted"><%= t('site_annc.title') %></label>
|
||||
<div class="controls">
|
||||
<%= text_area_tag "title[#{locale}]",(@site_annc.title[locale] rescue nil), class: "ckeditor_reduce input-block-level", placeholder: t(:title) %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="control-group input-title">
|
||||
<label class="control-label muted"><%= t('site_annc.content') %></label>
|
||||
<div class="controls">
|
||||
<%= text_area_tag "content[#{locale}]",(@site_annc.content[locale] rescue nil), class: "ckeditor input-block-level", placeholder: t('site_annc.content') %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
<label class="control-label muted"><%= t('site_annc.see_more_link') %></label>
|
||||
<div class="controls">
|
||||
<%= url_field_tag "see_more_link",(@site_annc.see_more_link rescue nil),class: "input-block-level", placeholder: t('site_annc.see_more_link') %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Form Actions -->
|
||||
<div class="form-actions">
|
||||
<%= submit_tag t('submit'), class: 'btn btn-primary' %>
|
||||
<input type="hidden" name="referer_url" value="<%= get_referer_url %>">
|
||||
<%= link_to t('cancel'), '/admin/registered_sites/announcement', :class=>"btn" %>
|
||||
</div>
|
||||
</form>
|
|
@ -0,0 +1,87 @@
|
|||
<% tags = @sites_order_by_tags
|
||||
.collect{|v| v.keys[0]}
|
||||
.map{|tag| tag.class == String ? [tag.to_s,'無標籤'] : [tag.id.to_s,tag.name] }
|
||||
cats = @sites_order_by_cats
|
||||
.collect{|v| v.keys[0]}
|
||||
.map{|cat| cat.class == String ? [cat.to_s,'無類別'] : [cat.id.to_s,cat.title] }
|
||||
@sites_by_cats_and_tags = @sites_order_by_cats + @sites_order_by_tags
|
||||
%>
|
||||
<div id="member-filter" class="modal hide fade">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3><%= t('site_annc.recieve_sites') %></h3>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="tabbable tabs-left">
|
||||
<div class="nano">
|
||||
<div class="content">
|
||||
<ul class="nav nav-pills nav-stacked">
|
||||
<li class="active"><a href="#all_cats" data-toggle="tab"><%= t(:categories) %></a></li>
|
||||
<% cats.each do |cat| %>
|
||||
<li class=""><a href="#r_<%= cat[0] %>" data-toggle="tab"><%= cat[1] %></a></li>
|
||||
<% end %>
|
||||
<li class=""><a href="#all_tags" data-toggle="tab"><%= t(:tags) %></a></li>
|
||||
<% tags.each do |tag| %>
|
||||
<li class=""><a href="#r_<%= tag[0] %>" data-toggle="tab"><%= tag[1] %></a></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tab-content">
|
||||
<div class="tab-pane fade in active" id="all_cats">
|
||||
<form>
|
||||
<fieldset class="role_field">
|
||||
<% cats.each do |v| %>
|
||||
<label class="checkbox inline">
|
||||
<%= check_box_tag 'email_role_ids[]', v[0].to_s, false,id: nil %> <%= v[1] %>
|
||||
</label>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<div class="tab-pane fade in" id="all_tags">
|
||||
<form>
|
||||
<fieldset class="role_field">
|
||||
<% tags.each do |v| %>
|
||||
<label class="checkbox inline">
|
||||
<%= check_box_tag 'email_role_ids[]', v[0].to_s, false,id: nil %> <%= v[1] %>
|
||||
</label>
|
||||
<% end %>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<% @sites_by_cats_and_tags.each do |child| %>
|
||||
<% key = child.keys[0]
|
||||
key = key.id if key.class != String
|
||||
values = child.values[0]
|
||||
%>
|
||||
<div class="tab-pane fade" id="r_<%= key %>">
|
||||
<form>
|
||||
<fieldset class="clearfix">
|
||||
<div class="member-filter-result nano">
|
||||
<div class="content">
|
||||
<ul class="checkbox-card clearfix">
|
||||
<% values.each do |value| %>
|
||||
<li class="check-item">
|
||||
<label>
|
||||
<%= image_tag ("member-pic.png"), class: "user-pic" %>
|
||||
<span class="user-name"><%= value.title.nil? ? value.site_domain : value.title %></span>
|
||||
</label>
|
||||
<%= check_box_tag 'email_user_ids[]', value.id.to_s , false,id: nil %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
<% end %>
|
||||
<div class="form-actions condition">
|
||||
<button type="button" class="btn" data-dismiss="modal"><%= t(:cancel) %></button>
|
||||
<button type="button" class="btn btn-primary" data-dismiss="modal" onclick="updateUsers()"><%= t(:submit) %></button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -4,7 +4,27 @@ en:
|
|||
status: Status
|
||||
permission: Access
|
||||
resend_email: Resend email
|
||||
site_annc:
|
||||
watch_list_count: Watch count
|
||||
recieve_sites: Recieve Sites
|
||||
new: New announcement
|
||||
title: Title
|
||||
content: Content
|
||||
visible: Visible
|
||||
see_more_link: See more link
|
||||
registered_sites:
|
||||
announcement: All site announcement
|
||||
destroy_bundle_temp: Destroy bundle temp
|
||||
stop_bundle_update: Stop Bundle update
|
||||
update_select: Update selected
|
||||
get_detail: Detail
|
||||
update: Update
|
||||
last_time: Last Update Time
|
||||
status: Status
|
||||
last_message: Last Message
|
||||
bundle_update_status: bundle update status
|
||||
bundle_update: bundle update
|
||||
bundle_update_remote_show: Bundle update remote
|
||||
customization_log: Customization Log
|
||||
registered_sites: Registered Sites
|
||||
all: All
|
||||
|
|
|
@ -4,7 +4,27 @@ zh_tw:
|
|||
status: Status
|
||||
permission: Access
|
||||
resend_email: Resend email
|
||||
site_annc:
|
||||
watch_list_count: 查看人數
|
||||
recieve_sites: 接收網站
|
||||
new: 新增公告
|
||||
title: 標題
|
||||
content: 內容
|
||||
visible: 顯示
|
||||
see_more_link: 更多連結
|
||||
registered_sites:
|
||||
announcement: 全站公告
|
||||
destroy_bundle_temp: 刪除程序暫存
|
||||
stop_bundle_update: 中止套件更新
|
||||
update_select: 更新所選
|
||||
get_detail: 詳細資訊
|
||||
update: 更新
|
||||
last_time: 最後更新時間
|
||||
status: 狀態
|
||||
last_message: 最新訊息
|
||||
bundle_update_status: 套件更新狀態
|
||||
bundle_update: 外掛更新
|
||||
bundle_update_remote_show: 遠端網站外掛更新
|
||||
customization_log: Customization Log
|
||||
registered_sites: Registered Sites
|
||||
all: All
|
||||
|
|
|
@ -1,15 +1,39 @@
|
|||
Rails.application.routes.draw do
|
||||
post "/register/site" => "admin/register_api#register"
|
||||
post "/register/store_token" => "admin/register_api#send_store_token"
|
||||
get "/register/confirm_email" => "admin/register_api#confirm_email"
|
||||
get "/site/permissions" => "admin/register_api#check_permissions"
|
||||
get "/site/send_email" => "admin/register_api#send_email"
|
||||
|
||||
locales = Site.first.in_use_locales rescue I18n.available_locales
|
||||
|
||||
scope "(:locale)", locale: Regexp.new(locales.join("|")) do
|
||||
post "/xhr/site/re_register_url", to: 'admin/register_api#re_register_url'
|
||||
get 'git-auth' => 'registered_sites#git_auth'
|
||||
post 'git-auth' => 'registered_sites#git_auth'
|
||||
namespace :admin do
|
||||
get "/registered_site/change_access/:uid" => "registered_sites#change_access_status"
|
||||
resources :registered_sites do
|
||||
resources :registered_sites,:except => ['show'] do
|
||||
member do
|
||||
get "progress"
|
||||
end
|
||||
end
|
||||
resource :registered_sites,:only => [] do
|
||||
post 'get_watch_list' => 'registered_sites#get_watch_list'
|
||||
get 'get_select_box' => 'registered_sites#get_select_box'
|
||||
get 'announcement' => 'registered_sites#announcement'
|
||||
get ':site_annc_id/edit_annc' => 'registered_sites#edit_annc'
|
||||
get ':site_annc_id/delete_annc' => 'registered_sites#delete_annc'
|
||||
post ':site_annc_id/update_annc' => 'registered_sites#update_annc'
|
||||
post 'get_check_log' => 'registered_sites#get_check_log'
|
||||
post 'check_all_site' => 'registered_sites#check_all_site'
|
||||
post 'destroy_bundle_temp' => 'registered_sites#destroy_bundle_temp'
|
||||
get 'bundle_update_remote_show' => 'registered_sites#bundle_update_remote_show'
|
||||
post "bundle_update" => 'registered_sites#bundle_update'
|
||||
post 'stop_bundle_update' => 'registered_sites#stop_bundle_update'
|
||||
post 'get_message' => 'registered_sites#get_message'
|
||||
post 'get_detail' => 'registered_sites#get_detail'
|
||||
post 'check_site' => 'registered_sites#check_site'
|
||||
end
|
||||
resources :customization_logs do
|
||||
member do
|
||||
|
|
|
@ -9,7 +9,7 @@ module RegisteredSites
|
|||
authorizable
|
||||
taggable "RegisteredSite"
|
||||
categorizable
|
||||
|
||||
set_keyword_contstraints ['/git-auth','/register/','/site/permissions','/site/send_email']
|
||||
side_bar do
|
||||
head_label_i18n 'registered_sites.registered_sites', icon_class: "icons-earth"
|
||||
available_for "users"
|
||||
|
@ -35,6 +35,18 @@ module RegisteredSites
|
|||
:active_for_action=>{'admin/registered_sites'=>'categories'},
|
||||
:active_for_category => 'RegisteredSite',
|
||||
:available_for => 'managers'
|
||||
|
||||
context_link 'registered_sites.bundle_update_remote_show',
|
||||
:link_path=>"bundle_update_remote_show_admin_registered_sites_path",
|
||||
:priority=>4,
|
||||
:active_for_action=>{'admin/registered_sites'=>'bundle_update_remote_show'},
|
||||
:available_for => 'managers'
|
||||
|
||||
context_link 'registered_sites.announcement',
|
||||
:link_path=>"announcement_admin_registered_sites_path",
|
||||
:priority=>5,
|
||||
:active_for_action=>{'admin/registered_sites'=>'announcement'},
|
||||
:available_for => 'managers'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|