UNPKG

netsoul

Version:

netsoul protocol library

2 lines (1 loc) 19.8 kB
(function(){var a=function(e,g){var b=a.resolve(e,g||"/");var d=a.modules[b];if(!d){throw new Error("Failed to resolve module "+e+", tried "+b)}var f=a.cache[b];var c=f?f.exports:d();return c};a.paths=[];a.modules={};a.cache={};a.extensions=[".js",".coffee",".json"];a._core={assert:true,events:true,fs:true,path:true,vm:true};a.resolve=(function(){return function(i,h){if(!h){h="/"}if(a._core[i]){return i}var k=a.modules.path();h=k.resolve("/",h);var g=h||"/";if(i.match(/^(?:\.\.?\/|\/)/)){var d=j(k.resolve(g,i))||b(k.resolve(g,i));if(d){return d}}var c=e(i,g);if(c){return c}throw new Error("Cannot find module '"+i+"'");function j(l){l=k.normalize(l);if(a.modules[l]){return l}for(var m=0;m<a.extensions.length;m++){var n=a.extensions[m];if(a.modules[l+n]){return l+n}}}function b(o){o=o.replace(/\/+$/,"");var q=k.normalize(o+"/package.json");if(a.modules[q]){var p=a.modules[q]();var n=p.browserify;if(typeof n==="object"&&n.main){var l=j(k.resolve(o,n.main));if(l){return l}}else{if(typeof n==="string"){var l=j(k.resolve(o,n));if(l){return l}}else{if(p.main){var l=j(k.resolve(o,p.main));if(l){return l}}}}}return j(o+"/index")}function e(o,t){var r=f(t);for(var q=0;q<r.length;q++){var p=r[q];var l=j(p+"/"+o);if(l){return l}var s=b(p+"/"+o);if(s){return s}}var l=j(o);if(l){return l}}function f(p){var o;if(p==="/"){o=[""]}else{o=k.normalize(p).split("/")}var n=[];for(var m=o.length-1;m>=0;m--){if(o[m]==="node_modules"){continue}var l=o.slice(0,m+1).join("/")+"/node_modules";n.push(l)}return n}}})();a.alias=function(h,j){var m=a.modules.path();var e=null;try{e=a.resolve(h+"/package.json","/")}catch(b){e=a.resolve(h,"/")}var g=m.dirname(e);var l=(Object.keys||function(n){var i=[];for(var f in n){i.push(f)}return i})(a.modules);for(var c=0;c<l.length;c++){var k=l[c];if(k.slice(0,g.length+1)===g+"/"){var d=k.slice(g.length);a.modules[j+d]=a.modules[g+d]}else{if(k===g){a.modules[j]=a.modules[g]}}}};(function(){var d={};var c=typeof window!=="undefined"?window:{};var b=false;a.define=function(f,h){if(!b&&a.modules.__browserify_process){d=a.modules.__browserify_process();b=true}var i=a._core[f]?"":a.modules.path().dirname(f);var g=function(j){var l=a(j,i);var k=a.cache[a.resolve(j,i)];if(k&&k.parent===null){k.parent=e}return l};g.resolve=function(j){return a.resolve(j,i)};g.modules=a.modules;g.define=a.define;g.cache=a.cache;var e={id:f,filename:f,exports:{},loaded:false,parent:null};a.modules[f]=function(){a.cache[f]=e;h.call(e.exports,g,e,e.exports,i,f,d,c);e.loaded=true;return e.exports}}})();a.define("path",function(h,g,j,k,i,d,e){function f(l,o){var n=[];for(var m=0;m<l.length;m++){if(o(l[m],m,l)){n.push(l[m])}}return n}function b(p,m){var l=0;for(var n=p.length;n>=0;n--){var o=p[n];if(o=="."){p.splice(n,1)}else{if(o===".."){p.splice(n,1);l++}else{if(l){p.splice(n,1);l--}}}}if(m){for(;l--;l){p.unshift("..")}}return p}var c=/^(.+\/(?!$)|\/)?((?:.+?)?(\.[^.]*)?)$/;j.resolve=function(){var n="",l=false;for(var m=arguments.length;m>=-1&&!l;m--){var o=(m>=0)?arguments[m]:d.cwd();if(typeof o!=="string"||!o){continue}n=o+"/"+n;l=o.charAt(0)==="/"}n=b(f(n.split("/"),function(q){return !!q}),!l).join("/");return((l?"/":"")+n)||"."};j.normalize=function(n){var m=n.charAt(0)==="/",l=n.slice(-1)==="/";n=b(f(n.split("/"),function(o){return !!o}),!m).join("/");if(!n&&!m){n="."}if(n&&l){n+="/"}return(m?"/":"")+n};j.join=function(){var l=Array.prototype.slice.call(arguments,0);return j.normalize(f(l,function(n,m){return n&&typeof n==="string"}).join("/"))};j.dirname=function(n){var m=c.exec(n)[1]||"";var l=false;if(!m){return"."}else{if(m.length===1||(l&&m.length<=3&&m.charAt(1)===":")){return m}else{return m.substring(0,m.length-1)}}};j.basename=function(n,l){var m=c.exec(n)[2]||"";if(l&&m.substr(-1*l.length)===l){m=m.substr(0,m.length-l.length)}return m};j.extname=function(l){return c.exec(l)[3]||""}});a.define("__browserify_process",function(c,d,b,g,e,h,f){var h=d.exports={};h.nextTick=(function(){var j=typeof window!=="undefined"&&window.setImmediate;var l=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(j){return function(m){return window.setImmediate(m)}}if(l){var i=[];window.addEventListener("message",function(n){if(n.source===window&&n.data==="browserify-tick"){n.stopPropagation();if(i.length>0){var m=i.shift();m()}}},true);return function k(m){i.push(m);window.postMessage("browserify-tick","*")}}return function k(m){setTimeout(m,0)}})();h.title="browser";h.browser=true;h.env={};h.argv=[];h.binding=function(i){if(i==="evals"){return(c)("vm")}else{throw new Error("No such module. (Possibly not yet loaded)")}};(function(){var i="/";var j;h.cwd=function(){return i};h.chdir=function(k){if(!j){j=c("path")}i=j.resolve(k,i)}})()});a.define("/connects.coffee",function(c,d,b,g,e,h,f){(function(){var l,k,i,r,q,p,n=function(s,t){return function(){return s.apply(t,arguments)}},o={}.hasOwnProperty,j=function(v,t){for(var s in t){if(o.call(t,s)){v[s]=t[s]}}function u(){this.constructor=v}u.prototype=t.prototype;v.prototype=new u();v.__super__=t.prototype;return v},m=[].slice;q=c("./protocol");p=c("./utils");l=(function(s){j(t,s);function t(u){this.options=u!=null?u:{};this.connect=n(this.connect,this);this.handleOptions=n(this.handleOptions,this);this.verbose=n(this.verbose,this);this.debug=n(this.debug,this);this.connected=false;this.handleOptions();this.debug("ConnectBase::constructor");t.__super__.constructor.call(this,this.options)}t.prototype.debug=function(){var u,v;u=1<=arguments.length?m.call(arguments,0):[];if(this.options.debug){return(v=this.options).logFn.apply(v,[""+this.constructor.name+"> "].concat(m.call(u)))}};t.prototype.verbose=function(){var u,v;u=1<=arguments.length?m.call(arguments,0):[];if(this.options.verbose){return(v=this.options).logFn.apply(v,[""+this.constructor.name+"> "].concat(m.call(u)))}};t.prototype.handleOptions=function(){var w,x,v,y,u,z;if((y=(w=this.options).logFn)==null){w.logFn=console.log}if((u=(x=this.options).verbose)==null){x.verbose=false}if((z=(v=this.options).debug)==null){v.debug=false}return this.debug("handleOptions")};t.prototype.connect=function(){if(!(this.socket!=null)){throw new Error("socket does not exists")}};return t})(p.PubSub);k=(function(t){j(s,t);function s(){this.onError=n(this.onError,this);this.onClose=n(this.onClose,this);this.onDisconnect=n(this.onDisconnect,this);this.handleLine=n(this.handleLine,this);this.onBuffer=n(this.onBuffer,this);this.onConnect=n(this.onConnect,this);this.disconnect=n(this.disconnect,this);this.send=n(this.send,this);this.connect=n(this.connect,this);return s.__super__.constructor.apply(this,arguments)}s.prototype.connect=function(){this.debug("ConnectNet::connect");s.__super__.connect.apply(this,arguments);this.socket.on("connect",this.onConnect);this.socket.on("data",this.onBuffer);this.socket.on("end",this.onDisconnect);this.socket.on("error",this.onError);return this.socket.on("close",this.onClose)};s.prototype.send=function(v,u,x){var w;if(u==null){u=null}if(x==null){x=null}if(typeof v==="string"){w=""+v+"\r\n"}else{w=v.join(" ")+"\r\n"}return this.socket.write(w,u,x)};s.prototype.disconnect=function(){this.socket.end();return this.onDisconnect()};s.prototype.onConnect=function(){this.connected=true;this.debug("ConnectNet::onConnect");return this.emit("connect")};s.prototype.onBuffer=function(x){var w,z,v,y,u;this.debug("ConnectNet::onBuffer",x);this.emit("buffer",x);y=x.toString().split("\n");u=[];for(z=0,v=y.length;z<v;z++){w=y[z];u.push(this.handleLine(w))}return u};s.prototype.handleLine=function(u){var v;u=u.replace(/^\s+|\s+$/g,"");if(!u.length){return false}this.debug("ConnectNet::handleLine",u);v=q.prototype.parseData(u);this.debug("protocol::parseData",v);this.emit("data",u);return this.emit("message",v)};s.prototype.onDisconnect=function(){this.debug("ConnectNet::onDisconnect");this.connected=false;return this.emit("disconnect")};s.prototype.onClose=function(){this.debug("ConnectNet::onClose");this.connected=false;return this.emit("disconnect")};s.prototype.onError=function(u){this.debug("ConnectNet::onError",u);return this.emit("error",u)};return s})(l);i=(function(t){j(s,t);function s(){this.connect=n(this.connect,this);this.handleOptions=n(this.handleOptions,this);return s.__super__.constructor.apply(this,arguments)}s.prototype.handleOptions=function(){var w,x,v,y,u,z;s.__super__.handleOptions.apply(this,arguments);if((y=(w=this.options).host)==null){w.host="ns-server.epitech.net"}if((u=(x=this.options).port)==null){x.port=4242}return(z=(v=this.options).localAddress)!=null?z:v.localAddress="0.0.0.0"};s.prototype.connect=function(){this.debug("ConnectTCP::connect");this.verbose("Connecting to "+this.options.host+":"+this.options.port+"...");this.socket=c("net").connect({port:this.options.port,host:this.options.host,localAddress:this.options.localAddress});return s.__super__.connect.apply(this,arguments)};return s})(k);r=(function(t){j(s,t);function s(){this.connect=n(this.connect,this);this.handleOptions=n(this.handleOptions,this);return s.__super__.constructor.apply(this,arguments)}s.prototype.handleOptions=function(){s.__super__.handleOptions.apply(this,arguments);if(!(this.options.path!=null)){throw new Error("unix socket not specified")}};s.prototype.connect=function(){this.debug("ConnectUnixSocket::connect");this.verbose("Connecting to "+this.options.path+"...");this.socket=c("net").connect({path:this.options.path});return s.__super__.connect.apply(this,arguments)};return s})(k);d.exports={unixSocket:r,tcp:i,net:k,base:l}}).call(this)});a.define("/protocol.coffee",function(c,d,b,g,e,h,f){(function(){var i,j;i=(function(){function k(){}k.prototype.data="";k.prototype.split=[];k.prototype.debug=function(l){if(l==null){l=console.dir}return l({data:this.data,split:this.split})};return k})();j=(function(){function k(){}k.prototype.parseData=function(l){var m,n;m=new i;m.line=l;m.split=l.split(" ");if((n=m.split[0])==="salut"||n==="ping"||n==="rep"){m.type=m.split[0]}return m};return k})();d.exports=j;d.exports.Message=i}).call(this)});a.define("/utils.coffee",function(c,d,b,g,e,h,f){(function(){var i,j=function(l,m){return function(){return l.apply(m,arguments)}},k=[].slice;i=(function(){function l(){this.emit=j(this.emit,this);this.on=j(this.on,this);this.subs={}}l.prototype.on=function(m,o,n){if(n==null){n=null}if(!(this.subs[m]!=null)){this.subs[m]=[]}return this.subs[m].push({callback:o,id:n})};l.prototype.emit=function(){var o,q,p,s,n,r,m;q=arguments[0],o=2<=arguments.length?k.call(arguments,1):[];if(!(this.subs[q]!=null)){return false}r=this.subs[q];m=[];for(s=0,n=r.length;s<n;s++){p=r[s];m.push(p.callback.apply(p,o))}return m};return l})();d.exports={PubSub:i}}).call(this)});a.define("net",function(c,d,b,g,e,h,f){});a.define("/clients.coffee",function(c,d,b,g,e,h,f){(function(){var m,k,n,i,r,q,o=function(s,t){return function(){return s.apply(t,arguments)}},p={}.hasOwnProperty,j=function(v,t){for(var s in t){if(p.call(t,s)){v[s]=t[s]}}function u(){this.constructor=v}u.prototype=t.prototype;v.prototype=new u();v.__super__=t.prototype;return v},l=[].slice;r=c("./protocol");q=c("./utils");i=c("crypto");k=(function(t){j(s,t);function s(u){this.options=u!=null?u:{};this.onConnect=o(this.onConnect,this);this.onError=o(this.onError,this);this.onMessage=o(this.onMessage,this);this.onDisconnect=o(this.onDisconnect,this);this.send=o(this.send,this);this.connect=o(this.connect,this);this.setupConnect=o(this.setupConnect,this);this.setupClient=o(this.setupClient,this);this.handleOptions=o(this.handleOptions,this);this.verbose=o(this.verbose,this);this.debug=o(this.debug,this);s.__super__.constructor.apply(this,arguments);this.handleOptions();this.debug("ClientBase::constructor");this.setupConnect();this.setupClient()}s.prototype.debug=function(){var u,v;u=1<=arguments.length?l.call(arguments,0):[];if(this.options.debug){return(v=this.options).logFn.apply(v,[""+this.constructor.name+"> "].concat(l.call(u)))}};s.prototype.verbose=function(){var u,v;u=1<=arguments.length?l.call(arguments,0):[];if(this.options.verbose){return(v=this.options).logFn.apply(v,[""+this.constructor.name+"> "].concat(l.call(u)))}};s.prototype.handleOptions=function(){var C,v,u,F,E,D,B,A,z,y,x,w;if((B=(C=this.options).logFn)==null){C.logFn=console.log}if((A=(v=this.options).verbose)==null){v.verbose=false}if((z=(u=this.options).debug)==null){u.debug=false}if((y=(F=this.options).login)==null){F.login=h.env.USER}if((x=(E=this.options).location)==null){E.location="-"}if((w=(D=this.options).agent)==null){D.agent="node-netsoul"}if(!(this.options.password!=null)){throw new Error("password is not specified")}if(!(this.options.nsconnect!=null)){throw new Error("nsconnect is not specified")}this.ns=this.options.nsconnect;return this.debug("ClientBase::handleOptions",this.options)};s.prototype.setupClient=function(){return this.debug("ClientBase::setupClient")};s.prototype.setupConnect=function(){this.debug("ClientBase::setup");this.ns.on("connect",this.onConnect);this.ns.on("message",this.onMessage);this.ns.on("error",this.onError);return this.ns.on("disconnect",this.onDisconnect)};s.prototype.connect=function(){this.debug("ClientBase::connect");return this.ns.connect()};s.prototype.send=function(u){this.verbose("ClientBase::send",u.join(" "));return this.ns.send(u)};s.prototype.onDisconnect=function(){return this.debug("ClientBase::onDisconnect")};s.prototype.onMessage=function(v){var u;this.verbose("ClientBase::onMessage",v.line);if(v.type!=null){u="message_"+v.type;this.debug("ClientBase::onMessage, type="+u);this.emit(u,v);if(this[u]!=null){return this[u](v)}}};s.prototype.onError=function(u){return this.debug("ClientBase::onError",u)};s.prototype.onConnect=function(){return this.debug("ClientBase::onConnect")};return s})(q.PubSub);m=(function(t){j(s,t);function s(){this.message_ping=o(this.message_ping,this);this.handshakeAccepted=o(this.handshakeAccepted,this);this.readyForHandshake=o(this.readyForHandshake,this);this.message_rep=o(this.message_rep,this);this.message_salut=o(this.message_salut,this);this.setupClient=o(this.setupClient,this);return s.__super__.constructor.apply(this,arguments)}s.prototype.setupClient=function(){s.__super__.setupClient.apply(this,arguments);this.debug("ClientAuth::setupClient");this.authenticated=false;return this.auth_step=0};s.prototype.message_salut=function(u){this.debug("ClientAuth::message_salut",u.line);this.handshake=u.split;return this.send(["auth_ag","ext_user","none","none"])};s.prototype.message_rep=function(v){var u;u=v.split[1];if(!this.authenticated){if(this.auth_step===0){this.readyForHandshake()}if(this.auth_step===1){this.handshakeAccepted()}return this.auth_step++}};s.prototype.readyForHandshake=function(){var w,y,x,u,v;y=""+this.handshake[2]+"-"+this.handshake[3]+"/"+this.handshake[4]+this.options.password;v=this.options.login;x=i.createHash("md5").update(y).digest("hex");w=encodeURIComponent(this.options.agent);u=encodeURIComponent(this.options.location);this.debug("ClientAuth::message_salut","login="+v+", concat="+y+", hash="+x+", location="+u+", agent="+w);return this.send(["ext_user_log",v,x,w,u])};s.prototype.handshakeAccepted=function(){this.debug("ClientAuth::handshakeAccepted");this.authenticated=true;return this.emit("authenticate")};s.prototype.message_ping=function(u){this.debug("ClientAuth::message_pong",u);return this.send(u.split)};return s})(k);n=(function(t){j(s,t);function s(){return s.__super__.constructor.apply(this,arguments)}s.prototype.setupClient=function(){var u=this;s.__super__.setupClient.apply(this,arguments);this.debug("ClientDaemon::setupClient");return this.on("authenticate",function(){return u.send(["user_cmd","state","actif"])})};return s})(m);d.exports={base:k,auth:m,daemon:n}}).call(this)});a.define("crypto",function(c,d,b,g,e,h,f){d.exports=c("crypto-browserify")});a.define("/node_modules/crypto-browserify/package.json",function(c,d,b,g,e,h,f){d.exports={}});a.define("/node_modules/crypto-browserify/index.js",function(f,e,h,i,g,c,d){var j=f("./sha");var b=f("./rng");var k={sha1:{hex:j.hex_sha1,binary:j.b64_sha1,ascii:j.str_sha1}};function l(){var n=[].slice.call(arguments).join(" ");throw new Error([n,"we accept pull requests","http://github.com/dominictarr/crypto-browserify"].join("\n"))}h.createHash=function(o){o=o||"sha1";if(!k[o]){l("algorithm:",o,"is not yet supported")}var n="";var m=k[o];return{update:function(p){n+=p;return this},digest:function(p){p=p||"binary";var q;if(!(q=m[p])){l("encoding:",p,"is not yet supported for algorithm",o)}var s=q(n);n=null;return s}}};h.randomBytes=function(m,o){if(o&&o.call){try{o.call(this,undefined,b(m))}catch(n){o(n)}}else{return b(m)}};["createCredentials","createHmac","createCypher","createCypheriv","createDecipher","createDecipheriv","createSign","createVerify","createDeffieHellman","pbkdf2"].forEach(function(m){h[m]=function(){l("sorry,",m,"is not implemented yet")}})});a.define("/node_modules/crypto-browserify/sha.js",function(k,c,B,A,w,s,u){B.hex_sha1=m;B.b64_sha1=j;B.str_sha1=f;B.hex_hmac_sha1=d;B.b64_hmac_sha1=i;B.str_hmac_sha1=o;var r=0;var z="";var e=8;function m(C){return l(g(y(C),C.length*e))}function j(C){return p(g(y(C),C.length*e))}function f(C){return v(g(y(C),C.length*e))}function d(C,D){return l(h(C,D))}function i(C,D){return p(h(C,D))}function o(C,D){return v(h(C,D))}function b(){return m("abc")=="a9993e364706816aba3e25717850c26c9cd0d89d"}function g(P,J){P[J>>5]|=128<<(24-J%32);P[((J+64>>9)<<4)+15]=J;var Q=Array(80);var O=1732584193;var N=-271733879;var M=-1732584194;var L=271733878;var K=-1009589776;for(var G=0;G<P.length;G+=16){var I=O;var H=N;var F=M;var E=L;var C=K;for(var D=0;D<80;D++){if(D<16){Q[D]=P[G+D]}else{Q[D]=q(Q[D-3]^Q[D-8]^Q[D-14]^Q[D-16],1)}var R=t(t(q(O,5),x(D,N,M,L)),t(t(K,Q[D]),n(D)));K=L;L=M;M=q(N,30);N=O;O=R}O=t(O,I);N=t(N,H);M=t(M,F);L=t(L,E);K=t(K,C)}return Array(O,N,M,L,K)}function x(D,C,F,E){if(D<20){return(C&F)|((~C)&E)}if(D<40){return C^F^E}if(D<60){return(C&F)|(C&E)|(F&E)}return C^F^E}function n(C){return(C<20)?1518500249:(C<40)?1859775393:(C<60)?-1894007588:-899497514}function h(E,H){var G=y(E);if(G.length>16){G=g(G,E.length*e)}var C=Array(16),F=Array(16);for(var D=0;D<16;D++){C[D]=G[D]^909522486;F[D]=G[D]^1549556828}var I=g(C.concat(y(H)),512+H.length*e);return g(F.concat(I),512+160)}function t(C,F){var E=(C&65535)+(F&65535);var D=(C>>16)+(F>>16)+(E>>16);return(D<<16)|(E&65535)}function q(C,D){return(C<<D)|(C>>>(32-D))}function y(F){var E=Array();var C=(1<<e)-1;for(var D=0;D<F.length*e;D+=e){E[D>>5]|=(F.charCodeAt(D/e)&C)<<(32-e-D%32)}return E}function v(E){var F="";var C=(1<<e)-1;for(var D=0;D<E.length*32;D+=e){F+=String.fromCharCode((E[D>>5]>>>(32-e-D%32))&C)}return F}function l(E){var D=r?"0123456789ABCDEF":"0123456789abcdef";var F="";for(var C=0;C<E.length*4;C++){F+=D.charAt((E[C>>2]>>((3-C%4)*8+4))&15)+D.charAt((E[C>>2]>>((3-C%4)*8))&15)}return F}function p(F){var E="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var H="";for(var D=0;D<F.length*4;D+=3){var G=(((F[D>>2]>>8*(3-D%4))&255)<<16)|(((F[D+1>>2]>>8*(3-(D+1)%4))&255)<<8)|((F[D+2>>2]>>8*(3-(D+2)%4))&255);for(var C=0;C<4;C++){if(D*8+C*6>F.length*32){H+=z}else{H+=E.charAt((G>>6*(3-C))&63)}}}return H}});a.define("/node_modules/crypto-browserify/rng.js",function(c,d,b,g,e,h,f){(function(){var l=this;var i,j;i=function(o){var m=new Array(o);var p;for(var n=0,p;n<o;n++){if((n&3)==0){p=Math.random()*4294967296}m[n]=p>>>((n&3)<<3)&255}return m};if(l.crypto&&crypto.getRandomValues){var k=new Uint32Array(4);j=function(n){var m=new Array(n);crypto.getRandomValues(k);for(var o=0;o<n;o++){m[o]=k[o>>2]>>>((o&3)*8)&255}return m}}d.exports=j||i}())});a.define("/browser.coffee",function(c,d,b,g,e,h,f){(function(){window.Netsoul={connects:c("./connects"),clients:c("./clients")}}).call(this)});a("/browser.coffee")})();