Skip to content

Instantly share code, notes, and snippets.

@mtgto
Created January 31, 2014 07:36
Show Gist options
  • Save mtgto/8727941 to your computer and use it in GitHub Desktop.
Save mtgto/8727941 to your computer and use it in GitHub Desktop.
ガルーンから今月&来月分のiCalデータを取ってきてくれるプロキシ
require 'sinatra'
require 'net/https'
require 'uri'
require 'date'
=begin
ガルーンから今月&来月分のiCalデータを取ってきてくれるプロキシです。
sinatraが必要なので、入れてなければgem install sinatraしてね。
使い方はこのプログラムを起動してから、iCalでカレンダーメニューの照会を開き、"http://localhost:10999/ical"を指定すればいけるはず。
=end
# 設定
PORT = 10999
USERNAME = '' # ガルーンのアカウント
PASSWORD = '' # ガルーンのパスワード
class Garoon
BASE_URL = '' # ガルーンのURL
def initialize(username, password)
@username = username
@password = password
end
def get_ical
uri = URI.parse(BASE_URL + '/schedule/personal/ical_export?')
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
https.ssl_version = :TLSv1
csrf_token = nil
cookie = nil
https.start {
request = Net::HTTP::Post.new(uri)
request.set_form_data('_system' => '1', '_account' => @username, '_password' => @password)
response = https.request(request)
cookie = response['Set-Cookie']
puts "cookie: #{cookie}"
if response.body =~ /<input type="hidden" name="csrf_ticket" value="([a-f0-9]+?)">/
csrf_token = $1
puts "csrf_token: #{csrf_token}"
else
puts "failed to take csrf_token..."
end
}
if csrf_token
https.start {
uri = URI.parse(BASE_URL + '/schedule/personal/command_ical_export/-/schedules.ical?')
request = Net::HTTP::Post.new(uri)
request['Cookie'] = cookie
start_date = Date.new(Date.today.year, Date.today.mon, 1)
end_date = Date.new(Date.today.next_month.year, Date.today.next_month.mon, -1)
request.set_form_data('csrf_ticket' => csrf_token, 'start_year' => start_date.year, 'start_month' => start_date.month, 'start_day' => start_date.day, 'end_year' => end_date.year, 'end_month' => end_date.month, 'end_day' => end_date.day)
response = https.request(request)
response.body
}
end
end
end
g = Garoon.new(USERNAME, PASSWORD)
get '/ical' do
g.get_ical
end
configure do
set :bind, '127.0.0.1'
set :port, PORT
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment