connection and ping support

This commit is contained in:
Rodolphe Breard 2012-10-21 23:18:55 +02:00
parent 8f25b4c862
commit 11d236eb9f
2 changed files with 72 additions and 13 deletions

View file

@ -5,7 +5,7 @@ Chromesoul is a minimalist NetSoul client for Google Chrome. It aim to connect t
## Why? ## Why?
When you're on the PIE, you're stuck in it unless you are connected to netsoul, and with multiple boot and mobile devices it's a real pain to configure many NetSoul clients. That's why chromesoul is awesome: not only it's a multi-platforme NS client, but with the Chrome extension synchronisation it's automaticaly installed. When you're on the PIE, you're stuck in it unless you are connected to netsoul, and with multiple boot and mobile devices it's a real pain to configure many NetSoul clients. That's why chromesoul is awesome: not only it's a cross-platform NS client, but with the Chrome synchronisation it's automaticaly installed and configured.
## Requirements ## Requirements
@ -15,18 +15,18 @@ Sockets have been introduced in Chromium 24. Therefore, it is required to have a
## Features ## Features
### Active state
Staying in an active state is the main purpose of this extension. It will be implemented as soon as possible.
### Password encryption ### Password encryption
Storing your socks password encrypted is a priority but is not available yet. Yes, the chromesoul dev version is not secured; so is the official NetSoul server which doesn't store a hash but the password itself (it's a requirement from the NetSoul protocol). Storing your socks password encrypted is a priority but is not available yet. Yes, the chromesoul dev version is unsafe; so is the official NetSoul server which doesn't store a hash but the password itself (it's a requirement from the NetSoul protocol).
### Messages ### Messages
Because the only purpose of this extension is to provide an access to internet when you're on the PIE, there is no plan to support messages at this time. Thoses stupid guys who have fun spamming everyone by broadcasting messages are the second reasons why you won't see any message using chromesoul. Because the only purpose of this extension is to provide an access to internet when you're on the PIE, there is no plan to support messages at this time. Thoses stupid guys who have fun spamming everyone by broadcasting messages are the second reasons why you won't see any message using chromesoul. Maybe one day I'll write a chat interface, however it will be unobtrusive.
### Contacts ### Contacts
If you cannot send and receive messages, you don't need a contact list. If you cannot send and receive messages, you don't need a contact list.
### State change
Same as contacts. Why changing your state if you're not gonna talk?
## Licence ## Licence

View file

@ -19,20 +19,52 @@ var NsClient = function() {
this.state = "actif"; this.state = "actif";
this.allowed_statuses = ["actif", "away", "idle", "lock"]; this.allowed_statuses = ["actif", "away", "idle", "lock"];
this.is_connected = false; this.is_connected = false;
this.socket = null;
}; };
NsClient.prototype.connect = function() { NsClient.prototype.connect = function() {
var cnt = function(elem) { var cnt = function(elem) {
return function(infos) { return function(infos) {
if (typeof infos.login !== "undefined" && typeof infos.pwd_socks !== "undefined") { if (typeof infos.login !== "undefined" && typeof infos.pwd_socks !== "undefined") {
elem.is_connected = true; chrome.socket.create('tcp', {}, function(sock_inf) {
console.info("connected to the netsoul server"); elem.socket = sock_inf.socketId;
elem.updateStatus(); chrome.socket.connect(elem.socket, "ns-server.epita.fr", 4242, function(res) {
chrome.socket.read(elem.socket, null, function(rd_inf) {
if (rd_inf.resultCode > 0) {
var data = ab2str(rd_inf.data).split(' '),
auth = "ext_user_log ";
auth += infos.login + " ";
auth += hex_md5(data[2] + "-" + data[3] + "/" + data[4] + infos.pwd_socks) + " ";
auth += "chromesoul chromesoul\n";
console.log("recv: " + ab2str(rd_inf.data));
console.log("sent: auth_ag ext_user none none\n");
chrome.socket.write(elem.socket, str2ab("auth_ag ext_user none none\n"), function(w_inf) {
chrome.socket.read(elem.socket, null, function(rd_inf) {
if (rd_inf.resultCode > 0) {
console.log("recv: " + ab2str(rd_inf.data));
console.log("sent: " + auth);
chrome.socket.write(elem.socket, str2ab(auth), function(w_inf) {
chrome.socket.read(elem.socket, null, function(rd_inf) {
if (rd_inf.resultCode > 0) {
console.log("recv: " + ab2str(rd_inf.data));
elem.is_connected = true;
console.info("connected to the netsoul server");
elem.updateStatus();
elem.daemonize();
}
});
});
}
});
});
}
});
});
});
} }
}; };
}; };
console.log('connecting...');
if (!this.is_connected) { if (!this.is_connected) {
this.storage.get(null, cnt(this)); this.storage.get(null, cnt(this));
} else { } else {
@ -42,9 +74,32 @@ NsClient.prototype.connect = function() {
NsClient.prototype.disconnect = function() { NsClient.prototype.disconnect = function() {
if (this.is_connected) { if (this.is_connected) {
chrome.socket.disconnect(this.socket);
this.is_connected = false; this.is_connected = false;
console.info("disconnected"); console.info("disconnected");
this.updateStatus(); } else {
console.warn("not connected");
}
};
NsClient.prototype.daemonize = function() {
var dm = function(elem) {
return function(rd_inf) {
if (rd_inf.resultCode > 0) {
var data = ab2str(rd_inf.data);
console.log("- recv: " + data);
if (data.substr(0, 5) === "ping ") {
console.log("- sent: " + data);
chrome.socket.write(elem.socket, rd_inf.data, function(w_inf) {
chrome.socket.read(elem.socket, null, this);
});
}
}
};
};
if (this.is_connected) {
chrome.socket.read(this.socket, null, dm(this));
} else { } else {
console.warn("not connected"); console.warn("not connected");
} }
@ -52,7 +107,11 @@ NsClient.prototype.disconnect = function() {
NsClient.prototype.updateStatus = function() { NsClient.prototype.updateStatus = function() {
if (this.is_connected) { if (this.is_connected) {
console.info("updating status"); var status_msg = "user_cmd state ";
status_msg += this.state + ":";
status_msg += Math.round(new Date().getTime() / 1000) + "\n";
console.log("+send: " + status_msg);
chrome.socket.write(this.socket, str2ab(status_msg), function(w_inf) {});
} else { } else {
console.warn("not connected"); console.warn("not connected");
} }
@ -94,6 +153,6 @@ NsClient.prototype.init = function() {
}; };
con(this).apply(); con(this).apply();
setInterval(con(this), 60000); setInterval(con(this), 10000);
setInterval(upd(this), 600000); setInterval(upd(this), 600000);
}; };