-
+
- <%= t(:categories) %> + <% cats.each do |cat| %> +
- <%= cat[1] %> + <% end %> +
- <%= t(:tags) %> + <% tags.each do |tag| %> +
- <%= tag[1] %> + <% end %> +
diff --git a/app/assets/images/registered_sites/ui-bg_flat_0_888888_40x100.png b/app/assets/images/registered_sites/ui-bg_flat_0_888888_40x100.png
new file mode 100644
index 0000000..7cd111a
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_flat_0_888888_40x100.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_flat_0_aaaaaa_40x100.png b/app/assets/images/registered_sites/ui-bg_flat_0_aaaaaa_40x100.png
new file mode 100644
index 0000000..5b5dab2
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_flat_0_aaaaaa_40x100.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_flat_75_ffffff_40x100.png b/app/assets/images/registered_sites/ui-bg_flat_75_ffffff_40x100.png
new file mode 100644
index 0000000..ac8b229
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_flat_75_ffffff_40x100.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_glass_25_e1f0f5_1x400.png b/app/assets/images/registered_sites/ui-bg_glass_25_e1f0f5_1x400.png
new file mode 100644
index 0000000..42f8788
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_glass_25_e1f0f5_1x400.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_glass_55_444444_1x400.png b/app/assets/images/registered_sites/ui-bg_glass_55_444444_1x400.png
new file mode 100644
index 0000000..b01b129
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_glass_55_444444_1x400.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_glass_65_ffffff_1x400.png b/app/assets/images/registered_sites/ui-bg_glass_65_ffffff_1x400.png
new file mode 100644
index 0000000..42ccba2
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_glass_65_ffffff_1x400.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_glass_75_dadada_1x400.png b/app/assets/images/registered_sites/ui-bg_glass_75_dadada_1x400.png
new file mode 100644
index 0000000..5a46b47
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_glass_75_dadada_1x400.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_highlight-soft_75_cccccc_1x100.png b/app/assets/images/registered_sites/ui-bg_highlight-soft_75_cccccc_1x100.png
new file mode 100644
index 0000000..7c9fa6c
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_highlight-soft_75_cccccc_1x100.png differ
diff --git a/app/assets/images/registered_sites/ui-bg_inset-soft_95_fef1ec_1x100.png b/app/assets/images/registered_sites/ui-bg_inset-soft_95_fef1ec_1x100.png
new file mode 100644
index 0000000..0e05810
Binary files /dev/null and b/app/assets/images/registered_sites/ui-bg_inset-soft_95_fef1ec_1x100.png differ
diff --git a/app/assets/images/registered_sites/ui-icons_222222_256x240.png b/app/assets/images/registered_sites/ui-icons_222222_256x240.png
new file mode 100644
index 0000000..b273ff1
Binary files /dev/null and b/app/assets/images/registered_sites/ui-icons_222222_256x240.png differ
diff --git a/app/assets/images/registered_sites/ui-icons_309bbf_256x240.png b/app/assets/images/registered_sites/ui-icons_309bbf_256x240.png
new file mode 100644
index 0000000..d6f62ed
Binary files /dev/null and b/app/assets/images/registered_sites/ui-icons_309bbf_256x240.png differ
diff --git a/app/assets/images/registered_sites/ui-icons_454545_256x240.png b/app/assets/images/registered_sites/ui-icons_454545_256x240.png
new file mode 100644
index 0000000..59bd45b
Binary files /dev/null and b/app/assets/images/registered_sites/ui-icons_454545_256x240.png differ
diff --git a/app/assets/images/registered_sites/ui-icons_bf3030_256x240.png b/app/assets/images/registered_sites/ui-icons_bf3030_256x240.png
new file mode 100644
index 0000000..c6cfba0
Binary files /dev/null and b/app/assets/images/registered_sites/ui-icons_bf3030_256x240.png differ
diff --git a/app/assets/images/registered_sites/ui-icons_ffffff_256x240.png b/app/assets/images/registered_sites/ui-icons_ffffff_256x240.png
new file mode 100644
index 0000000..42f8f99
Binary files /dev/null and b/app/assets/images/registered_sites/ui-icons_ffffff_256x240.png differ
diff --git a/app/assets/javascripts/registered_site_progress.js b/app/assets/javascripts/registered_site_progress.js
index 6d772dd..c59a437 100644
--- a/app/assets/javascripts/registered_site_progress.js
+++ b/app/assets/javascripts/registered_site_progress.js
@@ -1 +1,19 @@
-// site progress javascript is here
\ No newline at end of file
+// 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);
+ })
+});
\ No newline at end of file
diff --git a/app/controllers/admin/register_api_controller.rb b/app/controllers/admin/register_api_controller.rb
index 818c2ec..4ae52df 100644
--- a/app/controllers/admin/register_api_controller.rb
+++ b/app/controllers/admin/register_api_controller.rb
@@ -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
diff --git a/app/controllers/admin/registered_sites_controller.rb b/app/controllers/admin/registered_sites_controller.rb
index 73a6b9b..dabf8b0 100644
--- a/app/controllers/admin/registered_sites_controller.rb
+++ b/app/controllers/admin/registered_sites_controller.rb
@@ -7,15 +7,458 @@ class Admin::RegisteredSitesController < OrbitAdminController
.with_tags(filters("tag")).desc(:created_at)
@table_fields = table_fields
@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(10)
-
- if request.xhr?
- render :partial => "index"
- end
+ @categories = @module_app.categories.enabled
+ @filter_fields = filter_fields_without_status(@categories, @tags)
+ @registeredsites = search_data(@registeredsites,[:title,:site_domain]).page(params[:page]).per(10)
+
+ if request.xhr?
+ 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'
+ elsif urls == [nil,nil]
+ tp1.status = 'domain not found'
+ tp1.href = 'http://'+site.site_domain
+ 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) 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'
+ 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) 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
+ puts '1'
+ if !not_login_flag
+ not_accept_flag = true
+ puts '2'
+ 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 ''
+ puts ['3',res.inspect]
+ 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 += "
restart success"
+ #else
+ # log.last_message += "
restart failed"
+ #end
+ #log.message[-1] = log.last_message
+ #log.save!
+ end
+ rescue => e
+ not_accept_flag = true
+ puts e
+ end
+ puts 'out'
+ if not_accept_flag || not_login_flag
+ log.status = 'failed'
+ log.last_message = "can't login to admin"
+ elsif !timeout_flag
+ if sel_flag || site.is_alive?
+ puts 'finish2'
+ log.status = 'finish'
+ else
+ log.status = 'failed'
+ end
+ else
+ puts 'timeout_flag'
+ system('sleep 10')
+ puts 'sleep finish'
+ if site.is_alive?
+ puts 'finish'
+ log.status = 'finish'
+ else
+ puts 'failed'
+ 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('
') 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)
+ 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 +518,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
diff --git a/app/controllers/registered_sites_controller.rb b/app/controllers/registered_sites_controller.rb
index b75553a..0a83879 100644
--- a/app/controllers/registered_sites_controller.rb
+++ b/app/controllers/registered_sites_controller.rb
@@ -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
\ No newline at end of file
diff --git a/app/models/bundle_update_log.rb b/app/models/bundle_update_log.rb
new file mode 100644
index 0000000..4c33828
--- /dev/null
+++ b/app/models/bundle_update_log.rb
@@ -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
\ No newline at end of file
diff --git a/app/models/bundle_update_temp.rb b/app/models/bundle_update_temp.rb
new file mode 100644
index 0000000..c7aea85
--- /dev/null
+++ b/app/models/bundle_update_temp.rb
@@ -0,0 +1,8 @@
+class BundleUpdateTemp
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :all_ids
+ field :now_id
+
+end
\ No newline at end of file
diff --git a/app/models/check_site_temp.rb b/app/models/check_site_temp.rb
new file mode 100644
index 0000000..2fa204a
--- /dev/null
+++ b/app/models/check_site_temp.rb
@@ -0,0 +1,7 @@
+class CheckSiteTemp
+ include Mongoid::Document
+ include Mongoid::Timestamps
+
+ field :all_ids
+ field :status
+end
\ No newline at end of file
diff --git a/app/models/registered_site.rb b/app/models/registered_site.rb
index c90f3d4..fef862c 100644
--- a/app/models/registered_site.rb
+++ b/app/models/registered_site.rb
@@ -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) 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
\ No newline at end of file
diff --git a/app/models/site_annc.rb b/app/models/site_annc.rb
new file mode 100644
index 0000000..cfc5b70
--- /dev/null
+++ b/app/models/site_annc.rb
@@ -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
\ No newline at end of file
diff --git a/app/models/site_status.rb b/app/models/site_status.rb
new file mode 100644
index 0000000..9d3e60f
--- /dev/null
+++ b/app/models/site_status.rb
@@ -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
\ No newline at end of file
diff --git a/app/models/update_flags.rb b/app/models/update_flags.rb
new file mode 100644
index 0000000..dc8698e
--- /dev/null
+++ b/app/models/update_flags.rb
@@ -0,0 +1,6 @@
+class UpdateFlags
+ include Mongoid::Document
+
+ field :bundle_update_flag, type: Boolean, default: true
+
+end
\ No newline at end of file
diff --git a/app/views/admin/registered_sites/_bundle_update_remote_show.html.erb b/app/views/admin/registered_sites/_bundle_update_remote_show.html.erb
new file mode 100644
index 0000000..eb24188
--- /dev/null
+++ b/app/views/admin/registered_sites/_bundle_update_remote_show.html.erb
@@ -0,0 +1,79 @@
+
+
+ + | + <% @table_fields.zip(['20%','10%','15%','15%']).each do |f| %> +<%= t(f[0]) %> | + <% end %> +||||
---|---|---|---|---|---|
+ <% if site.is_hidden != true %> + + <% end %> + | +
+ <%= site.title.nil? ? site.site_domain : site.title %>
+
+
+
+ |
+ + + + + | +
+ <% if !site.site_confirmed %>
+ <%= t("registered_sites.site_inactive") %> + <%= t("registered_sites.email_not_confirmed") %> + <% elsif !site.access_granted %> + <%= t("registered_sites.site_inactive") %> + <%= t("registered_sites.site_permission_revoked") %> + <% else %> + <%= t("registered_sites.site_active") %> + <% end %> + <% ['last_time','status'].each do |log_t| %> + + <%= site.bundle_update_logs.first.send(log_t) rescue '' %> + + + <% end %> + |
+ <%= site.category.nil? ? "Category not assigned." : "#{site.category.title}".html_safe %> | ++ | + +
+ <%= t('site_annc.title') %>(中文/英文) + | ++ <%= t('site_annc.watch_list_count') %> + | ++ <%= t('site_annc.see_more_link') %> + | +
---|---|---|
+ <%= site_annc[:title][:zh_tw].to_s.html_safe %>
+ /
+ <%= site_annc[:title][:en].to_s.html_safe %>
+
+
+ <%= t(:edit) %>
+ delete
+
+ |
+ + + <%= site_annc.watch_list.count %> + + | ++ <%= link_to site_annc.see_more_link.to_s,site_annc.see_more_link.to_s %> + | +