titech-pubnet-auth 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/titech-pubnet-auth
CHANGED
@@ -1,12 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# -*- coding: utf-8 -*-
|
3
3
|
|
4
|
-
OS_X = RbConfig::CONFIG["target_os"].downcase =~ /^darwin/
|
5
|
-
|
6
4
|
$:.unshift File.expand_path('../lib', File.dirname(__FILE__))
|
7
5
|
require 'titech_pubnet_auth'
|
8
6
|
require 'optparse'
|
9
|
-
require 'terminal-notifier' if OS_X
|
10
7
|
|
11
8
|
opt = OptionParser.new
|
12
9
|
|
@@ -61,8 +58,7 @@ if daemon
|
|
61
58
|
end
|
62
59
|
|
63
60
|
|
64
|
-
|
65
|
-
error_notifier = ->(e){TerminalNotifier.notify(e.inspect,:title => 'Titech Punet Auth',:subtitle => 'Caught an unexpected error!') if OS_X}
|
61
|
+
include TitechPubnetAuth::BinRoutines
|
66
62
|
|
67
63
|
pubnet_auth = TitechPubnetAuth.new
|
68
64
|
retry_count = 0
|
@@ -71,7 +67,7 @@ loop do |t|
|
|
71
67
|
if mputs 'network_available?', pubnet_auth.network_available?
|
72
68
|
if not mputs 'is_connected?', pubnet_auth.is_connected?
|
73
69
|
if mputs 'auth', pubnet_auth.auth
|
74
|
-
notifier
|
70
|
+
notifier
|
75
71
|
retry_count = 0
|
76
72
|
pubnet_auth = TitechPubnetAuth.new(open_timeout: 3)
|
77
73
|
end
|
@@ -83,7 +79,7 @@ loop do |t|
|
|
83
79
|
puts " #{e.message}"
|
84
80
|
puts " == Stack Trace =="
|
85
81
|
puts e.backtrace.map{|l| " #{l}"}.join("\n")
|
86
|
-
error_notifier
|
82
|
+
error_notifier(e) if debug
|
87
83
|
|
88
84
|
pubnet_auth = TitechPubnetAuth.new(open_timeout: 10)
|
89
85
|
retry_count += 1
|
data/lib/titech_pubnet_auth.rb
CHANGED
@@ -5,7 +5,7 @@ require 'uri'
|
|
5
5
|
require 'yaml'
|
6
6
|
|
7
7
|
$:.unshift File.dirname(__FILE__)
|
8
|
-
require 'titech_pubnet_auth/
|
8
|
+
require 'titech_pubnet_auth/bin_routines'
|
9
9
|
|
10
10
|
|
11
11
|
class TitechPubnetAuth
|
@@ -55,11 +55,11 @@ class TitechPubnetAuth
|
|
55
55
|
#
|
56
56
|
# note: titech-pubnet allows to access portal.titech.ac.jp without authentication.
|
57
57
|
#
|
58
|
-
def network_available?
|
58
|
+
def network_available?(sample_uri = SAMPLE_URI.call)
|
59
59
|
@agent.get('http://portal.titech.ac.jp')
|
60
60
|
return true
|
61
|
-
rescue
|
62
|
-
return
|
61
|
+
rescue # check another website just to make sure
|
62
|
+
return @agent.get(sample_uri).uri.hostname == sample_uri.hostname
|
63
63
|
end
|
64
64
|
|
65
65
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
|
3
|
+
class TitechPubnetAuth
|
4
|
+
module BinRoutines
|
5
|
+
module_function
|
6
|
+
|
7
|
+
if RbConfig::CONFIG["target_os"].downcase =~ /^darwin/
|
8
|
+
require 'terminal-notifier'
|
9
|
+
|
10
|
+
def notifier
|
11
|
+
TerminalNotifier.notify(nil,:title => 'Titech Punet Auth', :subtitle => 'Connected!')
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_notifier(e)
|
15
|
+
TerminalNotifier.notify(e.inspect,:title => 'Titech Punet Auth',:subtitle => 'Caught an unexpected error!')
|
16
|
+
end
|
17
|
+
|
18
|
+
else
|
19
|
+
def notifier; end
|
20
|
+
def error_notifier; end
|
21
|
+
end
|
22
|
+
|
23
|
+
require 'colorize'
|
24
|
+
|
25
|
+
def mputs(tag,msg)
|
26
|
+
s = Time.now.strftime("%Y-%m-%d %H:%M:%S").green + "\t" + caller.first[/([^:]*):/,1].split('/').last.blue + "\t" + tag + ":" + msg.to_s
|
27
|
+
puts(s)
|
28
|
+
return msg
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: titech-pubnet-auth
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-12-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: colorize
|
@@ -68,7 +68,7 @@ executables:
|
|
68
68
|
extensions: []
|
69
69
|
extra_rdoc_files: []
|
70
70
|
files:
|
71
|
-
- lib/titech_pubnet_auth/
|
71
|
+
- lib/titech_pubnet_auth/bin_routines.rb
|
72
72
|
- lib/titech_pubnet_auth/version.rb
|
73
73
|
- lib/titech_pubnet_auth.rb
|
74
74
|
- bin/titech-pubnet-auth
|
@@ -1,14 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'colorize'
|
4
|
-
|
5
|
-
module Kernel
|
6
|
-
#
|
7
|
-
# バッチ処理の経過報告用メソッド。ファイル名と時刻を付けて出力してくれる。
|
8
|
-
#
|
9
|
-
def mputs(tag,msg)
|
10
|
-
s = Time.now.strftime("%Y-%m-%d %H:%M:%S").green + "\t" + caller.first[/([^:]*):/,1].split('/').last.blue + "\t" + tag + ":" + msg.to_s
|
11
|
-
puts(s)
|
12
|
-
return msg
|
13
|
-
end
|
14
|
-
end
|