Skip to content

Commit c83dc2c

Browse files
committed
some changes
filemanager can open jpg gif svg png mp3 mp4 filemanager can now zip backup and zip restore services on server (running in vm) remove of response.end can compile cs after enabled screen shot with ctrl+shift+p with cs enabled to configure cs go route '/cs/printscreen' or '/compiler/cs' bug on routes fixed( more than 3 folders)
1 parent 56de60d commit c83dc2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+2358
-472
lines changed

index.js

Lines changed: 99 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,81 +12,122 @@ for(i in toInclude) {
1212
mod[i] = require(toInclude[i]);
1313
}
1414

15+
if("services" in mod) { // DANGER DANGER DANGER
16+
console.log("----------------------------------------------------------------------------------------------------")
17+
console.log("SERVICES STARTED");
18+
console.log("----------------------------------------------------------------------------------------------------")
19+
mod.services.start();
20+
21+
}
1522

1623
var routesDirectory = { get : mod.torito.paths.server.routes.get, post : mod.torito.paths.server.routes.post, static : mod.torito.paths.server.routes.static };
1724

1825

1926
app = mod.express();
2027
mod.app = app;
21-
mod.session.reset();
2228
app.set("port",process.env.PORT || 3001);
29+
30+
31+
2332
function guid() {
2433
function s4() {
2534
return Math.floor((1 + Math.random()) * 0x10000) .toString(16) .substring(1);
2635
}
2736
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
2837
}
2938

