-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_noip.js
More file actions
104 lines (97 loc) · 3.25 KB
/
update_noip.js
File metadata and controls
104 lines (97 loc) · 3.25 KB
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
var page = require('webpage').create();
var system = require('system');
var env = system.env;
page.onConsoleMessage = function(msg) {
system.stderr.writeLine('console: ' + msg);
};
console.log('The default user agent is ' + page.settings.userAgent);
if (env['NO_IP_USERNAME'] === undefined || env['NO_IP_USERNAME'] === null || env['NO_IP_USERNAME'] === ''){
console.log('no user name in env. variables, please define your user name in the ENV as NO_IP_USERNAME and rerun.')
phantom.exit();
}
if (env['NO_IP_PASSWORD'] === undefined || env['NO_IP_PASSWORD'] === null || env['NO_IP_PASSWORD'] === ''){
console.log('no password in env. variables, please define your password in the ENV as NO_IP_PASSWORD and rerun.')
phantom.exit();
}
page.settings.userAgent = 'SpecialAgent';
page.viewportSize = { width: 1920, height: 1080 };
console.log(new Date());
page.open('https://www.noip.com/login', function(status) {
if (status !== 'success') {
console.log('Unable to access network');
phantom.exit()
}else{
console.log("successfully opened the page")
runAutomation()
}
})
//login
function doLogin(){
var ua = page.evaluate(function(env) {
var form=document.querySelector('#clogs')
var name=form.querySelector('input:nth-child(1)')
var pass=form.querySelector('input:nth-child(2)')
var username = env['NO_IP_USERNAME']
var password = env['NO_IP_PASSWORD']
console.log('will be using user: ' + username + ' pass: ' + password)
if( form == null || form == undefined ){
console.log("could not find form")
phantom.exit()
}
if( name != undefined && name != null ){
name.value=username
}
if( pass != undefined && pass != null ){
pass.value=password;
}
form.submit()
return "logged in"
}, env);
console.log(ua)
}
function clickSelectorOrExit(selector, tag){
var result = page.evaluate(function(selector){
var domItem = document.querySelector(selector);
if( domItem != undefined && domItem != null ){
domItem.click();
return true;
}
return false;
}, selector);
if( ! result ){
console.error("failed to find selector: " + selector);
printScreenshot(true, tag);
}
}
function clickOnHost(){
clickSelectorOrExit('#content-wrapper > div.row > div.col-lg-8.col-md-8' +
'.col-sm-12 > div:nth-child(1) > div:nth-child(1) > div > div > div ' +
'> div > div > span.text-bg.text-success', 'host');
}
function clickOnModify(){
clickSelectorOrExit('#host-panel > table > tbody > tr > td.hidden-xs.' +
'clearfix > div > div', 'modity');
}
function clickOnUpdate(){
clickSelectorOrExit('#host-modal > div > div > div > div > div > form > div.panel-body > div.form-footer.text-right > span', 'update');
}
var printScreenshot=function(isExit, tag){
page.render('screenshot' + tag + '.jpg')
if( isExit === true ){
phantom.exit()
}
}
function runAutomation(){
doLogin()
setTimeout(function(){
clickOnHost()
setTimeout(function(){
clickOnModify()
setTimeout(function(){
clickOnUpdate()
console.log("success!")
phantom.exit()
},2000)
},5000)
}, 10000)
}