turksatkablo_cli 0.3.0-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +35 -0
- data/.rspec +1 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +62 -0
- data/Rakefile +9 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bin/turksatkablo +28 -0
- data/lib/init/poltergeist.rb +12 -0
- data/lib/turksatkablo_cli.rb +33 -0
- data/lib/turksatkablo_cli/base.rb +16 -0
- data/lib/turksatkablo_cli/online_operations/agent.rb +145 -0
- data/lib/turksatkablo_cli/online_operations/auth.rb +71 -0
- data/lib/turksatkablo_cli/online_operations/cli.rb +214 -0
- data/lib/turksatkablo_cli/online_operations/commands/quota.rb +47 -0
- data/lib/turksatkablo_cli/online_operations/enums.rb +43 -0
- data/lib/turksatkablo_cli/online_operations/helpers.rb +62 -0
- data/lib/turksatkablo_cli/online_operations/version.rb +5 -0
- data/spec/helpers_spec.rb +72 -0
- data/spec/spec_helper.rb +30 -0
- data/spec/support/required_all/console_notifier.rb +5 -0
- data/spec/support/required_all/user.rb +5 -0
- data/spec/version_spec.rb +7 -0
- data/turksatkablo_cli.gemspec +52 -0
- metadata +320 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
require 'openssl'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
|
6
|
+
module TurksatkabloCli
|
7
|
+
module OnlineOperations
|
8
|
+
class Auth
|
9
|
+
include Singleton
|
10
|
+
include Helpers
|
11
|
+
attr_reader :path, :login_type
|
12
|
+
attr_accessor :login_data
|
13
|
+
|
14
|
+
FILE_NAME = '.turksatkablo'.freeze
|
15
|
+
KEY = "m\x13\x95\xBE6\x81\xEEN\xE6\xDC\xA0\x83K\xE8X2\a\xD7\xB2\x94L\xF2\xEC\xF9\x80\x9F_\xDB\xDB\xD05\v".freeze
|
16
|
+
private_constant :KEY
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@path = File.join(File.expand_path('~'), FILE_NAME)
|
20
|
+
@login_data = get
|
21
|
+
end
|
22
|
+
|
23
|
+
def save_login_info
|
24
|
+
login_info = { :radio_btn_value => agent.radio_btn_value, :username => agent.username,
|
25
|
+
:password => agent.password }
|
26
|
+
|
27
|
+
save_file(login_info) if @path
|
28
|
+
puts "Bilgileriniz bilgisayarınızda şifrelenerek saklandı." if File.exists?(@path)
|
29
|
+
|
30
|
+
login_info
|
31
|
+
end
|
32
|
+
|
33
|
+
def get
|
34
|
+
return read_file if File.exists?(@path)
|
35
|
+
begin
|
36
|
+
if agent.get_login
|
37
|
+
save_login_info
|
38
|
+
|
39
|
+
end
|
40
|
+
rescue Exception => e
|
41
|
+
puts "Bir sorun oluştu."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def read_file
|
46
|
+
YAML.load(decryption(File.read(@path)))
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def save_file(hash)
|
51
|
+
File.open(@path, 'w') { |file| file.write encryption(YAML.dump(hash)) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def encryption(data)
|
55
|
+
cipher = OpenSSL::Cipher::AES256.new :CBC
|
56
|
+
cipher.encrypt
|
57
|
+
cipher.key = KEY
|
58
|
+
cipher.update(data) + cipher.final
|
59
|
+
end
|
60
|
+
|
61
|
+
def decryption(data)
|
62
|
+
decipher = OpenSSL::Cipher::AES256.new :CBC
|
63
|
+
decipher.decrypt
|
64
|
+
decipher.key = KEY
|
65
|
+
decipher.update(data) + decipher.final
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
@@ -0,0 +1,214 @@
|
|
1
|
+
require 'terminal-table'
|
2
|
+
require 'launchy'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'securerandom'
|
5
|
+
|
6
|
+
module TurksatkabloCli
|
7
|
+
module OnlineOperations
|
8
|
+
class Cli < Base
|
9
|
+
# check_unknown_options!
|
10
|
+
|
11
|
+
|
12
|
+
def initialize(*)
|
13
|
+
@session = agent.session
|
14
|
+
super
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "ozet", "Hizmetler genel durum - kısa kodu o"
|
18
|
+
def ozet
|
19
|
+
if agent.authenticated?
|
20
|
+
invoke :kota
|
21
|
+
invoke :musterino
|
22
|
+
invoke :anlikborc
|
23
|
+
end
|
24
|
+
end
|
25
|
+
map "o" => "ozet"
|
26
|
+
|
27
|
+
desc "kota", "Kalan kota - kısa kodu k"
|
28
|
+
def kota
|
29
|
+
if agent.authenticated?
|
30
|
+
@session.find(:css, "div.circle-container div.toplam p").all("span, sub").map(&:text).each { |val| puts val }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
map "k" => "kota"
|
34
|
+
|
35
|
+
desc "musterino", "Müşteri no - kısa kodu mn"
|
36
|
+
def musterino
|
37
|
+
if agent.authenticated?
|
38
|
+
puts @session.find(:css, "div.musteri div.musteri-id").text
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
map "mn" => "musterino"
|
43
|
+
|
44
|
+
desc "hizmet", "Mevcut hizmetler - kısa kodu h"
|
45
|
+
def hizmet
|
46
|
+
if agent.authenticated?
|
47
|
+
visit_status = @session.visit(Enums::SERVICE_OPERATIONS_URL)
|
48
|
+
if visit_status["status"] == 'success' && @session.current_url == Enums::SERVICE_OPERATIONS_URL
|
49
|
+
|
50
|
+
# TODO: REFACTOR table helper
|
51
|
+
|
52
|
+
rows = []
|
53
|
+
services_td_list = @session.all(:css, 'table#hizmetTable tr td:nth-child(-n+4)').map(&:text)
|
54
|
+
|
55
|
+
if services_td_list.size > 0
|
56
|
+
(0..services_td_list.size).step(4) do |n|
|
57
|
+
rows << services_td_list[n...n+4]
|
58
|
+
end
|
59
|
+
|
60
|
+
table = Terminal::Table.new :headings => [Enums::HIZMET, Enums::HIZMET_TURU, Enums::HIZMET_DURUMU, Enums::TARIFE_TIPI], :rows => rows
|
61
|
+
puts table
|
62
|
+
else
|
63
|
+
puts "Mevcut bir hizmetiniz bulunmamaktadır."
|
64
|
+
end
|
65
|
+
|
66
|
+
else
|
67
|
+
puts "Hizmet İşlemleri menüsüne şuan ulaşılamıyor."
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
map "h" => "hizmet"
|
73
|
+
|
74
|
+
desc "kampanya", "Kampanya bilgileri - kısa kodu ka"
|
75
|
+
def kampanya
|
76
|
+
if agent.authenticated?
|
77
|
+
visit_status = @session.visit(Enums::CAMPAIGN_INFO_URL)
|
78
|
+
if visit_status["status"] == 'success' && @session.current_url == Enums::CAMPAIGN_INFO_URL
|
79
|
+
|
80
|
+
# TODO: REFACTOR table helper
|
81
|
+
rows = []
|
82
|
+
campaigns_td_list = @session.all(:css, 'table.table tr td').map(&:text)
|
83
|
+
|
84
|
+
if campaigns_td_list.size > 0
|
85
|
+
(0..campaigns_td_list.size).step(4) do |n|
|
86
|
+
rows << campaigns_td_list[n...n+4]
|
87
|
+
end
|
88
|
+
|
89
|
+
table = Terminal::Table.new :headings => [Enums::HIZMET_ID, Enums::KAMPANYA_ADI, Enums::TAAHHUT_BAS_TRH, Enums::TAAHHUT_BIT_TRH], :rows => rows
|
90
|
+
puts table
|
91
|
+
else
|
92
|
+
puts "Mevcut bir kampanyanız bulunmamaktadır."
|
93
|
+
end
|
94
|
+
|
95
|
+
else
|
96
|
+
puts "Kampanya Bilgileri menüsüne şuan ulaşılamıyor."
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
101
|
+
map "ka" => "kampanya"
|
102
|
+
|
103
|
+
desc "anlikborc", "Anlık borç - kısa kodu b"
|
104
|
+
def anlikborc
|
105
|
+
if agent.authenticated?
|
106
|
+
visit_status = @session.visit(Enums::INSTANT_DEBT_URL)
|
107
|
+
if visit_status["status"] == 'success' && @session.current_url == Enums::INSTANT_DEBT_URL
|
108
|
+
@session.find(:css, "div.anlik-borc").all("p, h1, small").map(&:text).each { |val| puts val }
|
109
|
+
else
|
110
|
+
puts "Anlık Borç menüsüne şuan ulaşılamıyor."
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
map "b" => "anlikborc"
|
115
|
+
|
116
|
+
desc "fatura TARIH", "Fatura göster ÖRN: 12.2017, ÖRN: 12.2017 pdf - kısa kodu f"
|
117
|
+
def fatura(tarih, pdf=nil)
|
118
|
+
if agent.authenticated?
|
119
|
+
visit_status = @session.visit(Enums::INVOICES_URL)
|
120
|
+
if visit_status["status"] == 'success' && @session.current_url == Enums::INVOICES_URL
|
121
|
+
temp = Dir.tmpdir()
|
122
|
+
invoice_file_path = temp + '/' + SecureRandom.uuid + '.html'
|
123
|
+
|
124
|
+
begin
|
125
|
+
if pdf
|
126
|
+
link_element = @session.find('tr', text: tarih).find('a:last-child')
|
127
|
+
if link_element[:id] != nil && link_element[:id] == "PDFYok"
|
128
|
+
puts "Fatura PDF'iniz ayın 13'ünden sonra oluşacaktır."
|
129
|
+
else
|
130
|
+
visit_url = link_element[:href]
|
131
|
+
Launchy.open(visit_url)
|
132
|
+
puts "Faturanız varsayılan internet tarayıcınızda açıldı, kontrol ediniz!"
|
133
|
+
end
|
134
|
+
|
135
|
+
else
|
136
|
+
op_button_count = @session.find('tr', text: tarih).all('a').size
|
137
|
+
|
138
|
+
link_css_selector = 'a:first-child'
|
139
|
+
if op_button_count != nil
|
140
|
+
if op_button_count == 3
|
141
|
+
link_css_selector = 'a:nth-child(2)'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
fatura_url = @session.find('tr', text: tarih).find(link_css_selector)[:onclick]
|
146
|
+
if fatura_url != nil
|
147
|
+
first_single_quote_ix = fatura_url.index('\'')
|
148
|
+
second_single_quote_ix = fatura_url.index('\'', first_single_quote_ix+1)
|
149
|
+
|
150
|
+
fatura_url = fatura_url[first_single_quote_ix+1..second_single_quote_ix-1]
|
151
|
+
visit_url = Enums::BASE_URL + fatura_url
|
152
|
+
|
153
|
+
@session.visit(visit_url)
|
154
|
+
File.open( "#{invoice_file_path}", "w+" ) { |f| f.write @session.html }
|
155
|
+
Launchy.open("#{invoice_file_path}")
|
156
|
+
puts 'Faturanız varsayılan internet tarayıcınızda açıldı, kontrol ediniz!'
|
157
|
+
else
|
158
|
+
puts "Mevcut bir faturanız bulunmamaktadır."
|
159
|
+
end
|
160
|
+
|
161
|
+
end
|
162
|
+
rescue Exception => e
|
163
|
+
puts 'Bir hata oluştu, mevcut bir faturanız bulunmamaktadır, fatura görüntüleme'
|
164
|
+
end
|
165
|
+
else
|
166
|
+
puts "Fatura Bilgileri menüsüne şuan ulaşılamıyor."
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
171
|
+
map "f" => "fatura"
|
172
|
+
|
173
|
+
desc "faturaliste", "Fatura listesi - kısa kodu fl"
|
174
|
+
def faturaliste
|
175
|
+
if agent.authenticated?
|
176
|
+
visit_status = @session.visit(Enums::INVOICES_URL)
|
177
|
+
if visit_status["status"] == 'success' && @session.current_url == Enums::INVOICES_URL
|
178
|
+
|
179
|
+
# TODO: REFACTOR table helper
|
180
|
+
rows = []
|
181
|
+
|
182
|
+
invoices_td_list = @session.all(:css, 'div.panel-default table.table tr td:nth-child(-n+5)').map(&:text)
|
183
|
+
|
184
|
+
if invoices_td_list.size > 0
|
185
|
+
(0..invoices_td_list.size).step(5) do |n|
|
186
|
+
rows << invoices_td_list[n...n+5]
|
187
|
+
end
|
188
|
+
|
189
|
+
table = Terminal::Table.new :headings => [Enums::AD_SOYAD, Enums::SON_ODEME_TRH, Enums::FATURA_TUTARI, Enums::GECIKME_BEDELI, Enums::TOPLAM_TUTAR], :rows => rows.reverse
|
190
|
+
puts table
|
191
|
+
else
|
192
|
+
puts "Mevcut bir faturanız bulunmamaktadır."
|
193
|
+
end
|
194
|
+
|
195
|
+
else
|
196
|
+
puts "Fatura Bilgileri menüsüne şuan ulaşılamıyor."
|
197
|
+
end
|
198
|
+
|
199
|
+
end
|
200
|
+
end
|
201
|
+
map "fl" => "faturaliste"
|
202
|
+
|
203
|
+
# default_task :ozet
|
204
|
+
|
205
|
+
|
206
|
+
desc "kotadetay", "Son 3 ay kota kullanım - kısa kodu kd"#son 3 ayın günlük takibi v.s"
|
207
|
+
subcommand 'kotadetay', Commands::Quota
|
208
|
+
map "kd" => "kotadetay"
|
209
|
+
|
210
|
+
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module TurksatkabloCli
|
2
|
+
module OnlineOperations
|
3
|
+
module Commands
|
4
|
+
class Quota < Base
|
5
|
+
|
6
|
+
def initialize(*)
|
7
|
+
@session = agent.session
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
desc "donem", "Kota Dönem takibi - kısa kodu d"
|
12
|
+
def donem
|
13
|
+
if agent.authenticated?
|
14
|
+
visit_status = @session.visit(Enums::QUOTA_PERIOD)
|
15
|
+
if visit_status["status"] == 'success' && @session.current_url == Enums::QUOTA_PERIOD
|
16
|
+
|
17
|
+
# TODO: REFACTOR table helper
|
18
|
+
rows = []
|
19
|
+
|
20
|
+
periods_td_list = @session.all(:css, 'div.panel-default table.table tr td:nth-child(-n+4)').map(&:text)
|
21
|
+
|
22
|
+
if periods_td_list.size > 0
|
23
|
+
(0..periods_td_list.size).step(4) do |n|
|
24
|
+
rows << periods_td_list[n...n+4]
|
25
|
+
end
|
26
|
+
|
27
|
+
table = Terminal::Table.new :headings => [Enums::HIZMET_ID, Enums::DONEM, Enums::DOWNLOAD_KULLANIM, Enums::UPLOAD_KULLANIM], :rows => rows
|
28
|
+
puts table
|
29
|
+
else
|
30
|
+
puts "Mevcut bir faturanız bulunmamaktadır."
|
31
|
+
end
|
32
|
+
|
33
|
+
else
|
34
|
+
puts "Kota dönem takibi menüsüne şuan ulaşılamıyor."
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
map "d" => "donem"
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'ruby-enum'
|
2
|
+
|
3
|
+
module TurksatkabloCli
|
4
|
+
module OnlineOperations
|
5
|
+
class Enums
|
6
|
+
include Ruby::Enum
|
7
|
+
|
8
|
+
define :BASE_URL, "https://online.turksatkablo.com.tr/"
|
9
|
+
define :BASE_URL_SUCCESS, "https://online.turksatkablo.com.tr/hosgeldiniz.aspx"
|
10
|
+
define :SERVICE_OPERATIONS_URL, "https://online.turksatkablo.com.tr/MusteriHizmetleri.aspx#Hizmet-Islemleri"
|
11
|
+
define :CAMPAIGN_INFO_URL, "https://online.turksatkablo.com.tr/KampanyaBilgileri.aspx#Hizmet-Islemleri"
|
12
|
+
define :INSTANT_DEBT_URL, "https://online.turksatkablo.com.tr/AnlikBorc.aspx#Fatura-Islemleri"
|
13
|
+
define :INVOICES_URL, "https://online.turksatkablo.com.tr/Faturalar.aspx"
|
14
|
+
define :QUOTA_PERIOD, "https://online.turksatkablo.com.tr/MusteriKotaDonem.aspx#Hizmet-Islemleri"
|
15
|
+
|
16
|
+
|
17
|
+
define :HIZMET, "HİZMET"
|
18
|
+
define :HIZMET_TURU, "HİZMET TÜRÜ"
|
19
|
+
define :HIZMET_DURUMU, "HİZMET DURUMU"
|
20
|
+
define :TARIFE_TIPI, "TARİFE TİPİ"
|
21
|
+
|
22
|
+
|
23
|
+
define :HIZMET_ID, "HİZMET ID"
|
24
|
+
define :KAMPANYA_ADI, "KAMPANYA ADI"
|
25
|
+
define :TAAHHUT_BAS_TRH, "TAAHHÜT BAŞLANGIÇ TARİHİ"
|
26
|
+
define :TAAHHUT_BIT_TRH, "TAAHHÜT BİTİŞ TARİHİ"
|
27
|
+
|
28
|
+
|
29
|
+
define :AD_SOYAD, "AD SOYAD"
|
30
|
+
define :SON_ODEME_TRH, "SON ÖDEME TARİHİ"
|
31
|
+
define :FATURA_TUTARI, "FATURA TUTARI(TL)"
|
32
|
+
define :GECIKME_BEDELI, "GECİKME BEDELİ(TL)"
|
33
|
+
define :TOPLAM_TUTAR, "TOPLAM TUTAR(TL)"
|
34
|
+
|
35
|
+
define :DONEM, "DÖNEM"
|
36
|
+
define :DOWNLOAD_KULLANIM, "DOWNLOAD KULLANIM"
|
37
|
+
define :UPLOAD_KULLANIM, "UPLOAD KULLANIM"
|
38
|
+
|
39
|
+
|
40
|
+
define :PHANTOM_JS_REQUIRED, "turksatkablo_cli requires phantomjs https://github.com/rokumatsumoto/turksatkablo_cli#setup"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'net/ping'
|
2
|
+
|
3
|
+
module TurksatkabloCli
|
4
|
+
module OnlineOperations
|
5
|
+
module Helpers
|
6
|
+
extend self
|
7
|
+
|
8
|
+
def internet_connection?(host = "8.8.8.8")
|
9
|
+
begin
|
10
|
+
Net::Ping::External.new(host).ping?
|
11
|
+
rescue
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def require_all(_dir)
|
17
|
+
Dir[File.join(_dir, "**/*.rb")].each do |file|
|
18
|
+
require file
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def agent
|
23
|
+
unless $agent
|
24
|
+
$agent = TurksatkabloCli::OnlineOperations::Agent.new
|
25
|
+
end
|
26
|
+
$agent
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_line
|
30
|
+
puts "\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_ruby_version(ruby_version = RUBY_VERSION)
|
34
|
+
if ruby_version < '2.2.0'
|
35
|
+
abort "turksatkablo_cli requires Ruby 2.2.0 or higher"
|
36
|
+
else
|
37
|
+
ruby_version
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_is_installed?(command, err_msg)
|
42
|
+
if which(command)
|
43
|
+
true
|
44
|
+
else
|
45
|
+
abort(err_msg)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def which(command)
|
50
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
51
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
52
|
+
exts.each { |ext|
|
53
|
+
exe = File.join(path, "#{command}#{ext}")
|
54
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
55
|
+
}
|
56
|
+
end
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|