30-
app.use(function (req, res, next) {
39+
app.use(function(req,res,next){
3140
console.log("------------------------------------------------------------------------------------------------");
3241
console.log('Request URL:', req.originalUrl,'Request Type:', req.method,'Request Params:', req.params,'Request Query:', req.query);
3342
console.log("------------------------------------------------------------------------------------------------");
34-
//mod.session.print();
35-
var found = false;
36-
//console.log(req.headers);
37-
if("cookie" in req.headers) {
38-
console.log("req.headers.cookie:",req.headers.cookie);
39-
req.cookies = mod.cookie.parse(req.headers.cookie);
40-
console.log("req.cookies:",req.cookies);
41-
if("session" in req.cookies) {
42-
var data = mod.session.get( req.cookies.session );
43-
if(data != null) {
44-
req.session = data;
45-
req.session.id = req.cookies.session;
46-
console.log("SESSION:",req.session.id);
47-
data.date = new Date();
48-
found = true;
43+
next();
44+
})
45+
46+
if("session" in mod) {
47+
mod.session.reset();
48+
app.use(function (req, res, next) {
49+
//mod.session.print();
50+
var found = false;
51+
//console.log(req.headers);
52+
if("cookie" in req.headers) {
53+
console.log("req.headers.cookie:",req.headers.cookie);
54+
req.cookies = mod.cookie.parse(req.headers.cookie);
55+
console.log("req.cookies:",req.cookies);
56+
if("session" in req.cookies) {
57+
var data = mod.session.get( req.cookies.session );
58+
if(data != null) {
59+
60+
var ip;
61+
if (req.headers['x-forwarded-for']) {
62+
ip = req.headers['x-forwarded-for'].split(",")[0];
63+
} else if (req.connection && req.connection.remoteAddress) {
64+
ip = req.connection.remoteAddress;
65+
} else {
66+
ip = req.ip;
67+
}
68+
req.session = data;
69+
if( req.session.ip == ip ) {
70+
// not found
71+
72+
req.session.id = req.cookies.session;
73+
console.log("SESSION:",req.session.id);
74+
//data.date = new Date();
75+
found = true;
76+
77+
}
78+
79+
}
4980
}
5081
}
51-
}
52-
if(!found) {
53-
// find a available id
54-
var id = guid();
55-
while(true) {
56-
var data = mod.session.get( id );
57-
if(data != null) {
58-
id = guid();
82+
if(!found) {
83+
// find a available id
84+
var id = guid();
85+
while(true) {
86+
var data = mod.session.get( id );
87+
if(data != null) {
88+
id = guid();
89+
} else {
90+
break;
91+
}
92+
}
93+
// create a new session
94+
95+
var ip;
96+
if (req.headers['x-forwarded-for']) {
97+
ip = req.headers['x-forwarded-for'].split(",")[0];
98+
} else if (req.connection && req.connection.remoteAddress) {
99+
ip = req.connection.remoteAddress;
59100
} else {
60-
break;
101+
ip = req.ip;
61102
}
62-
}
63-
// create a new session
64-
var session = {
65-
id : id,
66-
logged : false,
67-
date : new Date()
68-
};
69-
console.log("NEW SESSION:",id);
70-
var d1 = new Date (),
71-
d2 = new Date ( d1 );
72-
d2.setMinutes ( d1.getMinutes() + 60*24*365 );
73-
var d0 = new Date(0);
74-
mod.session.set(id,session);
75-
var cookie_str = mod.cookie.serialize("session",id,{
76-
httpOnly : true,
77-
path : "/",
78-
expires : d2,
79-
sameSite : true,
80-
SameSite : "strict"
81-
});
82-
console.log("cookie:",cookie_str);
83-
res.setHeader('Set-Cookie', cookie_str);
84-
req.session = session;
85-
}
86-
next();
87-
});
88103

104+
var session = {
105+
id : id,
106+
ip : ip,
107+
logged : false,
108+
date : new Date()
109+
};
110+
console.log("NEW SESSION:",id);
111+
var d1 = new Date (),
112+
d2 = new Date ( d1 );
113+
d2.setMinutes ( d1.getMinutes() + 60*24*365 );
114+
var d0 = new Date(0);
115+
mod.session.set(id,session);
116+
var cookie_str = mod.cookie.serialize("session",id,{
117+
httpOnly : true,
118+
path : "/",
119+
expires : d2,
120+
sameSite : true,
121+
SameSite : "strict"
122+
});
123+
console.log("cookie:",cookie_str);
124+
res.setHeader('Set-Cookie', cookie_str);
125+
req.session = session;
126+
}
127+
next();
128+
});
89129

130+
}
90131

91132

92133
var builtin = {
@@ -96,23 +137,28 @@ var builtin = {
96137
};
97138

98139
function readdirrecSync(dir,top) {
140+
99141
top = top || "";
100142
var files = mod.fs.readdirSync(dir);
101143
var ret = [];
102144
for(var x in files) {
103145
if( mod.fs.lstatSync(dir + "/" + files[x]).isDirectory() ) {
104-
var r = readdirrecSync(dir + "/" + files[x],files[x] + "/");
146+
var r = readdirrecSync(dir + "/" + files[x], top + files[x] + "/");
105147
ret = ret.concat(r);
148+
console.log("DIR:"+dir+" TOP:" + top, JSON.stringify(ret));
106149
} else {
107150
ret.push(top + files[x]);
151+
console.log("DIR:"+dir+" TOP:" + top, JSON.stringify(ret));
108152
}
109153
}
110154
return ret;
111155
}
112156
for(var dir in routesDirectory) {
157+
console.log("DIR:",routesDirectory[dir]);
113158
arrv = readdirrecSync(routesDirectory[dir]);
114159
for(var file in arrv) {
115160
if(dir == "get" || dir == "post") {
161+
console.log("@:",arrv[file]);
116162
if( arrv[file].lastIndexOf(".jsf") == arrv[file].length-4 ) {
117163
var name = arrv[file].substring(0,arrv[file].length-4);
118164
var names = name.split("/");

private/torito/client/root/default.css

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ body {
146146
left:0px;
147147
top:0px;
148148
}
149-
.menuRoutes , .menuFileManager, .menuAccounts {
149+
.menuRoutes , .menuFileManager, .menuAccounts, .menuServices {
150150
position:absolute;
151151
left:10px;
152152
top:70px;
@@ -155,20 +155,19 @@ body {
155155
width:230px;
156156
background-color:#777;
157157
}
158-
.menuRoutesTitle, .menuFilesTitle, .menuAccountsTitle {
158+
.menuRoutesTitle, .menuFilesTitle, .menuAccountsTitle, .menuServicesTitle {
159159
padding:10px;
160160
padding-left:5px;
161161
font-size:20px;
162162
background-color:#006;
163163
color:white;
164164
}
165-
.menuRoutesContents , .menuFilesContents, .menuAccountsContents{
165+
.menuRoutesContents , .menuFilesContents, .menuAccountsContents, .menuServicesContents{
166166
overflow:auto;
167167
width:230px;
168168
}
169169

170-
171-
.containerRoutesEditor, .containerFileManagerEditor, .containerAccountsEditor {
170+
.containerRoutesEditor, .containerFileManagerEditor, .containerAccountsEditor, .containerServicesEditor {
172171
position : absolute;
173172
left : 250px;
174173
top : 70px;

private/torito/client/root/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ webfile.import(__dirname + "/parts/AppAccounts.js","js");
2525
webfile.import(__dirname + "/parts/AppFileManager.js","js");
2626
webfile.import(__dirname + "/parts/AppLogout.js","js");
2727
webfile.import(__dirname + "/parts/AppRouter.js","js");
28-
webfile.import(__dirname + "/parts/AppTerminal.js","js");
28+
webfile.import(__dirname + "/parts/AppServices.js","js");
2929
webfile.import(__dirname + "/parts/AppNotes.js","js");
3030
webfile.import(__dirname + "/parts/Mask.js","js");
3131
webfile.import(__dirname + "/parts/ServerContainer.js","js");

private/torito/client/root/main.js

Lines changed: 96 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
UI.Body.canSelect(false);
2-
32
window.mousePos = { x : 0, y : 0 };
43
function handleMouseMove(event) {
54
var dot, eventDoc, doc, body, pageX, pageY;
@@ -22,17 +21,103 @@ function handleMouseMove(event) {
2221
//console.log(window.mousePos);
2322
}
2423
document.onmousemove = handleMouseMove;
25-
26-
/*
27-
setInterval(function() {
28-
Import({url:"/acl/ping",method:"post"})
29-
.done(function(data){
24+
window.torito = {
25+
tab : "",
26+
page : ""
27+
};
28+
UI.Window.Router.on("pageLoad",function(page,a) {
29+
//alert(History.getHash());
30+
window.torito.page = page;
31+
window.torito.date = new Date();
32+
Import({url:"/acl/tab/page",method:"post", data : { id : window.torito.tab , page : page, args : JSON.stringify(a) }})
33+
.done(function(data) {
3034
data = JSON.parse(data);
31-
if(!data.result) {
32-
window.location = "/logout";
35+
if(data.result) {
36+
console.log("logged on page : " + page + JSON.stringify(a));
37+
} else {
38+
console.log("123 @@@",data.code,window.torito.tab, name,JSON.stringify(data));
3339
}
3440
})
3541
.send();
36-
},1000);
37-
*/
38-
History.init("manage");
42+
});
43+
// request id for this tab
44+
Import({url:"/acl/tab/create",method:"post"})
45+
.done(function(data) {
46+
data = JSON.parse(data);
47+
if(data.result) {
48+
//data.value
49+
window.torito.tab = data.id;
50+
51+
52+
(function() {
53+
var hidden = "hidden";
54+
// Standards:
55+
if (hidden in document)
56+
document.addEventListener("visibilitychange", onchange);
57+
else if ((hidden = "mozHidden") in document)
58+
document.addEventListener("mozvisibilitychange", onchange);
59+
else if ((hidden = "webkitHidden") in document)
60+
document.addEventListener("webkitvisibilitychange", onchange);
61+
else if ((hidden = "msHidden") in document)
62+
document.addEventListener("msvisibilitychange", onchange);
63+
// IE 9 and lower:
64+
else if ("onfocusin" in document)
65+
document.onfocusin = document.onfocusout = onchange;
66+
// All others:
67+
else
68+
window.onpageshow = window.onpagehide
69+
= window.onfocus = window.onblur = onchange;
70+
71+
function onchange (evt) {
72+
var v = "visible", h = "hidden",
73+
evtMap = {
74+
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
75+
};
76+
77+
evt = evt || window.event;
78+
var s = "";
79+
if (evt.type in evtMap)
80+
s = evtMap[evt.type];
81+
else
82+
s = this[hidden] ? "hidden" : "visible";
83+
if(s == "visible") {
84+
setInterval(function() {
85+
/*
86+
Import({url:"/acl/ping",method:"post"})
87+
.done(function(data){
88+
data = JSON.parse(data);
89+
if(!data.result) {
90+
// window.location = "/logout"; (clear this when user got in unlogged state)
91+
} else {
92+
console.log("logged since:" + (data.value/1000) );
93+
}
94+
})
95+
.send();
96+
*/
97+
98+
},1000);
99+
console.log("visible");
100+
101+
} else {
102+
console.log("hidden");
103+
}
104+
}
105+
106+
// set the initial state (but only if browser supports the Page Visibility API)
107+
if( document[hidden] !== undefined )
108+
onchange({type: document[hidden] ? "blur" : "focus"});
109+
})();
110+
111+
112+
113+
History.init("manage");
114+
115+
116+
}
117+
})
118+
.send();
119+
120+
121+
122+
123+

private/torito/client/root/manage/load.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ if("system" in args) {
8484
}
8585
app.accounts.view = args.view;
8686
this.serverContainer.$.load(this.app,"accounts");
87+
} else if(args.system == "services") {
88+
89+
this.serverContainer.$.load(this.app,"services");
8790
} else if(args.system == "logout") {
8891
this.serverContainer.$.load(this.app,"logout");
8992
} else if(args.system == "notes") {

0 commit comments

Comments
 (0)