1
|
/* mandayejs - saml reverse proxy
|
2
|
* Copyright (C) 2015 Entr'ouvert
|
3
|
*
|
4
|
* This program is free software: you can redistribute it and/or modify it
|
5
|
* under the terms of the GNU Affero General Public License as published
|
6
|
* by the Free Software Foundation, either version 3 of the License, or
|
7
|
* (at your option) any later version.
|
8
|
*
|
9
|
* This program is distributed in the hope that it will be useful,
|
10
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
* GNU Affero General Public License for more details.
|
13
|
*
|
14
|
* You should have received a copy of the GNU Affero General Public License
|
15
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
16
|
*/
|
17
|
|
18
|
var page = require('webpage').create();
|
19
|
var system = require('system');
|
20
|
|
21
|
var input = JSON.parse(system.stdin.read(2000)); // no .readAll()...
|
22
|
|
23
|
headers_list = []
|
24
|
|
25
|
page.onResourceReceived = function(response){
|
26
|
for (var i=0; i < response.headers.length; i++){
|
27
|
var c_header = response.headers[i];
|
28
|
if (c_header['name'] === 'Set-Cookie'){
|
29
|
headers_list.push(c_header);
|
30
|
}
|
31
|
}
|
32
|
}
|
33
|
|
34
|
page.open(input.address, function() {
|
35
|
page.onLoadFinished = function() {
|
36
|
page.render('login.png');
|
37
|
console.log(JSON.stringify({'result': 'ok', 'cookies': page.cookies, 'headers': headers_list, 'url': page.frameUrl}));
|
38
|
phantom.exit();
|
39
|
}
|
40
|
page.injectJs('static/js/jquery.min.js');
|
41
|
page.evaluate(function(input) {
|
42
|
var locators = input.locators;
|
43
|
for ( var i=0; i < locators.length; i++ ) {
|
44
|
locator = locators[i];
|
45
|
for ( var key in locator ){
|
46
|
if (locator.hasOwnProperty(key)){
|
47
|
$(key).val(locator[key]);
|
48
|
}
|
49
|
}
|
50
|
}
|
51
|
$(key).parents('form').find('input[type=submit]').click();
|
52
|
}, input);
|
53
|
});
|