exports.createReport=function(b,c,a){return new Report(b,c,a)};var Report=function(e,i,l){var a=e.name,k=e.password,g=e.mrd,h=e.curPage,c={},b=[],i=i,j=true,f=0,o="wait",n=e.options||{};function d(q){if(q==null){return true}if(q.length>0){return false}if(q.length===0){return true}if(typeof q!=="object"){return true}for(var p in q){if(hasOwnProperty.call(q,p)){return false}}return true}this.reopenReport=function(p){g=p.mrd,h=p.curPage,b=[],f=0,o="wait",n=p.options||n};this.focusOnField=function(p,q){c[q]={formId:p.formId,fieldId:p.fieldId}};this.focusOutField=function(q){if(c[q]){var p={formId:c[q].formId,fieldId:c[q].fieldId};c[q]=undefined;return p}};var m=function(q){if(typeof q!=="string"||q.length==0){return}var p=q.substr(q.indexOf('path="')+6);return p.substr(0,p.indexOf('"'))};this.changeLock=function(p){j=p};this.changeLock=function(p){j=p};this.isLock=function(){return j};this.getName=function(){return a};this.getPassword=function(){return k};this.getMrd=function(){return g};this.getCurPage=function(){return h};this.setHostId=function(p){i=p};this.getHostId=function(){return i};this.syncDone=function(){++f};this.incSyncCnt=function(p){if(p){f+=p}else{++f}};this.decSyncCnt=function(){if(f>0){--f}};this.initSyncDoneCount=function(){f=0};this.getSyncDoneCount=function(){return f};this.setSyncState=function(p){o=p};this.getSyncState=function(){return o};this.setHostPage=function(p){h=p};this.getFocusInfo=function(r){if(r){var q={};for(var p in c){if(r!=c){q[p]=c[p]}}return q}return c};this.getOption=function(p){return n[p]};this.setOption=function(p,q){n[p]=q}};exports.createReportManager=function(b,a){return new ReportManager(b,a)};var ReportManager=function(c,a){var b=[];this.createReport=function(e,f){if(!this.getReport(e.name)){var d=exports.createReport(e,f,c);b.push(d);return d}};this.joinReport=function(e){var d=this.getReport(e.name);if(d){if(d.getPassword()&&d.getPassword()!=e.password){return"share_wrong_password"}return d}else{return"share_undefined_room"}};this.getReport=function(e){var d;b.some(function(f){if(e==f.getName()){d=f;return true}});return d};this.getReports=function(){return b};this.getReportList=function(){var d=b.sort(function(g,f){if(g.getName()f.getName()){return 1}return 0});var e=[];d.forEach(function(f){e.push({name:f.getName(),isPublic:!f.getPassword(),userCount:a.getUserCount(f.getName())})});return e};this.removeReport=function(d){b.some(function(e){if(e.getName()===d){b.splice(b.indexOf(e),1);return true}})}};exports.start=function(){process.on("uncaughtException",function(w){if(v){v.log("crit","[uncaughtException] "+w.stack)}else{console.log("[uncaughtException] "+w.stack)}});var c=require("fs");var t=require("v8");var e=require("os");var d=require("https");var f=require("socket.io");var o=exports.ConfigManager||require("./crownix-share-configManager.js").ConfigManager;var s=new o();var r=c.readdirSync("./").indexOf("crownix-share-logger.js")>=0?require("./crownix-share-logger.js"):require("./crownix-share-logger.min.js");var v=new r(s.getConfig("server.log"));var h=s.getConfig("server.port");var k=s.getConfig("server.ssl");var m={pingInterval:s.getConfig("server.opts.pingInterval"),pingTimeout:s.getConfig("server.opts.pingTimeout")};if(k!==undefined){var g={};if(k.key){g.key=c.readFileSync(k.key).toString()}if(k.cert){g.cert=c.readFileSync(k.cert).toString()}if(k.pfx){g.pfx=c.readFileSync(k.pfx).toString()}if(k.passphrase){g.passphrase=k.passphrase}var p=d.createServer(g,function(x,w){w.writeHead(200);w.end()});f=f(p,m);p.listen(h);console.log("Server Running at https://ServerURL:"+h)}else{f=f.listen(h,m);console.log("Server Running at http://ServerURL:"+h)}var l=Object.prototype.hasOwnProperty;v.log("info","[Server start] module load complete. Share Server start. \r\n Node.js Version:"+process.version+" \r\n OS type: "+e.type());var b=function(){this.getHeapUsage=function(){var w=t.getHeapStatistics();return((w.used_heap_size/w.total_heap_size)*100).toFixed(2)};this.getHeapProportion=function(){var w=t.getHeapStatistics();return((w.total_heap_size/w.heap_size_limit)*100).toFixed(2)}};var i=[];var u=s.getConfig("report.namespace");if(u.length===0){i.push(f.sockets)}else{u.forEach(function(w){i.push(f.of("/"+w))})}var a={getUserCount:function(x){var w=f.nsps;for(var y in w){var z=w[y].adapter.rooms[x];if(z){return z.length}}return 0}};var n=new b();var q=exports.createReportManager(v,a);var j=function(y){v.log("debug","[client connect] new client "+y.id+" connect.");var x,A="waiting";function w(C){y.leave(A);y.join(C);A=C}function B(){y.leave(A);y.join("waiting");A="waiting"}function z(C,D){return{mrd:C.getMrd(),pageNo:C.getCurPage(),formData:D.formData,focusInfo:C.getFocusInfo(y.id),noteData:D.noteData&&JSON.parse(D.noteData),isLock:C.isLock()}}y.join(A);y.emit("reportList",q.getReportList());y.on("createReport",function(E,C){var D=q.createReport(E,y.id);if(D){x=D;w(E.name);y.emit("startSharing","host");C({name:E.name,password:E.password});y.nsp.to("waiting").emit("newReport",{name:E.name,isPublic:!E.password});if(n.getHeapProportion()>95){v.log("warning","heap memory proportion: "+n.getHeapProportion()+"%. becoming closer to the heap size limit.")}v.log("info","[create report] report created. \r\n name: "+E.name+" \r\n host: "+y.id+" \r\n type: "+(E.password?"private":"public"))}else{y.emit("shareError",{message:"share_duplicated_name"})}});y.on("reopenReport",function(C){x.reopenReport(C);y.nsp.sockets[x.getHostId()].emit("getFormData",undefined,function(D){y.broadcast.to(A).emit("openFile",z(x,D))});v.log("info","[reopen report] report reopened. \r\n report: "+x.getName()+" \r\n opener: "+y.id)});y.on("joinReport",function(E,C){var D=q.joinReport(E);if(D&&typeof D==="object"){x=D;if(!E.reconnect){y.nsp.to("waiting").emit("renewUserCount",{name:E.name,incCount:true})}y.nsp.sockets[x.getHostId()].emit("getFormData",undefined,function(F){y.emit("openFile",z(x,F));w(E.name);var G=E.isHost;if(G){x.setHostId(y.id)}y.emit("startSharing",G?"host":"client");C({name:E.name,password:E.password});v.log("info","[join report] client "+y.id+" join report: "+E.name)})}else{if(D&&typeof D==="string"){y.emit("shareError",{message:D})}}});y.on("formField",function(C){if(x){y.broadcast.to(A).emit("formField",C)}});y.on("focusOn",function(D){if(x){var C=x.focusOutField(y.id);if(C){y.broadcast.to(A).emit("focusOut",C)}x.focusOnField(D,y.id);D.isLock=x.isLock();y.broadcast.to(A).emit("focusOn",D)}});y.on("focusOut",function(){if(x){var C=x.focusOutField(y.id);if(C){y.broadcast.to(A).emit("focusOut",C)}}});y.on("lockFields",function(){if(!x.isLock()){x.changeLock(true);y.broadcast.to(A).emit("lockFields");y.broadcast.to(A).emit("movePage",x.getCurPage())}});y.on("unlockFields",function(){if(x.isLock()){x.changeLock(false);y.broadcast.to(A).emit("unlockFields")}});y.on("submitRequest",function(G,D){v.log("info","[submit request] client "+y.id+" request for submit. \r\n report: "+x.getName());var F=x.getSyncState();if(F==="synchronization"||F==="done"){return}x.setSyncState("synchronization");var C=Object.keys(y.nsp.adapter.rooms[A].sockets);if(C.length===1||y.id==x.getHostId()){D("done");x.setSyncState("done");return}for(var E=0;E95){v.log("warning","heap memory proportion: "+n.getHeapProportion()+"%. becoming closer to the heap size limit.")}y.broadcast.to(A).emit("note",C)}});y.on("movePage",function(C){if(x){if(x.getOption("pageSync")){y.broadcast.to(A).emit("movePage",C.page);x.setHostPage(C.page)}else{if(C.isHost){if(x.isLock()){y.broadcast.to(A).emit("movePage",C.page)}x.setHostPage(C.page)}}}});y.on("isLock",function(C){if(!x.isLock()){C()}});y.on("error",function(C){throw new Error(C)});y.on("disconnect",function(D){v.log("debug","[client disconnect] client "+y.id+" disconnect. \r\n reason: "+D+" \r\n latest join: "+A);if(x&&a.getUserCount(A)===0){y.nsp.to("waiting").emit("removeReport",A);q.removeReport(A);v.log("info",'[destroy report] report "'+x.getName()+'" destroyed.')}else{if(x&&y.id===x.getHostId()){y.nsp.to(A).emit("hostDoesNotExist","share_stop_sharing");q.removeReport(A);return}if(x){var C=x.focusOutField(y.id);if(C){y.broadcast.to(A).emit("focusOut",C)}}y.nsp.to("waiting").emit("renewUserCount",{name:A,incCount:false})}});y.on("initFormField",function(C){y.broadcast.to(A).emit("initFormField",C)});y.on("reDrawPage",function(C){if(x){if(C.isHost){if(x.isLock()){y.broadcast.to(A).emit("reDrawPage")}}}});y.on("event",function(C){y.broadcast.to(A).emit("event",C)});y.on("requestFormData",function(){y.nsp.sockets[x.getHostId()].emit("getFormData",undefined,function(C){y.emit("responseFormData",z(x,C))})});y.on("drilldown",function(C){if(x){y.broadcast.to(A).emit("drilldown",C)}});y.on("startSync",function(){if(x&&x.getOption("useSync")){if(x.getSyncState()==="wait"){x.setSyncState("synchronization");y.nsp.to(A).emit("onOverlay")}x.incSyncCnt()}});y.on("endSync",function(){if(x&&x.getOption("useSync")){x.decSyncCnt();if(x.getSyncState()==="synchronization"&&x.getSyncDoneCount()===0){y.nsp.to(A).emit("offOverlay");x.setSyncState("wait")}}});y.on("validate",function(C){if(x){y.broadcast.to(A).emit("validate",C)}});y.on("changeSignValue",function(C){if(x){y.nsp.sockets[x.getHostId()].emit("displayOnSignMirrorView",C)}});y.on("signingControl",function(C){if(x){y.broadcast.to(A).emit("onSigning",C)}});y.on("sendMessage",function(C){if(x){y.broadcast.to(A).emit("getMessage",C);if(A!=="waiting"){y.nsp.to("waiting").emit("getMessage",C)}}});y.on("leaveReport",function(){B()})};i.forEach(function(w){w.on("connection",j)})};module.exports.ConfigManager=function(){var b=require("fs");var d=require("deep-extend");var c;var f;var a={server:{port:52280,opts:{pingInterval:60000,pingTimeout:210000},log:{level:"4",dir:"./logs",timestamp:"YYYY-MM-DD HH:mm:ss",maxFiles:"100"}},report:{namespace:[]}};try{f=JSON.parse(b.readFileSync("./config.json","utf-8"));c=d(a,f)}catch(g){console.log("Exception: "+g.message);c=a}this.getConfig=function(k){var e=k.split(".");var h=c;for(var j=0,l=e.length;j