Compare commits

...

3 Commits

Author SHA1 Message Date
Manson Wang 5d9f4f6782 ntu_ga sso server 2014-04-16 15:42:07 +08:00
Manson Wang b0ae1da581 Added missing Gem 2014-04-16 15:30:30 +08:00
Manson Wang b020b8e13f ntu_ga 2014-04-16 15:30:30 +08:00
21 changed files with 396 additions and 16 deletions

View File

@ -41,6 +41,7 @@ gem 'fb_graph'
gem 'rack-gridfs' gem 'rack-gridfs'
gem 'radius' gem 'radius'
gem 'rake' gem 'rake'
gem 'roo'
# gem 'remotipart' # gem 'remotipart'
gem 'resque', :require => 'resque/server' # background jobs gem 'resque', :require => 'resque/server' # background jobs
gem 'resque-scheduler' # job scheduling gem 'resque-scheduler' # job scheduling

View File

@ -0,0 +1,10 @@
$(document).ajaxStop(function() {
$('.nav').find('.dropdown').on({
mouseleave: function() {
$(this).removeClass("open");
},
mouseenter: function() {
$(this).addClass("open")
}
});
});

View File

@ -85,7 +85,6 @@
width: auto; width: auto;
} }
/* Check Box Card */ /* Check Box Card */
.checkbox-card { .checkbox-card {
margin: 0; margin: 0;

View File

@ -0,0 +1,34 @@
class SamlLoginsController < ApplicationController
require "net/http"
require "uri"
require 'rexml/document'
include REXML
def index
if params[:wa] == "wsignoutcleanup1.0" #logout
redirect_to :root
else #login
@wresult = params[:wresult]
@wctx = params[:wctx]
@main_url = LIST[:sites][@wctx]['url']
@main_public_key = LIST[:sites][@wctx]['key']
@doc = REXML::Document.new @wresult
public_key = OpenSSL::PKey::RSA.new(@main_public_key)
encrypted_data = public_key.public_encrypt(@doc.elements["//saml:AttributeValue"].text)
redirect_to "http://#{@main_url}/user_login?" + { :wresult => encrypted_data }.to_param
end
end
end

View File

@ -0,0 +1,40 @@
# encoding: utf-8
class SessionsController < Devise::SessionsController
prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
def create
@site = Site.first
private_key = OpenSSL::PKey::RSA.new(@site.private_key)
wresult = private_key.private_decrypt(request.params['wresult'])
@ids = wresult.split("@")
login_uid = @ids[0]
resource = User.first(conditions:{user_id: login_uid})
if !resource.blank?
resource_name = resource.class.to_s.downcase
sign_in(resource_name, resource)
session[:user_id_type] = "myntu"
redirect_to after_sign_in_path_for(resource)
else
flash[:error] = "很抱歉,您無此權限或帳號登入本站,請洽本站管理員<br />Sorry, you don't have the account or authority to login. Please contact the website administrator."
redirect_to :root
end
end
def destroy
@user_id_type = session[:user_id_type]
sign_out
if @user_id_type == "myntu"
redirect_to "https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignout1.0&wreply=https://galogin.ntu.edu.tw"
else
redirect_to root_path
end
end
end

View File

@ -204,6 +204,9 @@ module ApplicationHelper
def page_javascripts(page, edit=nil) def page_javascripts(page, edit=nil)
javascripts = '' javascripts = ''
unless edit
javascripts << "<script type='text/javascript' src='/assets/orbit-bar-search.js'></script>\n"
end
# javascripts << "<script type='text/javascript' src='/assets/lib/jquery.preload-min.js'></script>\n" # javascripts << "<script type='text/javascript' src='/assets/lib/jquery.preload-min.js'></script>\n"
# javascripts << "<script type='text/javascript' src='/assets/jquery.cycle.all.latest.js'></script>\n" # javascripts << "<script type='text/javascript' src='/assets/jquery.cycle.all.latest.js'></script>\n"
javascripts << "<script type='text/javascript' src='/assets/lib/social-share-button.js'></script>\n" javascripts << "<script type='text/javascript' src='/assets/lib/social-share-button.js'></script>\n"
@ -303,7 +306,7 @@ module ApplicationHelper
# NTU link # NTU link
def get_link(site_number) def get_link(site_number)
"http://#{request.host}:2#{site_number}00" "http://#{site_number}.#{request.domain(3)}"
end end
def sortable(column, title = nil, options = {}) def sortable(column, title = nil, options = {})

View File

@ -0,0 +1,7 @@
class GetAnnouncementFromRss
@queue = :high
def self.perform()
%x(ruby "#{Rails.root}/lib/rss_ntu_job.rb")
end
end

View File

@ -0,0 +1,14 @@
<% unless users.blank? %>
<div class="promoter-block">
<p class="promoter-title"><%= t(:promoter) %></p>
<ul>
<% users.each do |user| %>
<li class="promoter">
<p>
<%= link_to user.name, "mailto:#{user.email}", class: "promoter-name" %> / <span class="promoter-phone"><%= user.office_tel %></span>
</p>
</li>
<% end %>
</ul>
</div>
<% end %>

View File

@ -1,4 +1,5 @@
<% content_for :page_specific_javascript do -%> <% content_for :page_specific_javascript do -%>
<%= javascript_include_tag "member-selection" %>
<%= javascript_include_tag "lib/jquery.nanoscroller" %> <%= javascript_include_tag "lib/jquery.nanoscroller" %>
<%= javascript_include_tag "lib/checkbox.card" %> <%= javascript_include_tag "lib/checkbox.card" %>
<% end -%> <% end -%>

View File

@ -12,10 +12,11 @@
<input name="utf8" type="hidden" value="" /> <input name="utf8" type="hidden" value="" />
<input name="authenticity_token" type="hidden" value="" /> <input name="authenticity_token" type="hidden" value="" />
</div> </div>
<!-- <div class="other-sign-in"> <div class="other-sign-in">
<a class="btn btn-primary" type="submit">Other Sign In</a> <% @request_hosts = request.host_with_port.split(".") %>
<a class="btn btn-primary" type="submit" href="https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignin1.0&wtrealm=https://galogin.ntu.edu.tw/saml_login&wctx=<%= @request_hosts[0] %>">使用計中帳號登入</a>
<p>or</p> <p>or</p>
</div> --> </div>
<div class="form-block"> <div class="form-block">
<div class="form-list clearfix"> <div class="form-list clearfix">
<form class="content" accept-charset="UTF-8" action="/users/sign_in" method="post"> <form class="content" accept-charset="UTF-8" action="/users/sign_in" method="post">

View File

@ -7,6 +7,16 @@
</form> </form>
</li> </li>
<!-- ntu sites -->
<li id="orbit-tag" class="dropdown">
<a class="dropdown-toggle orbit-bar-language" data-icons="&#xe02d;" href="#" data-toggle="dropdown"></a>
<ul class="dropdown-menu language-menu">
<% t('ntu.site_names').each do |site| %>
<li><%= link_to site[1], get_link(site[0]) %></li>
<% end %>
</ul>
</li>
<!-- Language --> <!-- Language -->
<li id="orbit-language" class="dropdown"> <li id="orbit-language" class="dropdown">
<a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown" title="<%= t('site.language')%>"><%= t(:_locale, :locale => I18n.locale) %></a> <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown" title="<%= t('site.language')%>"><%= t(:_locale, :locale => I18n.locale) %></a>
@ -30,7 +40,7 @@
<% if @site.desktop_closed %> <% if @site.desktop_closed %>
<li><%= link_to content_tag(:i, nil, class: 'icons-screen') + ' ' + t(:desktop), desktop_path, tabindex: '-1' %></li> <li><%= link_to content_tag(:i, nil, class: 'icons-screen') + ' ' + t(:desktop), desktop_path, tabindex: '-1' %></li>
<% end %> <% end %>
<li><%= link_to content_tag(:i, nil, class: 'icons-logout') + ' ' + t(:logout), destroy_user_session_path, tabindex: '-1' %></li> <li><%= link_to content_tag(:i, nil, class: 'icons-logout') + ' ' + t(:logout), user_logout_path, tabindex: '-1' %></li>
<li class="divider"></li> <li class="divider"></li>
<li><a tabindex="-1" href="#"><i class="icons-lifebuoy"></i> <%= t(:help) %></a></li> <li><a tabindex="-1" href="#"><i class="icons-lifebuoy"></i> <%= t(:help) %></a></li>
</ul> </ul>
@ -50,6 +60,12 @@
</div> </div>
<div class="modal-body"> <div class="modal-body">
<%= form_for :user, url: user_session_path, html: {class: 'container'} do |f| %> <%= form_for :user, url: user_session_path, html: {class: 'container'} do |f| %>
<div class="other-sign-in">
<% @request_hosts = request.host_with_port.split(".") %>
<a class="btn btn-primary" type="submit" href="https://adfs.ntu.edu.tw/adfs/ls/?wa=wsignin1.0&wtrealm=https://galogin.ntu.edu.tw/saml_login&wctx=<%= @request_hosts[0] %>">使用計中帳號登入</a>
<p>or</p>
</div>
<div class="input-prepend"> <div class="input-prepend">
<span class="add-on"> <span class="add-on">
<i class="icon-user"></i> <i class="icon-user"></i>

View File

@ -1,10 +1,10 @@
#built-in-modules #built-in-modules
gem 'archive', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-archive.git' gem 'archive', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-archive.git', :branch => 'ntu_ga'
gem 'announcement', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-announcement.git' gem 'announcement', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-announcement.git', :branch => 'ntu_ga'
gem 'gallery', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-gallery.git' gem 'gallery', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-gallery.git'
gem 'member', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-member.git' gem 'member', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-member.git'
gem 'member_staff', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-memberstaff.git' gem 'member_staff', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-memberstaff.git', :branch => 'ntu_ga'
gem 'page_content', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-pagecontent.git' gem 'page_content', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-pagecontent.git', :branch => 'ntu_ga'
gem 'personal_book', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalbook.git' gem 'personal_book', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalbook.git'
gem 'personal_conference', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalconference.git' gem 'personal_conference', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalconference.git'
gem 'personal_diploma', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personaldiploma.git' gem 'personal_diploma', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personaldiploma.git'
@ -16,3 +16,6 @@ gem 'personal_patent', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orb
gem 'personal_project', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalproject.git' gem 'personal_project', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalproject.git'
gem 'personal_research', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalresearch.git' gem 'personal_research', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-personalresearch.git'
gem 'web_resource', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-webresource.git' gem 'web_resource', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-webresource.git'
gem 'ask', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-ask.git', :branch => 'ntu_ga'
gem 'survey', '0.0.1', :git => 'http://gitlab.tp.rulingcom.com/root/orbit-survey.git', :branch => 'ntu_ga'

View File

@ -80,3 +80,48 @@ default_widget_style:
- style3 - style3
- style4 - style4
- style5 - style5
sites:
www:
url: www.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3fDAM40XvEiM5oG7YbA\nKnhc5Dyv/ZhVDzyrg95QB0ylBPtSs6g5xgkSSQMnIpAUCzdVIMrUd/A6DuH6f+T5\nccshgh3aDj3wISfgYZc9e7WY1csOItq9lOr6YG4HEABSyjVCcX/RrB8kCuuIGcvR\nRnvu/4fFb93vsVYHwGuivTYRJ+8VM8fOtIFCvbCxZsFj6r5cMl4qI4g4vaIn3xf2\ndXUCICebvdIBfMAdW29yaCScEap1oawEfdXtKCD5vYvAaRZ85jLY/FV5dYhbe1dz\n9G7+B1HI7VBm5bKV0MI1ZH2MTRczaqjLGf6ZF0FbMmcMYLx8iEGL1z0/hgOTcNT6\nrQIDAQAB\n-----END PUBLIC KEY-----\n"
ga:
url: www.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAx3fDAM40XvEiM5oG7YbA\nKnhc5Dyv/ZhVDzyrg95QB0ylBPtSs6g5xgkSSQMnIpAUCzdVIMrUd/A6DuH6f+T5\nccshgh3aDj3wISfgYZc9e7WY1csOItq9lOr6YG4HEABSyjVCcX/RrB8kCuuIGcvR\nRnvu/4fFb93vsVYHwGuivTYRJ+8VM8fOtIFCvbCxZsFj6r5cMl4qI4g4vaIn3xf2\ndXUCICebvdIBfMAdW29yaCScEap1oawEfdXtKCD5vYvAaRZ85jLY/FV5dYhbe1dz\n9G7+B1HI7VBm5bKV0MI1ZH2MTRczaqjLGf6ZF0FbMmcMYLx8iEGL1z0/hgOTcNT6\nrQIDAQAB\n-----END PUBLIC KEY-----\n"
doc:
url: doc.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4aE7R0/49UBf5v4rbNiA\nnaXjPZ9rio9fjkaAZeow62yaZtoGurqf44BVj/cjQVUmLnMU4WDcZMI0osLa15+H\ndXSGCP8Upmvi+eA2UqhhBZts1IQ33rPMAjePAbpSGbNRxous0VpH7cc9BxMffQwh\nsygcbghUCEE3dVWdTFGokvgxkBzaKKTNbiqhmbuc8QIuzOvFFGkZHgqlxFHcaNYZ\n7KZJxqvuKSXsJcxIsQKzDiAPI11J3zgRdIf/CFVQv5g15gl1ieQgFdGc3jplsBcd\nrdLApPZ39+BWr9a/Gj9lgP6Ll5G/cM4Uq18a7TCWJIC9PNGw8bBDJTjnUEqmOu3R\nZQIDAQAB\n-----END PUBLIC KEY-----\n"
cashier:
url: cashier.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA9wliL8gFsRn0DVZusd2h\nSoj6aQWkKq1UU6fj3vzcrb1adMy8RnKogTW6z1W9wxrcrI/GfyRz9Wop0+9+XNYx\nDH+QQ+/1po/O/MkPBGZ6WxXpH2BSCncdJdYZ9qLvlJHHRhFtczcSQki693MCDUCy\nMrMDvmL4YOowHExD7A5qrCIaYnbNcUCYMKluSLxR52AUeAuYjCwZbkgEwIQRdZ+M\n3JMgTD/9GFsvZ4c5x6n1cUnKCJNyyUIvI8jThtOnySCU8ZN17nWfKb1Cxavt17Vp\nGSdyIIL2SO9+rjOFW3PrAyX5P3xEgPYoDxA1QsYLYbj189qA0sT17xf9H7KcNzyP\n7wIDAQAB\n-----END PUBLIC KEY-----\n"
general:
url: general.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvyFUUFyaEJgsR+bYhTXx\nOA60kw82ohyHCDzkoHDT/k2xS520RZR0AzxT449qD3XfRr0+7F0c6rMx/2pBG7hS\nlHjgrTX7eQ70wV8H4OApriDIp1UDemm4+fKxcPZ6vhWqzp+3ijPdhJXe7OC9D89I\n9QKdlHPBxKFnUrBJiqn3cHGLpRrYTsKpI/Nl7VW4UJJh0k7R7P1Jqry0e+HalOLB\nBu5kl5z6iYBPy1gJ4psDHWuoNboxIgIsVR1SSLM7Mooebwx2qjm3W4VQuc7eQk0g\nh7KH4B8CrK4bC+K6lAS3ZzmTlA6M1WZPtIKv3XqEYCkyomMnkdTNZQYKbCKKlLBo\ntQIDAQAB\n-----END PUBLIC KEY-----\n"
social:
url: social.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqB8htGdGzDPs3GA76REG\nyjM0eEYdXV6ugi4hPZEViCOBg3POC5RZslA5oTCYYWfTVui8jHC2CPD3AYQLG67Z\n79g2miLHEEyDzG7dp//dc85qp0FYR2JII1y26fJutMVCgn0hth6OpfjPB2QhkgZf\nat+Ico5ppDYIx+4jX8xQr4qqRlUIAmECMAE5ATiAUqfv117GJG/fR3AsKZPYm2U1\nFhSpKT2mvC0AiqstZzxYEm4srl1ZjpJPJ7uU+ewvi/EhRyLWFGPmygP6fvg4IaKS\nG00dx7FGedyLVcSaxJCoCX5Z98hIYEStanCSzuR3FQEL0JaB8ZKKWY8dsB+U1v46\nQwIDAQAB\n-----END PUBLIC KEY-----\n"
property:
url: property.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1bmnJSRmxcehehuKBwSQ\nXiuYhAxzUOmptIk0sgciB1hK8++anXMaHXf3QA6UiXWjNyU+g2ZL1nVfVl0Qd3Ps\nxM2+hSeZRus2sw0g7CQea7NkAqLGQrpicnZ8Fgcb+0qwgClk0RVBXwJzfTDu6V+5\nL9lLEKWnSdHmoGkxkZTPMAtJpXYx9SMLtljPYGkMWKY2C1cBqPdMOl/rKTUZ9dYp\n2eJ13NTXDJJgDJOhDFHevzK/I6kwxdJbetNo4IO1dhQdbPionR5SNkkCNZvfy3k3\n68+xopPKH3xECCIuxorcePx0hyoeXS8vdmJ09VKHVUz08LBYGq2S/36V5LIc1P/6\nSQIDAQAB\n-----END PUBLIC KEY-----\n"
procurement:
url: procurement.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAze/Yr3vrpRBpeu7ohyEP\nboPvZ476dtANbvW+rMuDyKeGD5FfoZYwzF+AbMIK6KfleWizObnMM8ABC0LdBuag\nQ0Brk4FMxyKz0aXlSgG3OZiZXJaaWm2/+gqghgpBLpAPMRFnEmK2y11b/EgCxurV\nl+RZ/MgrIviRGipnU7GXfG4O7Ai21oD4lzKt3WbvuWgBdgtEsYpZMIyddWrhkUki\noM39Vm72mCyKPkysCVYCnYaMwDXVx/SKuTRHiVQZ4GNIv74rwp7BOCkfDZ8HrNLH\nr3ObCB8X0Bh9GqUUj7gYu3cFmx8lXer7qkGtGUq2wNUM0CBc01EODVO9e9RQnulA\n3wIDAQAB\n-----END PUBLIC KEY-----\n"
fss:
url: fss.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzsvi4FfIQokfP2QmiRTs\nzuxjPg7oPK7pLHNQC/AyY35H0vmkXGTc74pVvLbfSuaprLO10WVzE4bGGQmhmls1\nDqeY7EyHg1vs7GHQm1932n+Va+qDToSx7S+Zs1ZOglYAdEzBI3dyhefIcDtNUfty\n0i64RGiEzDH4yV5lecilXo5Q4/7W/HNdtw8Oe//LopOZ2Mj+Eq7Tk70WkGFDV73Z\n/jIBLBn51g2P9nrsid63OLe1X8u0l9+xSGff0fR1VlqbElBRACCrAmPvs9ceOW7H\n+yLw71elR4nMDm+/dx/zimeYUj0WaY2A3/O8xucPhSP22YCRiO1jEsAEvMXkCU9p\n8wIDAQAB\n-----END PUBLIC KEY-----\n"
medicine:
url: medicine.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwx7zQLnde6Azy/03bIxg\nkp5rM0DsKKkBbX8C5vhUADxaC2zVmVJuF0NnTGCWutNSSYsKWRKzFwEoZdzJ+8XS\nr8f9kRdEB0yu3Akv+EhZyHA7yVGyFvNAhPGVuekSmpDlpFFKanAqlhBzrhByku5A\nTqp2fXi3zHMoP6WX8QXb6SpG/y4CBpjXCI1qLCAJRw0Fkt7yMXkJnjO2q7zCKAnU\nnv6DVz5yDuBiZPfYlW09KHVWxSehgk5fvLu9Jb/s1XklPwEw1m5BPhIA1YG0QelR\nXk9Pdvwb7aM59LZx1xQZYcku0KGSqLo9rCDTD8YT47226v921yeM36Az8t8e4egU\nzwIDAQAB\n-----END PUBLIC KEY-----\n"
police:
url: police.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzKawlFWAMzA/uV/kcewd\nmtj8PcqxosmnSh7ZzJ0DumG2ieeP9oDBicqbqIEaeJVvrRzYJD2a+u8x5KKMKB8J\nHbMUpCBFlIpkDMjU/oZVMcYT9pcH51QWNvCgHG7prVykSGFz1JRvjSP6cwuZKBFd\nFFneOViETqoMIO1DbRLXsGfPvMOJY9C1xDwv1dLv0Wbj7M9N6eNz06a50bu3I4gl\nMumxWnZUabXL3G62S/Si4NM7J2jOUnkEOxJWOhcAX/iiqS9T8AHu84um2+mLQpfB\nJJFFIWCIAtU78VnIN5JSWwjFU5TsiSyCFYpGXKxUFD25cFmt3SfG0gwmrFis5Pdn\nhwIDAQAB\n-----END PUBLIC KEY-----\n"
construction:
url: construction.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvxJcKnPUDaNNyhdGpedL\n+h2OI9RDDZUTkHcvX1UvBNvlX2+dvok6sHQh2AhZoNyCUFZTbp2CRSNfIM5jXigD\nfHA3KzpN7cmGG7W7nIdBBkZU/ly4HFvkD7mGoEymB0JYgZkz59CXBx+3Zg6KLSYY\nZDoOw6wikrl643So2zFZvwHJpDkRkmX5oWWYqXOZxaZnkgbhvA3KdcH9+C1aEBYY\npY2K2MJt86k0ahW/CJfVRDb9CWSxAGir1RAPu9bRV9y9WWKKGWekH0/IqhhJPT8q\nl3v6PB1Oc6ltbOyYkS2xHbmvRxjORzGen0Xcbjzo4N8HBEoPe0Uc5iP0Y50GDjEL\nEQIDAQAB\n-----END PUBLIC KEY-----\n"
sec:
url: sec.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApsVKJ8Cvr/A0dmHR+vDS\nAYjVzGqMNJ/4pO7GwMzUZMNSkpq3b9CIjrIGg/QKj7woTHnKM39vczu5gxPXJGYN\nIo+PnWsibMDjcz2Vm8s11XXIPho/Ce+hQkWpWGzxpaH7Z/qLKSwiwHdHhlgN3fWw\njR8jYhreQYfohkRGR70h8A9TTU4YkFY/+8yIdwGns61+5tK981kMbVkm+pcgL0cP\nMN08I7MM+c87COY6IO27jVb/ALPAYpo+QUdAfEp5hlI7BQW95nB7LHOnxAm7lLTD\nhbdETUssieQUicwgDpGa2aD769nH+V3UCp0nA4yPDWyJJyKEWsD5EEK24VAcotql\nkwIDAQAB\n-----END PUBLIC KEY-----\n"
info:
url: info.ga.ntu.edu.tw
key: "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5MLcsMcedzVWjw7pd/lr\nf8GdrzV6rubsJgEBJbC2OdrloHc+7uxEwWiYNTfg4j46nY/zCuTqzV/Wcfni5pY8\n0yuOmZdH9LjK0PW5BgXYJwe/bZkQmQcIQhkoSPghR8o+kZlI0a3+3gs4eAkpxB21\nPR5Rg2fvzDkaO3WcHf13HymayIk9wn4i0NdLUXgKSWcz5XNJtVBh6jtMkDq7ioOH\nQZT9OAODFw5CW/TvXBJaAvSEdDHsCNTE4vgJO1h6qowC27mErgjilA7TM81JFp40\nwexOW/gXHc4gCsj9BY39tDTqa56QIbJjKdqx7iyHUr1jMFmII1osS1ZVATco9RrM\naQIDAQAB\n-----END PUBLIC KEY-----\n"

View File

@ -397,6 +397,7 @@ en:
system_email: System Email system_email: System Email
preview: Preview preview: Preview
profile: Profile profile: Profile
promoter: Promoter
publications: Publications publications: Publications
purchase: Purchase purchase: Purchase
quantity: Quantity quantity: Quantity

17
config/locales/ntu.en.yml Normal file
View File

@ -0,0 +1,17 @@
en:
ntu:
rss_origin: Back to NTU Announcements
site_names:
"www": "Dean of General Affairs"
"sec": "Office of the Dean and Secretariat"
"doc": "Documentation Division"
"general": "General Service Division"
"property": "Property Management Division"
"construction": "Construction and Maintenance Division"
"cashier": "Cashier Division"
"procurement": "Procurement Division"
"fss": "Facilities Service Division"
"police": "Campus Security"
"social": "General Affairs Division, College of Social Science"
"medicine": "General Service Division, College of Medicine"

View File

@ -0,0 +1,17 @@
zh_tw:
ntu:
rss_origin: 回臺大校園公佈欄
site_names:
"www": "總務處"
"sec": "總務長室暨總務處秘書室"
"doc": "文書組"
"general": "事務組"
"property": "保管組"
"construction": "營繕組"
"cashier": "出納組"
"procurement": "採購組"
"fss": "經營管理組"
"police": "駐警隊"
"social": "社科院總務分處"
"medicine": "醫學院總務分處"

View File

@ -397,6 +397,7 @@ zh_tw:
sidebar_nav: 側欄導引 sidebar_nav: 側欄導引
system_email: 系統信箱 system_email: 系統信箱
profile: 基本資料 profile: 基本資料
promoter: 承辦人
publications: 著作 publications: 著作
purchase: 購買 purchase: 購買
quantity: 數量 quantity: 數量

View File

@ -15,3 +15,9 @@ email_cron:
class: EmailCron class: EmailCron
args: args:
description: EmailCron description: EmailCron
get_announcement_from_rss:
cron: 0 0 [2,12] * * *
class: GetAnnouncementFromRss
args:
description: Loop through the announcement RSS until 24h ago

View File

@ -9,6 +9,13 @@ Orbit::Application.routes.draw do
match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put match "/users_passwd" => "desktop/registrations#update", :as => :users_passwd, :via => :put
end end
devise_scope :user do
get 'user_login' => 'sessions#create'
match 'user_logout' => 'sessions#destroy'
end
match "saml_login" => 'saml_logins#index'
mount Resque::Server, :at => "/admin/resque" mount Resque::Server, :at => "/admin/resque"
mount Rack::GridFS::Endpoint.new(:db => Mongoid.database,:lookup=>:path), :at => "gridfs" mount Rack::GridFS::Endpoint.new(:db => Mongoid.database,:lookup=>:path), :at => "gridfs"

157
lib/rss_ntu_job.rb Normal file
View File

@ -0,0 +1,157 @@
# encoding: utf-8
require 'rss'
require 'mongo'
SITES = { "總務處-各單位公告" => "0",
"總務處-文書組" => "1",
"總務處-出納組" => "2",
"總務處-事務組" => "3",
"總務處-保管組" => "5",
"總務處-採購組" => "6",
"總務處-經營管理組" => "7",
"總務處-駐衛警察隊" => "9",
"總務處-營繕組" => "10",
"總務處-總務處" => "11",
"社會科學院-社會科學院總務分處" => "4",
"醫學院-醫學院總務分處" => "8" }
SITE_KEYS = SITES.keys
DB_BASE_NAME = "production_new"
all = {}
continue = true
i = 1
yesterday = Time.now - 86400
while continue do
open("http://ann.cc.ntu.edu.tw/asp/rss.asp?page=#{i}") do |rss|
feed = RSS::Parser.parse(rss.read.encode('utf-8', 'big5', invalid: :replace, undef: :replace, replace: '').gsub('<pubDate>Wes,', '<pubDate>Wed,').gsub(/(encoding=\"big5\")/, 'encoding="utf-8"'))
feed.items.each do |item|
if item.pubDate > yesterday
if SITE_KEYS.include?(item.author)
author = item.author.strip
category = item.category.to_s.gsub(/\<(\/)*category\>/, '')
if all[author]
all[author][item.link.strip] = {title: item.title.strip, author: author, link: item.link.strip, date: item.pubDate, category: category, description: item.description.gsub("\r\n", '<br/>').strip}
else
all[author] = {item.link.strip => {title: item.title.strip, author: author, link: item.link.strip, date: item.pubDate, category: category, description: item.description.gsub("\r\n", '<br/>').strip}}
end
end
else
continue = false
break
end
end
end
i += 1
end
# Get corresponding category_id or create a new one
def get_category_id(category, categories, coll_cat, bulletin_module_id)
if categories.keys.include? "rss_#{category}"
[categories["rss_#{category}"], categories]
else
cat = {
_type: "Category",
module_app_id: bulletin_module_id,
key: "rss_#{category}",
disable: false,
custom: false,
title: {:zh_tw => category},
created_at: Time.now,
updated_at: Time.now
}
categories["rss_#{category}"] = result = coll_cat.save(cat)
[result, categories]
end
end
# Get categories and id based on a given site number
def get_mongo_and_categories(site_number="0")
db = Mongo::Connection.new("localhost", 27017).db("#{DB_BASE_NAME}_#{site_number}")
bulletin_module_id = db["module_apps"].find(key: "announcement").first
coll_bulletin = db["bulletins"]
coll_buffer_cat = db["buffer_categories"]
coll_cat = db["categories"]
coll_bulletin_cat = db["categories"].find(module_app_id: bulletin_module_id["_id"])
categories = coll_bulletin_cat.find().to_a.inject({}) do |categories, category|
categories[category['key']] = category['_id']
categories
end
[categories, coll_bulletin, coll_cat, bulletin_module_id["_id"],coll_buffer_cat]
end
# Get main site (總務處) categories
@main_categories, @main_coll_bulletin, @main_coll_cat, @main_bulletin_module_id, @main_coll_buffer_cat = get_mongo_and_categories
@copy_categories, @copy_coll_bulletin, @copy_coll_cat, @copy_bulletin_module_id, @copy_coll_buffer_cat = get_mongo_and_categories('11')
all.each do |key, value| # Loop through all the authors
site_number = SITES[key]
categories, coll_bulletin, coll_cat, bulletin_module_id, coll_buffer_cat = get_mongo_and_categories(site_number) # Get current's site categories
value.each_value do |bul| # Loop through all the items
category_id, categories = get_category_id(bul[:category], categories, coll_cat, bulletin_module_id)
unless coll_bulletin.find_one(rss_link: bul[:link])
bulletin = { _type: "Bulletin",
postdate: bul[:date],
created_at: bul[:date],
updated_at: bul[:date],
public: true,
is_checked: true,
is_pending: false,
is_rejected: false,
category_id: category_id,
title: {:zh_tw => bul[:title]},
text: {:zh_tw => bul[:description]},
available_for_en: false,
available_for_zh_tw: true,
rss_link: bul[:link],
is_top: false,
is_hot: false,
is_hidden: false }
bs = coll_bulletin.save(bulletin)
buffer_cat = { _type: "BufferCategory",
category_id: category_id,
categorizable_type: "Bulletin",
categorizable_id: bs }
coll_buffer_cat.save(buffer_cat)
unless site_number.eql?("0") || @main_coll_bulletin.find_one(rss_link: bul[:link]) # Copy the item to the main site
category_id, @main_categories = get_category_id(bul[:category], @main_categories, @main_coll_cat, @main_bulletin_module_id)
main_bulletin = bulletin.clone
main_bulletin['_id'] = BSON::ObjectId.new
main_bulletin[:category_id] = category_id
@main_coll_bulletin.save(main_bulletin)
main_buffer_cat = { _type: "BufferCategory",
category_id: category_id,
categorizable_type: "Bulletin",
categorizable_id: main_bulletin['_id'] }
@main_coll_buffer_cat.save(main_buffer_cat)
category_id, @copy_categories = get_category_id(bul[:category], @copy_categories, @copy_coll_cat, @copy_bulletin_module_id)
copy_bulletin = bulletin.clone
copy_bulletin['_id'] = BSON::ObjectId.new
copy_bulletin[:category_id] = category_id
@copy_coll_bulletin.save(copy_bulletin)
copy_buffer_cat = { _type: "BufferCategory",
category_id: category_id,
categorizable_type: "Bulletin",
categorizable_id: copy_bulletin['_id'] }
@copy_coll_buffer_cat.save(copy_buffer_cat)
end
end
end
end