-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflyssh_svr_changer.js
71 lines (63 loc) · 1.87 KB
/
flyssh_svr_changer.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
var system = require("system")
var args = system.args
var username = args[1]
var password = args[2]
var productID = args[3]
var targetSvr = args[4]
if (args.length < 4){
console.log("usage: phatomjs path/to/script username password productID targetSvr")
console.log("eg. phantomjs test.js bob securitpass 987 02 ")
console.log("this will change bob's ssh product id 987 to 02.flyssh.net")
phantom.exit()
}
var page = require('webpage').create();
page.open('http://www.flyssh.net', function(status) {
page.evaluate(function(username,password) {
var txt = document.getElementsByName('username')[0]
txt.value = username
var pass = document.getElementsByName('password')[0]
pass.value = password
var form = document.getElementsByTagName("form")[0]
form.submit()
},username,password);
});
page.onLoadFinished = function(status){
title = page.evaluate(
function(status){
return document.title
}
)
console.log("page loaded: ",title)
if (title == "我的账户 - FlySSH") {
console.log("changing ssh server ... ",targetSvr)
page.open("https://buy.flyssh.net/clientarea.php?action=productdetails&id="+productID,function(){
// console.log(page.content)
page.evaluate(function(targetSvr){
var sel = document.getElementsByName("newsrv")[0]
var form = sel.form
var val = targetSvr
var opts = sel.options
var found = false
for(var opt, j = 0; opt = opts[j]; j++) {
if(opt.value == val) {
found = true
sel.selectedIndex = j;
break;
}
}
if (found){
form.submit()
}else{
console.log("can't find target server "+targetSvr+" please check the name and try again.")
phantom.exit()
}
},targetSvr)
})
page.onLoadFinished = null
}
}
page.onAlert = function (msg) {
console.log("page alert says:",msg)
console.log("Done")
phantom.exit()
}