]> git.0d.be Git - mandayejs.git/blob - do_login.js
add README file with sample apache configuration
[mandayejs.git] / do_login.js
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 page.open(input.address, function() {
24   page.onLoadFinished = function() {
25     console.log(JSON.stringify({'result': 'ok', 'cookies': page.cookies}));
26     phantom.exit();
27   }
28   page.evaluate(function(input) {
29     if ($(input.username_locator).length == 0) {
30       console.log(JSON.stringify({'result': 'ok', 'cookies': page.cookies}));
31       phantom.exit();
32     }
33     $(input.username_locator).val(input.username_value);
34     $(input.password_locator).val(input.password_value);
35     $(input.username_locator).parents('form').find('input[type=submit]').click();
36   }, input);
37 });