Created
March 12, 2018 14:19
-
-
Save ouoam/f0e65af6cff7933859e9627f73d9539a to your computer and use it in GitHub Desktop.
Program to check username and password with sgs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var querystring = require('querystring'); | |
| var http = require('http'); | |
| var sgs = {}; | |
| sgs.check = function (username, password, callback) { | |
| // Login html form data | |
| var post_data = querystring.stringify({ | |
| '__EVENTTARGET': 'ctl00$PageContent$OKButton$_Button', | |
| 'ctl00$PageContent$UserName': username, | |
| 'ctl00$PageContent$Password': password | |
| }); | |
| // Send request header | |
| var post_options = { | |
| host: 'sgs6.bopp-obec.info', | |
| port: '80', | |
| path: '/sgss/Security/SignIn.aspx', | |
| method: 'POST', | |
| headers: { | |
| 'User-Agent': 'Node/' + process.versions.node, | |
| 'Content-Type': 'application/x-www-form-urlencoded', | |
| 'Content-Length': Buffer.byteLength(post_data) | |
| } | |
| }; | |
| // Set up the request | |
| var post_req = http.request(post_options, function (res) { | |
| res.setEncoding('utf8'); | |
| sessionID = res.headers['set-cookie'][0].split('; ')[0].split('='); | |
| if (sessionID[0] == 'ASP.NET_SessionId') { | |
| callback(true); | |
| } else { | |
| callback(false); | |
| } | |
| }).on('error', function (e) { | |
| callback(false); | |
| }); | |
| // post the data | |
| post_req.write(post_data); | |
| post_req.end(); | |
| } | |
| module.exports = sgs; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment