login_reliance 0.1.0 → 0.1.1
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.
- checksums.yaml +4 -4
- data/bin/login_reliance +29 -0
- data/lib/login_reliance.rb +58 -82
- data/lib/login_reliance/version.rb +1 -1
- data/login_reliance.gemspec +2 -2
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: abbc47b42092827910f4999eae5967182998f6d5
|
4
|
+
data.tar.gz: b7e75d9e2fb2452be0b5c9dce805dd472b01ebd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e2eb3cc9d33e617abb52de788276145ca6ff403a9a009594fa0f7c1db91f37b54679e9a6ec793ed5b03dfa026874c3ad6620fc13bf866b11d08dc009ea62e12
|
7
|
+
data.tar.gz: 54090c6e3ada7609e2a082040b980ddd45306c31e9d769ba37b42682a1ca2722fdf628593c29d57e273d064bd2fb5b14e404f26d2d80ccaef852d5f66af87aff
|
data/bin/login_reliance
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'login_reliance'
|
4
|
+
|
5
|
+
repeat = false
|
6
|
+
repeat = (ARGV[0] == "-r") if ARGV.size > 0
|
7
|
+
reliance = LoginReliance::Reliance.new
|
8
|
+
|
9
|
+
loop do
|
10
|
+
statusCode = reliance.login
|
11
|
+
if statusCode == StatusCode::LOGIN_FAILED
|
12
|
+
puts "Login failed."
|
13
|
+
unless repeat
|
14
|
+
puts "Try login_reliance -r to keep trying again."
|
15
|
+
break
|
16
|
+
else
|
17
|
+
puts "Trying again"
|
18
|
+
end
|
19
|
+
elsif statusCode == StatusCode::ALREADY_LOGGED_IN
|
20
|
+
puts "Already logged in"
|
21
|
+
break
|
22
|
+
elsif statusCode == StatusCode::INVALID_LOGIN
|
23
|
+
puts "Invalid login information"
|
24
|
+
reliance.remove_save_file
|
25
|
+
else
|
26
|
+
puts "Login successful"
|
27
|
+
break
|
28
|
+
end
|
29
|
+
end
|
data/lib/login_reliance.rb
CHANGED
@@ -7,102 +7,78 @@ module StatusCode
|
|
7
7
|
ALREADY_LOGGED_IN = 3
|
8
8
|
end
|
9
9
|
|
10
|
-
|
10
|
+
module LoginReliance
|
11
|
+
class Reliance
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def initialize
|
14
|
+
@save_file = File.expand_path('~/.reliance')
|
15
|
+
@url = 'http://220.224.142.229/reliance/startportal_isg.do?CPURL=null'
|
16
|
+
#@url = 'http://reliancebroadband.co.in/reliance/startportal_isg.do'
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
def read_login_from_file
|
20
|
+
begin
|
21
|
+
File.open(@save_file) do |f|
|
22
|
+
contents_array = f.gets.split(',')
|
23
|
+
throw Exception.new if contents_array.size != 2
|
24
|
+
return contents_array
|
25
|
+
end
|
26
|
+
rescue
|
24
27
|
end
|
25
|
-
|
28
|
+
nil
|
26
29
|
end
|
27
|
-
nil
|
28
|
-
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def get_login_from_user
|
35
|
-
puts 'Enter username'
|
36
|
-
username = STDIN.gets.chomp
|
37
|
-
puts 'Enter password'
|
38
|
-
password = STDIN.gets.chomp
|
39
|
-
[username, password]
|
40
|
-
end
|
31
|
+
def remove_save_file
|
32
|
+
File.delete(@save_file)
|
33
|
+
end
|
41
34
|
|
42
|
-
|
43
|
-
|
44
|
-
|
35
|
+
def get_login_from_user
|
36
|
+
puts 'Enter username'
|
37
|
+
username = STDIN.gets.chomp
|
38
|
+
puts 'Enter password'
|
39
|
+
password = STDIN.gets.chomp
|
40
|
+
[username, password]
|
45
41
|
end
|
46
|
-
end
|
47
42
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
agent.get(@url) do |signin_page|
|
52
|
-
if signin_page.body.include?("logout")
|
53
|
-
return StatusCode::ALREADY_LOGGED_IN
|
54
|
-
end
|
55
|
-
success_page = signin_page.form_with(:name => 'form1') do |form|
|
56
|
-
form.userId = username
|
57
|
-
form.password = password
|
58
|
-
end.submit
|
59
|
-
unless success_page.body.include?("logout")
|
60
|
-
return StatusCode::INVALID_LOGIN
|
61
|
-
end
|
43
|
+
def save_login_to_file(username, password)
|
44
|
+
File.open(@save_file, 'w') do |f|
|
45
|
+
f.write "#{username},#{password}"
|
62
46
|
end
|
63
|
-
rescue Exception => ex
|
64
|
-
puts ex.message
|
65
|
-
return StatusCode::LOGIN_FAILED
|
66
47
|
end
|
67
|
-
return StatusCode::LOGIN_SUCCESSFUL
|
68
|
-
end
|
69
48
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
49
|
+
def login_reliance(username, password)
|
50
|
+
begin
|
51
|
+
agent = Mechanize.new
|
52
|
+
agent.get(@url) do |signin_page|
|
53
|
+
if signin_page.body.include?("logout")
|
54
|
+
return StatusCode::ALREADY_LOGGED_IN
|
55
|
+
end
|
56
|
+
success_page = signin_page.form_with(:name => 'form1') do |form|
|
57
|
+
form.userId = username
|
58
|
+
form.password = password
|
59
|
+
end.submit
|
60
|
+
unless success_page.body.include?("logout")
|
61
|
+
return StatusCode::INVALID_LOGIN
|
62
|
+
end
|
63
|
+
end
|
64
|
+
rescue Exception => ex
|
65
|
+
puts ex.message
|
66
|
+
return StatusCode::LOGIN_FAILED
|
78
67
|
end
|
68
|
+
return StatusCode::LOGIN_SUCCESSFUL
|
79
69
|
end
|
80
|
-
login_reliance(username, password)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
repeat = false
|
85
|
-
repeat = (ARGV[0] == "-r") if ARGV.size > 0
|
86
|
-
reliance = LoginReliance.new
|
87
70
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
71
|
+
def login
|
72
|
+
username, password = read_login_from_file
|
73
|
+
if username.nil?
|
74
|
+
username, password = get_login_from_user
|
75
|
+
puts 'Do you want to save the login to a file in the home folder? (y/n)'
|
76
|
+
answer = STDIN.gets[0].downcase
|
77
|
+
if answer == 'y'
|
78
|
+
save_login_to_file(username, password)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
login_reliance(username, password)
|
97
82
|
end
|
98
|
-
elsif statusCode == StatusCode::ALREADY_LOGGED_IN
|
99
|
-
puts "Already logged in"
|
100
|
-
break
|
101
|
-
elsif statusCode == StatusCode::INVALID_LOGIN
|
102
|
-
puts "Invalid login information"
|
103
|
-
reliance.remove_save_file
|
104
|
-
else
|
105
|
-
puts "Login successful"
|
106
|
-
break
|
107
83
|
end
|
108
84
|
end
|
data/login_reliance.gemspec
CHANGED
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
#end
|
23
23
|
|
24
24
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
-
spec.bindir = "
|
26
|
-
spec.executables =
|
25
|
+
spec.bindir = "bin"
|
26
|
+
spec.executables = "login_reliance"
|
27
27
|
spec.require_paths = ["lib"]
|
28
28
|
|
29
29
|
spec.add_development_dependency "bundler", "~> 1.10"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: login_reliance
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rakesh BS
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -55,7 +55,8 @@ dependencies:
|
|
55
55
|
description:
|
56
56
|
email:
|
57
57
|
- rakeshbs@gmail.com
|
58
|
-
executables:
|
58
|
+
executables:
|
59
|
+
- login_reliance
|
59
60
|
extensions: []
|
60
61
|
extra_rdoc_files: []
|
61
62
|
files:
|
@@ -65,6 +66,7 @@ files:
|
|
65
66
|
- README.md
|
66
67
|
- Rakefile
|
67
68
|
- bin/console
|
69
|
+
- bin/login_reliance
|
68
70
|
- bin/setup
|
69
71
|
- lib/login_reliance.rb
|
70
72
|
- lib/login_reliance/version.rb
|