diff --git a/db.js b/db.js
index a0abcae..f3d9a03 100644
--- a/db.js
+++ b/db.js
@@ -2,7 +2,7 @@ const mysql = require('mysql');
const vars = require('./vars');
const logcon = mysql.createConnection({
- host: 'localhost',
+ host: 'db',
user: 'user',
password: 'user',
database: 'users'
diff --git a/func.js b/func.js
index 26243d7..b5d5a12 100644
--- a/func.js
+++ b/func.js
@@ -24,29 +24,29 @@ module.exports.sendfile = (fileName, response) => {
});
}
-module.exports.check_sid = (Cookies, callback) =>{
- let uuid = Cookies["uuid"];
- let sid = Cookies["sid"];
- // console.log(uuid,sid);
- db.gv("users","uuid",`'${uuid}'`,(udata)=>{ udata = udata[0];
- // console.log(udata);
- db.gv("sids","uid",udata["id"],(rdata)=>{
- let valid = "";
- rdata.forEach(rec => {
- if (rec["sid"] == sid){
- valid = rec["sid"];
- return;
- }
- });
- if(valid != ""){
- callback(true,udata);
- }
- else{
- callback(false,udata);
- }
- });
- })
-}
+// module.exports.check_sid = (Cookies, callback) =>{
+// let uuid = Cookies["uuid"];
+// let sid = Cookies["sid"];
+// // console.log(uuid,sid);
+// db.gv("users","uuid",`'${uuid}'`,(udata)=>{ udata = udata[0];
+// // console.log(udata);
+// db.gv("sids","uid",udata["id"],(rdata)=>{
+// let valid = "";
+// rdata.forEach(rec => {
+// if (rec["sid"] == sid){
+// valid = rec["sid"];
+// return;
+// }
+// });
+// if(valid != ""){
+// callback(true,udata);
+// }
+// else{
+// callback(false,udata);
+// }
+// });
+// })
+// }
module.exports.sid = (cook,res,callback,auto = true)=>{
let uuid = cook["uuid"];
@@ -61,24 +61,26 @@ module.exports.sid = (cook,res,callback,auto = true)=>{
}
else{
if(auto) res.send({out:"bad",err:"wrong"});
- callback(false);
+ if(!auto) callback(false);
}
});
}
else{
if(auto) res.send({out:"bad",err:"expired"});
- callback(false);
+ if(!auto) callback(false);
}
});
}else{
if(auto) res.send({out:"bad",err:"nocr"});
- callback(false);
+ if(!auto) callback(false);
}
}
-module.exports.log = (comment) =>{
- var date = moment().format('YYYY-MM-DD_hh:mm')
- console.log(`${date}|${comment}`);
+module.exports.log = (message) =>{
+ var date = moment().format('YYYY-MM-DD')
+ var time = moment().format('hh:mm:ss')
+ console.log(`${date}_${time}|${message}`);
+ db.nr("logs","`date`,`time`,`log`",`'${date}','${time}','${message}'`);
}
@@ -87,13 +89,13 @@ module.exports.get_uuid = () =>{
return unid;
}
-module.exports.encrypt = (password,uuid) => {
+module.exports.encrypt = (text,cipher) => {
// return bcrypt.hashSync(password,bcrypt.genSaltSync());
- return cryptojs.AES.encrypt(password,uuid).toString();
+ return cryptojs.AES.encrypt(text,cipher).toString();
}
-module.exports.decrypt = (password,uuid) =>{
- const en = cryptojs.AES.decrypt(password,uuid);
+module.exports.decrypt = (text,cipher) =>{
+ const en = cryptojs.AES.decrypt(text,cipher);
const de = en.toString(cryptojs.enc.Utf8);
// console.log(de + "-dec");
return de;
diff --git a/index.js b/index.js
index 2b949e3..9399bc8 100644
--- a/index.js
+++ b/index.js
@@ -26,7 +26,7 @@ const app = express();
// const { mainModule } = require('process');
// const { name } = require('ejs');
-const maxRequestBodySize = '50mb';
+const maxRequestBodySize = '20mb';
app.set('view engine', 'ejs');
app.use(express.urlencoded({
extended: false,
@@ -79,7 +79,6 @@ app.post("/get_cr_uuid", (req,res) => {
app.post("/save_proj", (req,res) => {
let inp = req.body;
let cook = req.cookies;
- // func.log(inp["img"]);
func.sid(cook,res,()=>{
proj.save(inp,cook,res);
})
diff --git a/public/img/shadow-energy.gif b/public/img/shadow-energy.gif
new file mode 100644
index 0000000..dde7285
Binary files /dev/null and b/public/img/shadow-energy.gif differ
diff --git a/public/lib/fn.js b/public/lib/fn.js
index ce5d4c0..15f9d05 100644
--- a/public/lib/fn.js
+++ b/public/lib/fn.js
@@ -7,11 +7,6 @@ function get_from_uuid(callback){
// console.log("good");
callback(res["body"])
}
- else if (res["out"] == bad){
- if (res["body"] == "expired"){
- logout(true);
- }
- }
});
}
@@ -19,37 +14,40 @@ function log_by_sid() {
// const uuid = $.cookie("uuid");
// const sid = $.cookie("sid");
// console.log("log");
- if($.cookie('uuid') == null && $.cookie('sid') == null){
+ if($.cookie('sid') == null){
// get_sid(location.hostname);
get_sid();
- }else if ($.cookie('sid') != null && $.cookie('uuid') != null){
- $.post( "/sid_log")
- .done(function( res ) {
- console.log("ping");
- if(res["out"] == "good"){
- goto(res["url"]);
- }
- else if (res["out"] == "bad"){
- clear_ck(false);
- }
- })}
+ }
+ // else if ($.cookie('sid') != null && $.cookie('uuid') != null){
+ // $.post( "/sid_log")
+ // .done(function( res ) {
+ // console.log("ping");
+ // if(res["out"] == "good"){
+ // goto(res["url"]);
+ // }
+ // else if (res["out"] == "bad"){
+ // clear_ck(false);
+ // }
+ // })}
}
function clear_ck(redirect = true){
+ let uuid = $.cookie("uuid");
+ let sid = $.cookie("sid");
+ $.removeCookie("uuid");
+ $.removeCookie('sid');
console.log("sid");
- $.post( "/clear_sid")
- .done(function( res ) {
- console.log("sid");
- $.cookie("uuid",null);
- $.cookie("sid",null);
- $.removeCookie("uuid");
- $.removeCookie('sid');
- console.log("clear");
- get_sid();
- if(res["out"] == "good"){
- if (redirect) goto("/login");
- }
- })
+ setTimeout(()=>{
+ $.post( "/clear_sid",{uuid:uuid,sid:sid})
+ .done(function( res ) {
+ console.log("sid");
+ if(res["out"] == "good"){
+ // get_sid();
+ if (redirect) goto("/login");
+ }
+ console.log("clear");
+ })
+ },100)
}
diff --git a/public/lib/inter.js b/public/lib/inter.js
index 2c00d8b..3638fd0 100644
--- a/public/lib/inter.js
+++ b/public/lib/inter.js
@@ -1,12 +1,7 @@
window.dragMoveListener = dragMoveListener;
let root = document.getElementById("drags");
let objs = { height:"2",width:"4"};
-
-function get_count(clas){
- if (objs[clas] == null) objs[clas] = {};
- let count = Object.keys(objs[clas]).length;
- return count;
-}
+let objs_store = {};
function create(clas,x,y,body,id,size){
let main_clas = clas.split(" ")[0];
@@ -18,20 +13,39 @@ function create(clas,x,y,body,id,size){
clas.forEach(cl => {
obj.classList.add(cl);
});
- load_obj(main_clas,"`img`,`name`,`description`,`width`,`height`",(db_data)=>{
- if (db_data == null) {
- delete objs[main_clas][id];
- save(()=>{
- goto("/proj/"+proj_name);
- });
+ get_obj(main_clas,(db_data)=>{
+ if ($.cookie("cache") == "true"){
+ if (localStorage.getItem(`${main_clas}`) == null){
+ load_obj(main_clas,"`img`",(odata)=>{
+ localStorage.setItem(main_clas,odata["img"]);
+ make(odata["img"]);
+ })
+ }
+ else{
+ make(localStorage.getItem(main_clas))
+ }
}
- else if (db_data != null){
- obj.src = db_data["img"];
- obj.title = `${db_data["name"]}\n${db_data["description"]}\nwidth:${db_data["width"]}см height:${db_data["height"]}см`;
- // drag.transform = `translate(${drag.getAttribute("data-y")}px, ${drag.getAttribute("data-y")}px) scale(${db_data["width"] * 2} ${db_data["height"] * 2})`;
- if(size){
- obj.style.width = `${db_data["width"] * 2}px`;
- obj.style.height = `${db_data["height"] * 2}px`;
+ else{
+ load_obj(main_clas,"`img`",(odata)=>{
+ localStorage.setItem(main_clas,odata["img"]);
+ make(odata["img"]);
+ })
+ }
+ function make(img){
+ if (db_data == null) {
+ delete objs[main_clas][id];
+ save(()=>{
+ goto("/proj/"+proj_name);
+ });
+ }
+ else if (db_data != null){
+ obj.src = img;
+ obj.title = `${db_data["name"]}\n${db_data["description"]}\nwidth:${db_data["width"]}см height:${db_data["height"]}см`;
+ // drag.transform = `translate(${drag.getAttribute("data-y")}px, ${drag.getAttribute("data-y")}px) scale(${db_data["width"] * 2} ${db_data["height"] * 2})`;
+ if(size){
+ obj.style.width = `${db_data["width"] * 2}px`;
+ obj.style.height = `${db_data["height"] * 2}px`;
+ }
}
}
})
@@ -40,6 +54,12 @@ function create(clas,x,y,body,id,size){
set_pos(obj,x,y);
}
+function resize_drags(){
+ document.getElementById('drags').style.left = $('.dropzone')[0].getBoundingClientRect().x;
+ document.getElementById('drags').style.width = $('.dropzone')[0].style.width;
+ drag_start();
+}
+
function wall_size_change(type,value){
let wall = document.getElementsByClassName("wall")[0];
let scroll;
@@ -47,7 +67,7 @@ function wall_size_change(type,value){
if (value == null) scroll = document.getElementById("wall_width").value;
else scroll = value;
// document.getElementById("wall_width_value").innerHTML = (Math.ceil((parseFloat(scroll)+0.1)*10)/ 10);
- document.getElementById("wall_width_value").innerHTML = scroll;
+ document.getElementById("wall_width_value").innerHTML = `${scroll}м`;
// console.log(scroll);
wall.style.width = `${scroll * 200}px`;
@@ -57,7 +77,7 @@ function wall_size_change(type,value){
if (value == null) scroll = document.getElementById("wall_height").value;
else scroll = value;
// document.getElementById("wall_height_value").innerHTML = (Math.ceil((parseFloat(scroll)+0.1)*10)/ 10);
- document.getElementById("wall_height_value").innerHTML = scroll;
+ document.getElementById("wall_height_value").innerHTML = `${scroll}м`;
// console.log(scroll);
wall.style.height = `${scroll * 200}px`;
@@ -65,7 +85,7 @@ function wall_size_change(type,value){
}
}
-function load_local(objss){
+function load(objss){
// objs = JSON.parse($.cookie("objs"));
// console.log(objs);
objs = objss;
@@ -92,7 +112,9 @@ function load_local(objss){
drag_start();
}
-function load_proj(){
+function load_proj_cloud(){
+ document.getElementById("drags").innerHTML = "";
+ document.getElementById("top_panel_center").innerText = `loading ${proj_name} from cloud`;
$.post( "/load_proj",{name:proj_name})
.done(function( res ) {
if(res["out"] == "good"){
@@ -100,7 +122,8 @@ function load_proj(){
// console.log(JSON.parse(`'${res["body"]}'`));
// console.log(JSON.parse(res["body"]));
// $.cookie("objs",res["body"]);
- load_local(JSON.parse(res["body"]));
+ load(JSON.parse(res["body"]));
+ document.getElementById("top_panel_center").innerText = `${proj_name} (cloud)`;
}
else if(res["out"] == "bad proj"){
console.log("bad");
@@ -111,12 +134,28 @@ function load_proj(){
})
}
+function load_proj_local(){
+ // document.getElementById("top_panel_center").innerText = `loading ${proj_name} from local storage`;
+ if(localStorage.getItem(proj_name) == null){
+ save_local()
+ }
+ document.getElementById("top_panel_center").innerText = `${proj_name} (local)`;
+ document.getElementById("drags").innerHTML = "";
+ load(JSON.parse(localStorage.getItem(proj_name)));
+}
+
+function save_local(){
+ // console.log(objs);
+ localStorage.setItem(proj_name,JSON.stringify(objs));
+}
+
function save(callback){
// console.log(objs);
- html2canvas(document.querySelector("body"),{height: 500, width:(window.innerWidth /1.65),x:(window.innerWidth / 5), y:250}).then(canvas => {
+ html2canvas(document.querySelector("body"),{height: document.getElementById("wall").style.height.split("p")[0], width:document.getElementById("wall").style.width.split("p")[0], y:document.getElementById("wall").getBoundingClientRect().top,x:document.getElementById("wall").getBoundingClientRect().left}).then(canvas => {
let scr = "";
console.log(canvas.toDataURL().length);
- if (canvas.toDataURL().length < 120000) scr = canvas.toDataURL()
+ scr = canvas.toDataURL();
+ // if (canvas.toDataURL().length < 120000) scr = canvas.toDataURL()
// console.log(scr);
$.post( "/save_proj", {proj:JSON.stringify(objs),name:proj_name,img:scr})
.done(function( res ) {
@@ -134,11 +173,25 @@ function load_objs(callback){
.done(function( res ) {
if(res["out"] == "good"){
// console.log(res["body"]);
+ res["body"].forEach(element => {
+ objs_store[`${element["name"]}`] = {description:element["description"],height:element["height"],width:element["width"],id:element["id"],name:element["name"]}
+ });
callback(res["body"]);
}
});
}
+function get_obj(clas,callback){
+ if(objs_store != null && objs_store[clas] != null){
+ callback(objs_store[clas]);
+ }
+ else{
+ load_objs(()=>{
+ callback(objs_store[clas]);
+ })
+ }
+}
+
function load_obj(name,key,callback){
$.post( "/get_obj",{name:name,key:key})
.done(function( res ) {
@@ -233,11 +286,11 @@ interact('.createzone').dropzone({
var drag = event.relatedTarget;
var zone = event.target;
if(drag.classList[1] == "spawn" && drag.classList[0] == zone.classList[0]){
- load_obj(drag.classList[0],"`height`, `width`",(db_data)=>{
+ get_obj(drag.classList[0],(db_data)=>{
// drag.transform = `translate(${drag.getAttribute("data-y")}px, ${drag.getAttribute("data-y")}px) scale(${db_data["width"] * 2} ${db_data["height"] * 2})`;
drag.style.width = `${db_data["width"] * 2}px`;
drag.style.height = `${db_data["height"] * 2}px`;
- console.log(db_data);
+ // console.log(db_data);
})
let x = zone.getBoundingClientRect().left - document.getElementById("drags").getBoundingClientRect().left;
let y = zone.getBoundingClientRect().top - document.getElementById("drags").getBoundingClientRect().top;
@@ -251,6 +304,10 @@ interact('.createzone').dropzone({
})
function drag_start() {
+ let spawns = document.getElementsByClassName("spawn");
+ Object.entries(spawns).forEach(([key, spawn]) => {
+ spawn.parentElement.removeChild(spawn);
+ });
let zones = document.getElementsByClassName("createzone");
Object.entries(zones).forEach(([key, zone]) => {
let x = zone.getBoundingClientRect().left - document.getElementById("drags").getBoundingClientRect().left;
diff --git a/user.js b/user.js
index b603b51..84be3a5 100644
--- a/user.js
+++ b/user.js
@@ -12,18 +12,27 @@ module.exports.login = (inp,cook,res)=>{
}
else if (login != null){
db.gv("users","login",`'${ilogin}'`,(udata)=>{udata = udata[0];
- if(ipass == udata["pass"]){
- func.log("good boy "+udata["uuid"]+" logged in by login & pass from "+cook["sid"]);
- res.cookie("uuid",udata["uuid"],{maxAge:vars.week,path:"/;SameSite=Strict"});
+ db.ggv("sids","`sid`","uid",udata["id"],(sdata)=>{sdata = sdata[0];
+ // console.log(sdata);
+ if(ipass == udata["pass"]){
+ if (sdata != null){
+ // res.send({out:"logged",sid:sdata["sid"]});
+ // console.log(sdata);
+ db.dl("sids","uid",`'${udata["id"]}'`,() =>{});
- // db.sv("users","sids",sids += inp["sid"]+";","uuid",udata["uuid"],()=>{});
- db.nr("sids",'`sid`,`uid`',`'${cook["sid"]}','${udata["id"]}'`);
- res.send({out:"goto",url:"/main"});
+ }
+ func.log("good boy "+udata["uuid"]+" logged in by login & pass from "+cook["sid"]);
+ res.cookie("uuid",udata["uuid"],{maxAge:vars.week,path:"/;SameSite=Strict"});
+
+ // db.sv("users","sids",sids += inp["sid"]+";","uuid",udata["uuid"],()=>{});
+ db.nr("sids",'`sid`,`uid`',`'${cook["sid"]}','${udata["id"]}'`);
+ res.send({out:"goto",url:"/main"});
+ }
+ else{
+ res.status(210).send({out:"bad", err:"pass"});
+ }
- }
- else{
- res.status(210).send({out:"bad", err:"pass"});
- }
+ })
});
}
})
@@ -83,10 +92,29 @@ module.exports.get_cr = (inp,cook,res)=>{
}
module.exports.clear_sid = (inp,cook,res)=>{
- if(cook["sid"] != null){
+ if(inp["sid"] != null){
// res.send({out:"good"});
- func.log("good boy"+cook["uuid"] + " logged out from "+cook["sid"]);
- db.dl("sids","sid",`'${cook["sid"]}'`,() =>{});
+ db.dl("sids","sid",`'${inp["sid"]}'`,() =>{
+ func.log("good boy "+inp["uuid"] + " logged out from "+inp["sid"]);
+ });
+ // db.ggv("sids","id","sid",`'${cook["sid"]}'`,(sids)=>{
+ // Object.entries(sids).forEach(([key,value])=>{
+ // db.dl("sids","id",`'${value["id"]}'`,() =>{});
+ // })
+ // })
+ }
+ else if(inp["uuid"] != null){
+ // res.send({out:"good"});
+ db.ggv("users","id","uuid",`'${inp["uuid"]}'`,(udata)=>{udata = udata[0]
+ db.dl("sids","uid",`'${udata["id"]}'`,() =>{
+ func.log("good boy "+inp["uuid"] + " logged out from "+inp["sid"]);
+ });
+ // db.ggv("sids","id","uid",`'${udata["id"]}'`,(sids)=>{
+ // Object.entries(sids).forEach(([key,value])=>{
+ // db.dl("sids","id",`'${value["id"]}'`,() =>{});
+ // })
+ // })
+ });
}
res.send({out:"good"});
}
@@ -94,12 +122,12 @@ module.exports.clear_sid = (inp,cook,res)=>{
module.exports.sid_log=(inp,cook,res,req)=>{
func.sid(cook,res,(include) => {
if (include){
- if(req.headers.referer.split("http://n0rsrv2:3002/")[1] == "login") func.log("good boy "+ id["uuid"]+" logged in by sid logs from " + id["sid"]);
res.send({out:"good",url:"/main"});
+ if(req.headers.referer.split("http://n0rsrv2:3002/")[1] == "login") func.log("good boy "+ id["uuid"]+" logged in by sid logs from " + id["sid"]);
}
else if (!include){
- if(req.headers.referer.split("http://n0rsrv2:3002/")[1] == "login") func.log("bad boy "+ id["uuid"]+" tried to login by sid but sid expired from " + id["sid"]);
res.send({out:"bad"});
+ if(req.headers.referer.split("http://n0rsrv2:3002/")[1] == "login") func.log("bad boy "+ id["uuid"]+" tried to login by sid but sid expired from " + id["sid"]);
}
},false)
}
\ No newline at end of file
diff --git a/views/header.ejs b/views/header.ejs
index 9fda58c..47c5d77 100644
--- a/views/header.ejs
+++ b/views/header.ejs
@@ -11,13 +11,15 @@
/* float: right; */
justify-content: space-between;
display: flex;
- width: 20vw;
+ cursor: pointer;
+ /* width: 20vw; */
}
#top_panel_left{
/* float: left; */
justify-content: space-between;
+ cursor: pointer;
display: flex;
- width: 20vw;
+ /* width: 20vw; */
}
#top_panel{
height: 20px;
@@ -25,59 +27,85 @@
/* button{
/* margin-inline: 5px; */
/* } */
- #ctxmenu {
- position: fixed;
- background: ghostwhite;
- color: black;
- cursor: pointer;
- border: 1px black solid
- }
- #ctxmenu > p {
- padding: 0 1rem;
- margin: 0
- }
- #ctxmenu > p:hover {
- background: black;
- color: ghostwhite
+ .menu_btn{
+ background: ghostwhite;
+ cursor: pointer;
+ border: 1px black dashed;
+ padding: 5px;
+ }
+ .cmenu{
+ position: fixed;
+ display: block;
+ background: ghostwhite;
+ color: black;
+ cursor: pointer;
+ border: 1px black solid;
}
+
+
user already logged in from sid - ${res["sid"]}