hotspot-login 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/hl.rb +99 -0
  3. data/lib/hl.rb +119 -0
  4. metadata +46 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a71203d114609d71636bb4490ccd636d48246745
4
+ data.tar.gz: 4fe532f0c83f237f7f639bc3a8a1b68c3a4bcf22
5
+ SHA512:
6
+ metadata.gz: 27a94406c1129a9f2f5b27d33e0900a597bd301e19a69492b4649d3e7cdccc293b1b5e2dfad270d6deea8344e47f5ee2403eeffdf6a8d5020cf84e01cfbe1b65
7
+ data.tar.gz: 0001cc81897e290c609e0328e9ad05b0d12c1cf194392c12d10a5e8548792fe9baf8ca55b9287d4f6bc56f2c789b93586f86efaea899208c4ecce64844c6a5c2
data/bin/hl.rb ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+ require 'yaml'
3
+ require 'optparse'
4
+ require 'hl'
5
+
6
+ class Hotspot_Login
7
+ def initialize
8
+ @engine = {
9
+ "sfr" => Hotspot::Sfr,
10
+ "free" => Hotspot::FreeWifi
11
+ }
12
+ end
13
+
14
+ def parse
15
+ @options = parse!(ARGV) if @options.nil?
16
+ @options
17
+ end
18
+
19
+ def parse!(args)
20
+ options = {verbose: false, hotspot: nil}
21
+
22
+ opt_parser = OptionParser.new do |opts|
23
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
24
+ options[:verbose] = true
25
+ end
26
+
27
+ opts.on("-h", "--hotspot HOTSPOT", "Hotspot") do |hotspot|
28
+ options[:hotspot] = hotspot
29
+ end
30
+
31
+ opts.on("-u", "--user USER", "User") do |user|
32
+ options[:user] = user
33
+ end
34
+
35
+ opts.on("-p", "--password PASSWORD","Password") do |password|
36
+ options[:password] = password
37
+ end
38
+ end
39
+
40
+ opt_parser.parse!(args)
41
+ @options = options
42
+ end
43
+
44
+ def config
45
+ @config = config! if @config.nil?
46
+ @config
47
+ end
48
+
49
+ def config!
50
+ config = {
51
+ "sfr" => {type: "sfr"},
52
+ "free" => {type: "free"}
53
+ }
54
+
55
+ file = File.open(Dir.home + "/.config/hl.yml")
56
+ config.merge! YAML.load(file)
57
+ end
58
+
59
+ def connect
60
+ connected = false
61
+ hotspot = parse[:hotspot]
62
+ if not hotspot.nil?
63
+ raise "Not found config hotspot: #{hotspot}" if config[hotspot].nil?
64
+ connected = connect! config[hotspot].merge!(parse)
65
+ else
66
+ config.each do |hotspot, params|
67
+ if connect! params.merge!(parse)
68
+ connected = true
69
+ break
70
+ end
71
+ end
72
+ end
73
+
74
+ if connected
75
+ puts "Connected"
76
+ true
77
+ else
78
+ puts "Not connected"
79
+ false
80
+ end
81
+ end
82
+
83
+ def connect!(config)
84
+ engine = engine?(config[:type])
85
+ hotspot = engine.new(config[:user], config[:password])
86
+
87
+ raise "Already connected" if hotspot.connect?
88
+ return false if not hotspot.hotspot?
89
+
90
+ hotspot.auth
91
+ hotspot.connect?
92
+ end
93
+
94
+ def engine?(type)
95
+ @engine[type]
96
+ end
97
+ end
98
+
99
+ Hotspot_Login.new.connect
data/lib/hl.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'net/http'
2
+ require 'cgi'
3
+
4
+ module Hotspot
5
+ class Hotspot
6
+ def initialize(user, password)
7
+ @uri_test = URI("http://www.example.com")
8
+ @user = user
9
+ @password = password
10
+ login_url
11
+ end
12
+
13
+ def connect?
14
+ redirect = redirect? Net::HTTP.get_response(@uri_test)
15
+ redirect == @uri_test.to_s
16
+ end
17
+
18
+ def login_url
19
+ login_url! if @login_url.nil?
20
+ @login_url
21
+ end
22
+
23
+ def login_url!
24
+ @login_url = redirect? Net::HTTP.get_response(@uri_test)
25
+ end
26
+
27
+ #& Feature : HTTP redirect
28
+ def redirect?(res)
29
+ case res
30
+ when Net::HTTPSuccess then
31
+ javascript = /window\.location = \"(.*)\"/m.match(res.body)
32
+ if not javascript.nil?
33
+ javascript[1]
34
+ else
35
+ res.uri.to_s
36
+ end
37
+ when Net::HTTPRedirection then
38
+ res['location']
39
+ else
40
+ raise
41
+ end
42
+ end
43
+
44
+ def info
45
+ URI.parse(login_url)
46
+ end
47
+
48
+ def params
49
+ if not info.query.nil?
50
+ CGI::parse(info.query)
51
+ else
52
+ Hash.new
53
+ end
54
+ end
55
+
56
+ def uri_test
57
+ @uri_test
58
+ end
59
+
60
+ def auth
61
+ raise
62
+ end
63
+
64
+ def get(uri)
65
+ Net::HTTP.get_response(URI(uri))
66
+ end
67
+
68
+ def post(uri, query)
69
+ Net::HTTP.post_form(URI(uri), query)
70
+ end
71
+
72
+ def sfr?
73
+ info.host == "hotspot.wifi.sfr.fr"
74
+ end
75
+
76
+ def uppa?
77
+ info.host == "wism.univ-pau.fr"
78
+ end
79
+
80
+ def free?
81
+ info.host == "wifi.free.fr"
82
+ end
83
+ end
84
+
85
+ class Sfr < Hotspot
86
+ def hotspot?
87
+ sfr?
88
+ end
89
+
90
+ def auth
91
+ query = params.merge!({username: @user, username2: @user, password: @password, conditions: "on", lang: "fr", connexion: "Connexion", accessType: "neuf"})
92
+ t = redirect? post("https://hotspot.wifi.sfr.fr/nb4_crypt.php", query)
93
+ get(t)
94
+ end
95
+ end
96
+
97
+ class UPPA < Hotspot
98
+ def hotspot?
99
+ uppa?
100
+ end
101
+
102
+ def auth
103
+ query = params.merge!({username: @user, password: @password, buttonClicked: 4, info_msg:nil, info_flag: 0, err_msg: nil, err_flag: 0})
104
+ post("https://wism.univ-pau.fr/login.html", query)
105
+ end
106
+ end
107
+
108
+ class FreeWifi < Hotspot
109
+ def hotspot?
110
+ free?
111
+ end
112
+
113
+ def auth
114
+ query = params.merge!({login: @user, password: @password, submit: "Valider"})
115
+ post("https://wifi.free.fr/Auth", query)
116
+ end
117
+ end
118
+
119
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hotspot-login
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Jeser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Hotspot Login
14
+ email: adrien@jeser.me
15
+ executables:
16
+ - hl.rb
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/hl.rb
21
+ - bin/hl.rb
22
+ homepage: http://rubygems.org/gems/hl
23
+ licenses:
24
+ - GPLv3
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.14
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: HotspotLogin
46
+ test_files: []