Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Skripta za pošiljanje SMSov prek Klape iz Node.js
/*
Primer:
messagingSimobil = require('./messaging.js');
var username = "ime";
var password = "geslo";
var sms = new messagingSimobil.messagingSimobil(username, password);
sms.sendSMS('040xxxxxx', 'sporočilo', function(messages_left) {
console.log('yeah '+messages_left);
});
*/
var _username = '';
var _password = '';
var messagingSimobil = function(username, password) {
_username=username;
_password=password;
}
messagingSimobil.prototype.sendSMS = function(number, message, cb) {
var request = require('request');
var querystring = require("querystring");
var num = "386" + number.substring(1);
var j = request.jar();
var request = request.defaults({jar:j});
request('http://klapa.simobil.net/klapa/send.php', function(error, response, body) {
var cookie = response.headers["set-cookie"];
if (cookie) {
var regexState = /id=\"__VIEWSTATE\" value=\"(.*)\" \/>/;
var regexValidation = /id=\"__EVENTVALIDATION\" value=\"(.*)\" \/>/;
var state = body.match(regexState)[1];
var validation = body.match(regexValidation)[1];
var data = {'__EVENTTARGET': '',
'__EVENTARGUMENT': '',
'__VIEWSTATE': state,
'__VIEWSTATEENCRYPTED': '',
'__EVENTVALIDATION': validation,
'ctl00$ContentPlaceHolder$txtUsername': _username,
'ctl00$ContentPlaceHolder$txtPassword': _password,
'ctl00$ContentPlaceHolder$btnLogin': 'PRIJAVITE SE'
};
var path = response.request.uri.protocol+'//'+response.request.uri.host+response.request.uri.path;
request.post(path, {form: data}, function(error, response, body) {
var authTicket = body.match(/name=\"authTicket\" value=\"(.*)\"\/>/)[1];
if(authTicket) {
request.post('http://klapa.simobil.net/klapa/send_msg.php', {
form: {'authTicket': authTicket}
}, function(error, response, body) {
var data = {
'recipient': '',
'number.1001': num,
'text': message,
'js_enabled': 'true',
'sendit': 'true'
};
request.post('http://klapa.simobil.net/klapa/send_msg.php', {
form: data,
headers: {'referer': 'http://klapa.simobil.net/klapa/send.php'}
}, function(error, response, body) {
var left = body.match(/: ([0-9]?[0-9]?)<\/span>/);
if(left) {
cb(left[1]);
}else{
left(0);
}
});
});
}
});
}
});
}
module.exports.messagingSimobil = messagingSimobil;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment