-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
63 lines (52 loc) · 1.41 KB
/
index.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
/**
PPP over XMPP (Jabber)
@author Andrey Nedobylsky
@git https://github.com/lailune/PPPoverXMPP
*/
var nodeTuntap = require('node-tuntap');
var Client = require('xmpp-client').Client;
/**
* Implements PPPoverXMPP object
*
* @param {{interface:string, ip: string, gateway: string, mask: string, login: string, password: string, gatewayContact:string, debug: boolean }} options
* @returns {PPPoverXMPP}
* @constructor
*/
function PPPoverXMPP(options) {
var that = this;
function log(message) {
if (typeof options.debug != 'undefined' && options.debug) {
console.log('PPPoXMPP: ' + message);
}
}
this.tuntap = nodeTuntap({
type: 'tun',
name: options.interface,
mtu: typeof options.mtu == 'undefined' ? 1500 : options.mtu,
addr: options.ip,
dest: options.gateway,
mask: options.mask,
ethtype_comp: 'none',
persist: false,
up: true,
running: true
});
this.client = new Client({
jid: options.login,
password: options.password
}, function () {
log("XMPP Connected");
that.tuntap.on('data', function (data) {
log('>>> Send packet');
that.client.message(options.gatewayContact, new Buffer(data).toString('base64'));
});
this.addListener('message', function (from, message) {
if (from.indexOf(options.gatewayContact) !== -1) {
log('<<< Recived packet');
that.tuntap.write(new Buffer(message, 'base64'));
}
});
});
return this;
}
module.exports = PPPoverXMPP;