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..ccc6d2e 100644 --- a/app/controllers/admin/registered_sites_controller.rb +++ b/app/controllers/admin/registered_sites_controller.rb @@ -7,15 +7,454 @@ 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' + 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 += "
restart success" + #else + # log.last_message += "
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('
') 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 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..cfb05d4 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,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 \ 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| %> + + <% end %> + + + + <% @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 + %> + + + + + + + + + <% end %> + +
+ + <%= t(f[0]) %>
+ <% 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 %> + <%=site.bundle_update_logs.first.last_message.html_safe rescue '' %> +
+ + <%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@registeredsites), class: "pagination pagination-centered" + end +%> \ No newline at end of file diff --git a/app/views/admin/registered_sites/_form.html.erb b/app/views/admin/registered_sites/_form.html.erb index d0b6219..cec2819 100644 --- a/app/views/admin/registered_sites/_form.html.erb +++ b/app/views/admin/registered_sites/_form.html.erb @@ -45,13 +45,18 @@ -
+
<%= f.text_field :admin_email %>
- +
+ +
+ <%= f.check_box :is_hidden,{},'true','false' %> +
+
diff --git a/app/views/admin/registered_sites/_site_selection_box.html.erb b/app/views/admin/registered_sites/_site_selection_box.html.erb new file mode 100644 index 0000000..96c14c8 --- /dev/null +++ b/app/views/admin/registered_sites/_site_selection_box.html.erb @@ -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 %> + +
+ <% recieve_sites.each do |recieve_site| %> + + x + <%= recieve_site.title.nil? ? recieve_site.site_domain : recieve_site.title %> + <%= hidden_field_tag field, recieve_site.id %> + + <% end %> +
+delete all +<%= t(:add) %> + \ No newline at end of file diff --git a/app/views/admin/registered_sites/announcement.erb b/app/views/admin/registered_sites/announcement.erb new file mode 100644 index 0000000..0d0dd3b --- /dev/null +++ b/app/views/admin/registered_sites/announcement.erb @@ -0,0 +1,100 @@ + + + +
+
+ +
+ + + + + + + + + + + <% @site_anncs.each do |site_annc| %> + + + + + + <% end %> + +
+ <%= 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 %> + + + + <%= site_annc.watch_list.count %> + + + <%= link_to site_annc.see_more_link.to_s,site_annc.see_more_link.to_s %> +
+ <%= + content_tag :div, class: "bottomnav clearfix" do + content_tag :div, paginate(@site_anncs), class: "pagination pagination-centered" + end + %> +
\ No newline at end of file diff --git a/app/views/admin/registered_sites/bundle_update_remote_show.erb b/app/views/admin/registered_sites/bundle_update_remote_show.erb new file mode 100644 index 0000000..bc28632 --- /dev/null +++ b/app/views/admin/registered_sites/bundle_update_remote_show.erb @@ -0,0 +1,348 @@ + + +<% 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 %> +
+ 失敗(僅確認可登入): + <%= 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| "#{v.show_name} :#{v.bundle_update_logs.first.last_message}"}.join('
').html_safe %> +<% end %> +<%= render_filter @filter_fields, "index_table" %> + + + + select all behind + + + + + +show_all + +ok only + +fail only +
+
+
+ + +
+ <%= render 'bundle_update_remote_show'%> +
\ No newline at end of file diff --git a/app/views/admin/registered_sites/edit_annc.erb b/app/views/admin/registered_sites/edit_annc.erb new file mode 100644 index 0000000..e77dc1d --- /dev/null +++ b/app/views/admin/registered_sites/edit_annc.erb @@ -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 %> + +
+ <%= hidden_field_tag :authenticity_token, form_authenticity_token %> + +
+
+ +
+ <%= render partial: 'admin/registered_sites/site_selection_box', locals: {field: 'recieve_sites[]', recieve_sites:(@site_annc.recieve_sites || [])} %> +
+
+
+ + <%= check_box_tag 'visible', 'true', @site_annc.visible %> +
+
+ + <%= check_box_tag 'send_all', 'true', @site_annc.send_all %> +
+ + + + +
+ <% I18n.available_locales.each_with_index do |locale, i| %> +
"> + +
+ +
+ <%= text_area_tag "title[#{locale}]",(@site_annc.title[locale] rescue nil), class: "ckeditor_reduce input-block-level", placeholder: t(:title) %> +
+
+
+ +
+ <%= text_area_tag "content[#{locale}]",(@site_annc.content[locale] rescue nil), class: "ckeditor input-block-level", placeholder: t('site_annc.content') %> +
+
+
+ <% end %> + +
+ <%= url_field_tag "see_more_link",(@site_annc.see_more_link rescue nil),class: "input-block-level", placeholder: t('site_annc.see_more_link') %> +
+
+
+ +
+ <%= submit_tag t('submit'), class: 'btn btn-primary' %> + + <%= link_to t('cancel'), '/admin/registered_sites/announcement', :class=>"btn" %> +
+
\ No newline at end of file diff --git a/app/views/admin/registered_sites/get_select_box.html.erb b/app/views/admin/registered_sites/get_select_box.html.erb new file mode 100644 index 0000000..acec738 --- /dev/null +++ b/app/views/admin/registered_sites/get_select_box.html.erb @@ -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 +%> + \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index a486c93..65b2f5a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -4,13 +4,33 @@ 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: - customization_log: Customization Log - registered_sites: Registered Sites - all: All - email_not_confirmed: Email not confirmed. - site_permission_revoked: Site permission revoked. - site_active: Active - site_inactive: Inactive - progress: Progress + 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 + email_not_confirmed: Email not confirmed. + site_permission_revoked: Site permission revoked. + site_active: Active + site_inactive: Inactive + progress: Progress diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index 358c1cc..46e5903 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 8358216..eea601b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' - namespace :admin 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 diff --git a/lib/registered_sites/engine.rb b/lib/registered_sites/engine.rb index 13cbb06..b4f85b9 100644 --- a/lib/registered_sites/engine.rb +++ b/lib/registered_sites/engine.rb @@ -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