This repository has been archived by the owner on Jul 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
yota.js
194 lines (171 loc) · 6.56 KB
/
yota.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//
// SET YOUR CREDENTIALS HERE
//
var login = '',
password = '';
//
// DON'T MODIFY ANYTHING BELOW THIS LINE
//
// ----------------------------------------------------------------------------------------------
//
var ip_url = 'http://www.myglobalip.com/',
base_url = 'https://my.yota.ru/selfcare/',
login_url = 'login',
dev_url = 'devices';
var casper = require('casper').create({
verbose: false,
logLevel: 'debug'
});
show_usage_and_exit = function() {
casper.echo("Usage: yota [ status | list | set <desired-speed> ]");
casper.echo("\tstatus\t- Показывает текущий план и остаток дней");
casper.echo("\tlist\t- Показывает список доступных скоростей для команды set");
casper.echo("\tset\t- Устанавливает скорость Интернета");
casper.exit();
};
if (!login.length || !password.length) {
casper.echo("Пожалуйста настройте ваш login и password в файле yota.js !");
casper.exit();
}
if (!casper.cli.args.length) {
show_usage_and_exit();
}
if (casper.cli.args[0] === 'set') {
if (casper.cli.args.length < 2) {
casper.echo("Пожалуйста, укажите скорость (используйте команду 'list' для списка доступных парамтеров)");
show_usage_and_exit();
}
if (casper.cli.args[1] === 64) {
casper.echo("Бесплатный доступ (64 кбит/с) не может быть установлен при активной подписке");
casper.exit();
}
}
casper.start(ip_url);
// casper.then(function() {
// this.capture('0.png', {
// top: 100,
// left: 0,
// width: 600,
// height: 600
// });
// });
casper.then(function() {
var ip = this.evaluate(function() {
var ip = $(".ip").get(0).innerText.split(".");
return ip;
});
if (!ip) {
this.echo("Нет подключения к Интернету ?!");
this.exit();
}
var yota_ip_range = [ "178.176", "178.177", "109.188" ],
our_ip = ip[0] + '.' + ip[1];
if (yota_ip_range.indexOf(our_ip) !== -1)
this.echo("Вы подключены к Интернету через Yota");
else
this.echo("ВНИМАНИЕ: Вы НЕ подключены к Интернету через Yota !");
});
casper.thenOpen(base_url+'login');
// casper.then(function() {
// this.test.assertExists('input[name=IDToken1]', 'login field is found');
// this.test.assertExists('input[name=IDToken1]', 'password field is found');
// this.test.assertExists('#doSubmitLoginForm', 'submit button is found');
// });
casper.thenEvaluate(function(login, password) {
$('input[name=IDToken1]').attr('value', login);
$('input[name=IDToken2]').attr('value', password);
$('#doSubmitLoginForm').click();
}, login, password);
// casper.then(function() {
// this.capture('1.png', {
// top: 100,
// left: 0,
// width: 600,
// height: 600
// });
// });
casper.thenOpen(base_url+'devices');
// casper.then(function() {
// this.capture('2.png', {
// top: 100,
// left: 0,
// width: 600,
// height: 600
// });
// });
switch (casper.cli.args[0]) {
case 'status':
casper.then(function() {
var current = this.evaluate(function() {
var result = '';
var f = $('.tariff-choice-form');
var steps = sliderData[f.find('input[name="product"]').val()].steps;
var offerCode = f.find('input[name="offerCode"]').val();
for (var i = 0; i < steps.length; i++) {
if(steps[i].code == offerCode) {
result = 'План: '+steps[i].name + '\nОсталось: ' + steps[i].remainNumber + ' дней';
break;
}
}
return result;
});
this.echo(current);
});
break;
case 'list':
casper.then(function() {
var variants = this.evaluate(function() {
var variants = [];
var f = $('.tariff-choice-form');
var steps = sliderData[f.find('input[name="product"]').val()].steps;
for (var i = 0; i < steps.length; i++) {
var speedNumber = steps[i].speedNumber;
variants[i] = (/max/.test(speedNumber) ? 'max : ' : speedNumber +' : ') + (steps[i].name || steps[i].description) + '(остаток ' + steps[i].remainNumber + ')';
}
return variants;
});
for (var i = 0; i < variants.length; i++) {
this.echo(variants[i]);
}
});
break;
case "set":
casper.then(function() {
var new_status = this.evaluate(function(speed) {
var f = $('.tariff-choice-form');
var steps = sliderData[f.find('input[name="product"]').val()].steps;
var currentOfferCode = f.find('input[name="offerCode"]').val();
var offerCode = null;
var status = "";
var isDisablingAutoprolong = false;
for (var i = 0; i < steps.length; i++) {
if (steps[i].speedNumber == speed || (speed == 'max' && steps[i].speedNumber.contains('max'))) {
offerCode = steps[i].code;
status = 'Новый План: '+steps[i].name + '\nОсталось: ' + steps[i].remainNumber + ' дней';
isDisablingAutoprolong = steps[i].isDisablingAutoprolong;
}
}
if (offerCode && currentOfferCode != offerCode) {
f.find("form").append("<input type='hidden' name='isDisablingAutoprolong' value='" + isDisablingAutoprolong + "'/>");
f.find('[name="offerCode"]').val(offerCode);
f.find('[name="productOfferingCode"]').val(offerCode);
f.submit();
}
return status;
}, casper.cli.args[1]);
this.echo(new_status);
});
break;
default:
casper.echo("Неизвестный аргумент " + casper.cli.args[0]);
show_usage_and_exit();
}
// casper.then(function() {
// this.capture('3.png', {
// top: 100,
// left: 0,
// width: 600,
// height: 600
// });
//});
casper.run();