New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

ernest

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ernest - npm Package Compare versions

Comparing version
2.4.1
to
2.5.0
+977
Ernest_Commands.js
const fs = require('fs');
const DB_BKP = require('./Ernest_DB_BKP');
class Ernest_Commands
{
constructor(ernest,logPath,inputLine,outputLine)
{
this.ernest = ernest;
this.currentUser = null;
this.inputLine = inputLine;
this.outputLine = outputLine;
this.logPath = logPath;
};
MainMenu()
{
var _this = this;
_this.show("\x1b[37mErnest CLI\\>\x1b[0m ",function(input)
{
_this.ProcessCMD(input);
});
};
show(message,callback)
{
this.inputLine(message + " ", (answer) =>
{
callback(answer);
});
};
ProcessCMD(cmd)
{
var _this = this;
if(cmd == "")
{
_this.MainMenu();
}
else
{
if( cmd == 'stop')
{
_this.outputLine("Good Bye");
process.exit(0);
}
else
{
if(cmd == 'clear')
{
process.stdout.write('\x1Bc');
_this.MainMenu();
}else
{
var functs = Object.getOwnPropertyNames(Ernest_Commands.prototype).filter(function (p) {return (p.indexOf("_") == 0); });
var till = functs.length -1;
let notfound = true;
functs.map(function(f,index)
{
if( cmd == f.slice(1))
{
_this[f].call(_this,_this);
notfound = false;
};
if((till == index) && notfound)
{
_this.outputLine("Command not found");
_this.MainMenu();
};
});
};
};
};
};
UserSelection(cli,callback)
{
var _this = this;
if(_this.currentUser != null)
{
callback(_this.currentUser);
}
else
{
cli.show("User: ", user =>
{
callback(user);
});
};
}
_onUser(cli)
{
var _this = this;
cli.show("User: ", user =>
{
_this.currentUser = user;
_this.outputLine("Done");
cli.MainMenu();
});
};
_outUser(cli)
{
var _this = this;
this.currentUser = null;
_this.outputLine("Done");
cli.MainMenu();
}
_reloadREST(cli)
{
var _this = this;
_this.ernest.ReloadTemplaters(function(e,r)
{
_this.outputLine("Reloading Rest Templates ...");
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
_this.outputLine("Done");
cli.MainMenu();
});
};
_dbCommand(cli)
{
var _this = this;
cli.show("Command:",function(strObj)
{
var jsonObj = JSON.parse(JSON.stringify(strObj));
_this.ernest.dbc.DBCommand(jsonObj,function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
});
};
_adminCommand(cli)
{
var _this = this;
cli.show("Command:",function(strObj)
{
var jsonObj = JSON.parse(JSON.stringify(strObj));
_this.ernest.dbc.AdminCommand(jsonObj,function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
});
};
_rsStatus(cli)
{
var _this = this;
_this.ernest.dbc.rsStatus(function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
};
_serverStatus(cli)
{
var _this = this;
_this.ernest.dbc.ServerStatus(function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
};
_addUser(cli)
{
var _this = this ;
_this.UserSelection(cli, user =>
{
if(user=="")
{
_this.outputLine("Cancelled");
_this.outputLine("");
cli.MainMenu();
}
else
{
cli.show("password:",function(password)
{
cli.show("properties (as json):",function(valor)
{
var jprop = JSON.parse(JSON.parse(JSON.stringify(valor)));
_this.ernest.Users.CreateUser(user,password,jprop,function(success)
{
if(success)
{
_this.outputLine("Success: User has been added");
_this.outputLine("");
cli.MainMenu();
}
else
{
_this.outputLine("Error: User already exist");
_this.outputLine("");
cli.MainMenu();
};
});
});
});
};
});
};
_deleteUser(cli)
{
var _this = this ;
_this.UserSelection(cli, user =>
{
if(user=="")
{
_this.outputLine("Cancelled");
_this.outputLine("");
cli.MainMenu();
}
else
{
_this.ernest.Users.DeleteUser(user,function()
{
_this.outputLine("User has been deleted");
_this.outputLine("");
cli.MainMenu();
});
};
});
};
_showUser(cli)
{
var _this = this ;
_this.UserSelection(cli, user =>
{
if(user=="")
{
_this.outputLine("Cancelled");
_this.outputLine("");
cli.MainMenu();
}
else
{
_this.ernest.Users.GetUserAccesses(user,function(r)
{
if(r.length == 1)
{
delete r[0]['_id'];
_this.outputLine(r[0], {depth: null, colors: true});
_this.outputLine("");
cli.MainMenu();
}
else
{
_this.outputLine("Error: User not Found");
_this.outputLine("");
cli.MainMenu();
};
});
};
});
};
_status(cli)
{
var _this = this;
_this.outputLine(_this.ernest.status + ". Ernest Mongo Database Name: '"+ _this.ernest.db_name + "'. ");
cli.MainMenu();
};
_pid(cli)
{
var _this = this;
_this.outputLine("Current Erenst PID: " + process.pid);
cli.MainMenu();
}
_db(cli)
{
var _this = this;
_this.outputLine(_this.ernest.db_name);
cli.MainMenu();
};
_setdb(cli)
{
var _this = this;
_this.outputLine("Current Ernest DB: " + _this.ernest.db_name);
cli.show("New DB Name:",input =>
{
if(input != "")
{
_this.ernest.setDB(input);
_this.outputLine("Done");
};
cli.MainMenu();
});
};
_logs(cli)
{
var _this = this;
fs.readdir(_this.logPath , (e, files) =>
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
}
else
{
files.map((file) =>
{
let d =file.replace(".log","");
if(!isNaN(d))
{
let n = Number(d)
let date = new Date(n);
_this.outputLine(" --> Log Date: " + date + ", --> Log File Name: " + file);
};
});
};
cli.MainMenu();
});
};
_log(cli)
{
var _this = this;
cli.show("Log File Name:",logfile =>
{
if(logfile != "")
{
var data = fs.readFileSync(_this.logPath + "/" + logfile, 'utf-8');
_this.outputLine(" >>>>>>>>>>>>>>>>>>>>>>> " +logfile + " <<<<<<<<<<<<<<<<<<<<<<<");
_this.outputLine(data);
_this.outputLine(" >>>>>>>>>>>>>>>>>>>>>>> " +logfile + " <<<<<<<<<<<<<<<<<<<<<<<");
};
cli.MainMenu();
});
};
_updateUserPassword(cli)
{
var _this = this;
_this.UserSelection(cli, user =>
{
cli.show("New Password: ", pass =>
{
_this.ernest.Users.UpdateUserPassword(user,pass,function(r)
{
_this.outputLine("Done");
cli.MainMenu();
});
});
});
};
_updateUserProperties(cli)
{
var _this = this;
_this.UserSelection(cli, user =>
{
cli.show("New Properties: ", properties =>
{
var json_properties = JSON.parse(properties);
_this.ernest.Users.UpdateUserProperties(user,json_properties,function(r)
{
_this.outputLine("Done");
cli.MainMenu();
});
});
});
};
_deleteUserProperty(cli)
{
var _this = this;
_this.UserSelection(cli, user =>
{
cli.show("Property: ", property =>
{
_this.ernest.Users.DeleteUserProperty(user,property,function(r)
{
_this.outputLine("Done");
cli.MainMenu();
});
});
});
};
_addPagetoUser(cli)
{
var _this = this;
_this.UserSelection(cli, user =>
{
cli.show("New Page: ", page =>
{
cli.show("Level Access: ", level =>
{
_this.ernest.Users.SetUserAccess(user,page,level,function(r)
{
_this.outputLine("Done");
cli.MainMenu();
});
});
});
});
};
_removePageUser(cli)
{
var _this = this;
_this.UserSelection(cli, user =>
{
cli.show("Remove Page: ", page =>
{
_this.ernest.Users.UnsetUserAccess(user,page,function(r)
{
_this.outputLine("Done");
cli.MainMenu();
});
});
});
};
_createCollection(cli)
{
var _this = this;
cli.show("New Collection: ", col =>
{
_this.ernest.dbc.CreateCollection(col,function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
});
};
_deleteCollection(cli)
{
var _this = this;
cli.show("Collection: ", col =>
{
_this.ernest.dbc.DropCollection(col,function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
});
};
_collectionExist(cli)
{
var _this = this;
cli.show("Collection: ", col =>
{
_this.ernest.dbc.CollectionExist(col,function(e,r)
{
if(e)
{
_this.outputLine(" Error: ");
_this.outputLine(e );
};
if(r)
{
_this.outputLine(" Response: ");
_this.outputLine(r);
};
cli.MainMenu();
});
});
};
_Collections(cli)
{
var _this = this;
_this.ernest.dbc.getCollectionNames(function(e,d)
{
_this.outputLine({error:e,data:d}, {depth: null, colors: true});
cli.MainMenu();
});
};
_IsPublicAccess(cli)
{
var _this = this;
cli.show("URL: ", iurl =>
{
if(iurl.length > 0)
{
_this.ernest.Permission.IsPublicAccess(iurl,function(r)
{
if(r)
{
_this.outputLine("URL has public access in DB");
cli.MainMenu();
}
else
{
_this.outputLine("URL doesn't has public access in DB");
cli.MainMenu();
};
});
}
else
{
_this.outputLine("Cancelled!");
cli.MainMenu();
}
});
};
_SetPublicAccess(cli)
{
var _this = this;
cli.show("URL: ", iurl =>
{
if(iurl.length > 0)
{
_this.ernest.Permission.SetPublicAccess(iurl,function(r)
{
if(r)
{
_this.outputLine("URL now haspublic access in DB");
cli.MainMenu();
}
else
{
_this.outputLine("operation incomplete");
cli.MainMenu();
};
});
}
else
{
_this.outputLine("Cancelled!");
cli.MainMenu();
}
});
};
_UnSetPublicAccess(cli)
{
var _this = this;
cli.show("URL: ", iurl =>
{
if(iurl.length > 0)
{
_this.ernest.Permission.UnSetPublicAccess(iurl,function(r)
{
if(r)
{
_this.outputLine("URL now doesn't has public access in DB");
cli.MainMenu();
}
else
{
_this.outputLine("operation incomplete");
cli.MainMenu();
};
});
}
else
{
_this.outputLine("Cancelled!");
cli.MainMenu();
}
});
};
_CreatePublicAccess(cli)
{
var _this = this;
cli.show("Access Collection: ", iaccess =>
{
if(iaccess.length > 0)
{
_this.ernest.Permission.CreatePublicAccess(iaccess,function(r)
{
if(r)
{
_this.outputLine("public access in DB created");
cli.MainMenu();
}
else
{
_this.outputLine("public access in DB couldn't being created");
cli.MainMenu();
};
});
}
else
{
_this.outputLine("Cancelled!");
cli.MainMenu();
}
});
};
_ListPublicFiles(cli)
{
var _this = this;
if(_this.ernest.public == null)
{
_this.outputLine("Ernest working without public folder");
cli.MainMenu();
}
else
{
cli.show("Path inside Public folder (default:public/):",function(pth)
{
if(pth == "")
{
fs.readdir(_this.ernest.public, (err, files) =>
{
if(err)
{
throw err;
cli.MainMenu();
}
else
{
var till = files.length -1;
if(till == -1)
{
_this.outputLine("Ernest Public folder has no files");
cli.MainMenu();
}
else
{
files.map(function(file,index)
{
_this.outputLine(file);
if(index == till)
{
cli.MainMenu();
};
});
};
};
});
}
else
{
fs.readdir(_this.ernest.public + "/" +pth, (err, files) =>
{
if(err)
{
throw err;
cli.MainMenu();
}
else
{
var till = files.length -1;
if(till == -1)
{
_this.outputLine("Ernest Public folder has no files");
cli.MainMenu();
}
else
{
files.map(function(file,index)
{
_this.outputLine(file);
if(index == till)
{
cli.MainMenu();
};
});
};
};
});
};
});
};
};
_CopyPublicFile(cli)
{
var _this = this;
if(_this.ernest.public == null)
{
_this.outputLine("Ernest working without public folder");
cli.MainMenu();
}
else
{
cli.show("Public File Path (src. Default public/):",function(pth_src)
{
cli.show("Public File Name (src):",function(name_src)
{
cli.show("New Public File Name (copy):",function(name_cpy)
{
copyFile(_this.ernest.public + "/" +pth_src + name_src, _this.ernest.public + "/" + pth_src + name_cpy , (err) =>
{
if(err)
{
_this.outputLine("Erenst couldn't copy the file");
cli.MainMenu();
}
else
{
cli.MainMenu();
};
});
});
});
});
};
};
_DB_Backup(cli)
{
var _this = this;
let db_bkp = new DB_BKP(_this.ernest.db_name);
cli.show("Output DB Backup Folder:",function(pth_dst)
{
db_bkp.Create_BackUp(pth_dst,function()
{
_this.outputLine("Done");
cli.MainMenu();
});
});
};
_DB_Restore(cli)
{
var _this = this;
let db_bkp = new DB_BKP(_this.ernest.db_name);
cli.show("Backup Source Folder (without file): ",function(src_path)
{
cli.show("Backup Source TAR.GZ File Name (without extension): ",function(tarfilename)
{
cli.show("Database name target: ",function(new_dbname)
{
let tarfile = tarfilename + ".tar.gz";
db_bkp.Restore_BackUp(src_path,tarfile,new_dbname,function(r)
{
if(r)
{
_this.outputLine("Done");
}
else
{
_this.outputLine("Error");
};
cli.MainMenu();
});
});
});
});
};
_man(cli)
{
var _this = this;
let info = `
\x1b[37m reloadREST \x1b[0m
Reload all template controlers after an update in templates or views;
\x1b[37m logs \x1b[0m
Shows all log files;
\x1b[37m log \x1b[0m
Shows the content of a log file;
\x1b[37m dbCommand \x1b[0m
Executes a Obj Form Mongo Command in DB;
\x1b[37m adminCommand \x1b[0m
Executes a Obj Form Mongo Command in adminDB;
\x1b[37m serverStatus \x1b[0m
Show the DB server Status.
\x1b[37m rsStatus \x1b[0m
Show the replicaSet Status.
\x1b[37m onUser \x1b[0m
Sets the user for the next operations.
\x1b[37m outUser \x1b[0m
Unsets the user for the next operations.
\x1b[37m addUser \x1b[0m
Add a new user to your login web system.(user, password, propiertis in json format : {"name": "john doe", "age":34, level:33})
\x1b[37m deleteUser \x1b[0m
Delete a user to your login web system
\x1b[37m showUser \x1b[0m
Show user info
\x1b[37m status \x1b[0m
Show Ernest info (port - http / https)
\x1b[37m pid \x1b[0m
Show Current Ernest PID procces
\x1b[37m db \x1b[0m
Show current Mongo DB
\x1b[37m setdb \x1b[0m
Set a Mongo DB
\x1b[37m updateUserPassword \x1b[0m
Update user password
\x1b[37m updateUserProperties \x1b[0m
Update User properties
\x1b[37m _deleteUserProperty \x1b[0m
Update User properties
\x1b[37m addPagetoUser \x1b[0m
Add permission for user access to the a specific page.
\x1b[37m removePageUser \x1b[0m
Remove permission for user access to the a specific page.
\x1b[37m createCollection \x1b[0m
Create a collection in the current Mongo Db.
\x1b[37m deleteCollection \x1b[0m
Delete a collection in the current Mongo Db.
\x1b[37m collectionExist \x1b[0m
Show if collection exits in the current Mongo DB.
\x1b[37m Collections \x1b[0m
Show all collections in the current Mongo DB.
\x1b[37m IsPublicAccess \x1b[0m
Show if the file has public access in the db.
\x1b[37m SetPublicAccess \x1b[0m
Set file's public access in the db.
\x1b[37m UnSetPublicAccess \x1b[0m
Unset file's public access in the db.
\x1b[37m CreatePublicAccess \x1b[0m
Create public access in DB for first time(One time per DB)
\x1b[37m ListPublicFiles \x1b[0m
Show the files in public folder.
\x1b[37m CopyPublicFile \x1b[0m
Copy one file in public folder, with other name(example: template file) inside public folder.
\x1b[37m DB_Backup \x1b[0m
Create Current Ernest DB Backup. Exports DB to a specific tar.gz file
\x1b[37m DB_Restore \x1b[0m
Restore Ernest DB from Backup. Imports DB from a specific tar.gz file
\x1b[37m man \x1b[0m
Show Ernest command info.
\x1b[37m clear \x1b[0m
Clear Ernest CLI.
\x1b[37m stop \x1b[0m
Stop Ernest an exit Ernest CLI.
`;
_this.outputLine(info);
cli.MainMenu();
};
};
module.exports = Ernest_Commands;
function copyFile(src, dest,callback)
{
if (!fs.existsSync(src))
{
callback(true);
}
else
{
var data = fs.readFileSync(src, 'utf-8');
fs.writeFileSync(dest, data);
if (!fs.existsSync(dest))
{
callback(true);
}
else
{
callback(null);
};
};
};
const Ernest_Commands = require('./Ernest_Commands');
const SCM = require('./ServerCommunicationModule');
class Ernest_CSI
{
constructor(ernest,logPath,serverId,serverChannel)
{
this.ernest = ernest;
this.scm = new SCM(serverId,serverChannel);
this.socket = null;
this.ernestCommand = null;
this.msg = "";
this.funct = null;
this.loggedOn = false;
this.logPath = logPath;
};
Start()
{
var _this = this;
this.ernestCommand = new Ernest_Commands(_this.ernest,_this.logPath,function(message,funct)
{
_this.scm.Send(message,_this.socket);
_this.funct = funct;
},function(message)
{
_this.scm.Send(message,_this.socket);
});
this.Hook();
this.scm.Start();
};
Hook()
{
var _this = this;
_this.scm.OnData((data,currentSocket) =>
{
_this.socket = currentSocket;
if(data == "admin")
{
_this.loggedOn = true;
_this.scm.Send("Welcome Admin \n",currentSocket);
_this.ernestCommand.MainMenu();
}
else
{
if(data == "logout")
{
_this.loggedOn = false;
_this.scm.Disconnect(_this.socket);
}
else
{
if(!_this.loggedOn)
{
_this.scm.Send("Not loggin \n",currentSocket);
}
else
{
if(typeof _this.funct == 'function')
{
_this.funct(data);
}
}
}
};
});
};
};
module.exports = Ernest_CSI;
const ipc = require('node-ipc');
class ServerCommunicationModule
{
constructor(serverId,serverChannel)
{
this.serverId = serverId;
this.ServerChannel = serverChannel;
this.toServerChannel = '1' + this.ServerChannel;
this.fromServerChannel = '0' + this.ServerChannel;
ipc.config.id = serverId;
ipc.config.retry = 1500;
ipc.config.silent = true;
};
OnData(callback)
{
ipc.serve(() => ipc.server.on(this.toServerChannel, (message,socket )=>
{
callback(message,socket);
}));
};
Start()
{
ipc.server.start();
};
Send(data,socket)
{
ipc.server.emit(socket,this.fromServerChannel,data);
};
Disconnect(socket)
{
ipc.disconnect(socket);
};
};
module.exports = ServerCommunicationModule
+48
-911

@@ -1,5 +0,4 @@

const readline = require('readline');
const fs = require('fs');
const DB_BKP = require('./Ernest_DB_BKP');
const rl = readline.createInterface({
const Ernest_Commands = require('./Ernest_Commands');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,

@@ -9,899 +8,24 @@ output: process.stdout,completer

class Ernest_show
{
constructor(ernest)
{
this.ernest = ernest;
this.currentUser = null;
};
MainMenu()
constructor(ernest,logPath)
{
var _this = this;
_this.show("\x1b[37mErnest CLI\\>\x1b[0m ",function(input)
this.ernestCommand = new Ernest_Commands(ernest,logPath,function(message,callback)
{
_this.ProcessCMD(input);
});
};
show(message,callback)
{
rl.question(message + " ", (answer) =>
{
callback(answer);
});
};
ProcessCMD(cmd)
{
var _this = this;
if(cmd == "")
{
_this.MainMenu();
}
else
{
if( cmd == 'exit')
rl.question(message + " ", (answer) =>
{
console.log("Good Bye");
process.exit(0);
}
else
{
if(cmd == 'clear')
{
process.stdout.write('\x1Bc');
_this.MainMenu();
}else
{
var functs = Object.getOwnPropertyNames(Ernest_show.prototype).filter(function (p) {return (p.indexOf("_") == 0); });
var till = functs.length -1;
let notfound = true;
functs.map(function(f,index)
{
if( cmd == f.slice(1))
{
_this[f].call(_this,_this);
notfound = false;
};
if((till == index) && notfound)
{
console.log("Command not found");
_this.MainMenu();
};
});
};
};
};
};
UserSelection(cli,callback)
{
var _this = this;
if(_this.currentUser != null)
{
callback(_this.currentUser);
}
else
{
cli.show("User: ", user =>
{
callback(user);
callback(answer);
});
};
}
_onUser(cli)
{
var _this = this;
cli.show("User: ", user =>
},function(text)
{
_this.currentUser = user;
console.log("Done");
cli.MainMenu();
console.log(text);
});
};
_outUser(cli)
MainMenu()
{
this.currentUser = null;
console.log("Done");
cli.MainMenu();
}
_reloadREST(cli)
{
var _this = this;
_this.ernest.ReloadTemplaters(function(e,r)
{
console.log("Reloading Rest Templates ...");
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
console.log("Done");
cli.MainMenu();
});
this.ernestCommand.MainMenu();
};
_dbCommand(cli)
{
var _this = this;
cli.show("Command:",function(strObj)
{
var jsonObj = JSON.parse(JSON.stringify(strObj));
_this.ernest.dbc.DBCommand(jsonObj,function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
});
};
_adminCommand(cli)
{
var _this = this;
cli.show("Command:",function(strObj)
{
var jsonObj = JSON.parse(JSON.stringify(strObj));
_this.ernest.dbc.AdminCommand(jsonObj,function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
});
};
_rsStatus(cli)
{
var _this = this;
_this.ernest.dbc.rsStatus(function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
};
_serverStatus(cli)
{
var _this = this;
_this.ernest.dbc.ServerStatus(function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
};
_addUser(cli)
{
var _this = this ;
this.UserSelection(cli, user =>
{
if(user=="")
{
console.log("Cancelled");
console.log("");
cli.MainMenu();
}
else
{
cli.show("password:",function(password)
{
cli.show("properties (as json):",function(valor)
{
var jprop = JSON.parse(JSON.parse(JSON.stringify(valor)));
_this.ernest.Users.CreateUser(user,password,jprop,function(success)
{
if(success)
{
console.log("Success: User has been added");
console.log("");
cli.MainMenu();
}
else
{
console.log("Error: User already exist");
console.log("");
cli.MainMenu();
};
});
});
});
};
});
};
_deleteUser(cli)
{
var _this = this ;
this.UserSelection(cli, user =>
{
if(user=="")
{
console.log("Cancelled");
console.log("");
cli.MainMenu();
}
else
{
_this.ernest.Users.DeleteUser(user,function()
{
console.log("User has been deleted");
console.log("");
cli.MainMenu();
});
};
});
};
_showUser(cli)
{
var _this = this ;
this.UserSelection(cli, user =>
{
if(user=="")
{
console.log("Cancelled");
console.log("");
cli.MainMenu();
}
else
{
_this.ernest.Users.GetUserAccesses(user,function(r)
{
if(r.length == 1)
{
delete r[0]['_id'];
console.dir(r[0], {depth: null, colors: true});
console.log("");
cli.MainMenu();
}
else
{
console.log("Error: User not Found");
console.log("");
cli.MainMenu();
};
});
};
});
};
_status(cli)
{
console.log(this.ernest.status + ". Ernest Mongo Database Name: '"+ this.ernest.db_name + "'. ");
cli.MainMenu();
};
_pid(cli)
{
console.log("Current Erenst PID: " + process.pid);
cli.MainMenu();
}
_db(cli)
{
console.log(this.ernest.db_name);
cli.MainMenu();
};
_setdb(cli)
{
console.log("Current Ernest DB: " + this.ernest.db_name);
cli.show("New DB Name:",input =>
{
if(input != "")
{
this.ernest.setDB(input);
console.log("Done");
};
cli.MainMenu();
});
};
_updateUserPassword(cli)
{
this.UserSelection(cli, user =>
{
cli.show("New Password: ", pass =>
{
this.ernest.Users.UpdateUserPassword(user,pass,function(r)
{
console.log("Done");
cli.MainMenu();
});
});
});
};
_updateUserProperties(cli)
{
this.UserSelection(cli, user =>
{
cli.show("New Properties: ", properties =>
{
var json_properties = JSON.parse(properties);
this.ernest.Users.UpdateUserProperties(user,json_properties,function(r)
{
console.log("Done");
cli.MainMenu();
});
});
});
};
_deleteUserProperty(cli)
{
this.UserSelection(cli, user =>
{
cli.show("Property: ", property =>
{
this.ernest.Users.DeleteUserProperty(user,property,function(r)
{
console.log("Done");
cli.MainMenu();
});
});
});
};
_addPagetoUser(cli)
{
this.UserSelection(cli, user =>
{
cli.show("New Page: ", page =>
{
this.ernest.Users.SetUserAccess(user,page,function(r)
{
console.log("Done");
cli.MainMenu();
});
});
});
};
_addPagestoUser(cli)
{
var _this = this;
this.UserSelection(cli, user =>
{
cli.show("New Pages separates by , : ", pages =>
{
var pgs = pages.split(",");
var till = pgs.length -1;
if(till >= 0)
{
pgs.map(function(page,index)
{
_this.ernest.Users.SetUserAccess(user,page,function(r)
{
if(index == till)
{
console.log("Done");
cli.MainMenu();
};
});
});
}
else
{
console.log("Cancelled");
cli.MainMenu();
};
});
});
}
_removePageUser(cli)
{
this.UserSelection(cli, user =>
{
cli.show("Remove Page: ", page =>
{
this.ernest.Users.UnsetUserAccess(user,page,function(r)
{
console.log("Done");
cli.MainMenu();
});
});
});
};
_createCollection(cli)
{
cli.show("New Collection: ", col =>
{
this.ernest.dbc.CreateCollection(col,function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
});
};
_deleteCollection(cli)
{
cli.show("Collection: ", col =>
{
this.ernest.dbc.DropCollection(col,function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
});
};
_collectionExist(cli)
{
cli.show("Collection: ", col =>
{
this.ernest.dbc.CollectionExist(col,function(e,r)
{
if(e)
{
console.log(" Error: " + e );
};
if(r)
{
console.log(" Response: " + r);
};
cli.MainMenu();
});
});
};
_Collections(cli)
{
this.ernest.dbc.getCollectionNames(function(e,d)
{
console.dir({error:e,data:d}, {depth: null, colors: true});
cli.MainMenu();
});
};
_IsPublicAccess(cli)
{
cli.show("URL: ", iurl =>
{
if(iurl.length > 0)
{
this.ernest.Permission.IsPublicAccess(iurl,function(r)
{
if(r)
{
console.log("URL has public access in DB");
cli.MainMenu();
}
else
{
console.log("URL doesn't has public access in DB");
cli.MainMenu();
};
});
}
else
{
console.log("Cancelled!");
cli.MainMenu();
}
});
};
_SetPublicAccess(cli)
{
cli.show("URL: ", iurl =>
{
if(iurl.length > 0)
{
this.ernest.Permission.SetPublicAccess(iurl,function(r)
{
if(r)
{
console.log("URL now haspublic access in DB");
cli.MainMenu();
}
else
{
console.log("operation incomplete");
cli.MainMenu();
};
});
}
else
{
console.log("Cancelled!");
cli.MainMenu();
}
});
};
_UnSetPublicAccess(cli)
{
cli.show("URL: ", iurl =>
{
if(iurl.length > 0)
{
this.ernest.Permission.UnSetPublicAccess(iurl,function(r)
{
if(r)
{
console.log("URL now doesn't has public access in DB");
cli.MainMenu();
}
else
{
console.log("operation incomplete");
cli.MainMenu();
};
});
}
else
{
console.log("Cancelled!");
cli.MainMenu();
}
});
};
_CreatePublicAccess(cli)
{
cli.show("Access Collection: ", iaccess =>
{
if(iaccess.length > 0)
{
this.ernest.Permission.CreatePublicAccess(iaccess,function(r)
{
if(r)
{
console.log("public access in DB created");
cli.MainMenu();
}
else
{
console.log("public access in DB couldn't being created");
cli.MainMenu();
};
});
}
else
{
console.log("Cancelled!");
cli.MainMenu();
}
});
};
_ListPublicFiles(cli)
{
var _this = this;
if(_this.ernest.public == null)
{
console.log("Ernest working without public folder");
cli.MainMenu();
}
else
{
cli.show("Path inside Public folder (default:public/):",function(pth)
{
if(pth == "")
{
fs.readdir(_this.ernest.public, (err, files) =>
{
if(err)
{
throw err;
cli.MainMenu();
}
else
{
var till = files.length -1;
if(till == -1)
{
console.log("Ernest Public folder has no files");
cli.MainMenu();
}
else
{
files.map(function(file,index)
{
console.log(file);
if(index == till)
{
cli.MainMenu();
};
});
};
};
});
}
else
{
fs.readdir(_this.ernest.public + "/" +pth, (err, files) =>
{
if(err)
{
throw err;
cli.MainMenu();
}
else
{
var till = files.length -1;
if(till == -1)
{
console.log("Ernest Public folder has no files");
cli.MainMenu();
}
else
{
files.map(function(file,index)
{
console.log(file);
if(index == till)
{
cli.MainMenu();
};
});
};
};
});
};
});
};
};
_CopyPublicFile(cli)
{
var _this = this;
if(_this.ernest.public == null)
{
console.log("Ernest working without public folder");
cli.MainMenu();
}
else
{
cli.show("Public File Path (src. Default public/):",function(pth_src)
{
cli.show("Public File Name (src):",function(name_src)
{
cli.show("New Public File Name (copy):",function(name_cpy)
{
copyFile(_this.ernest.public + "/" +pth_src + name_src, _this.ernest.public + "/" + pth_src + name_cpy , (err) =>
{
if(err)
{
console.log("Erenst couldn't copy the file");
cli.MainMenu();
}
else
{
cli.MainMenu();
};
});
});
});
});
};
};
_DB_Backup(cli)
{
let db_bkp = new DB_BKP(this.ernest.db_name);
cli.show("Output DB Backup Folder:",function(pth_dst)
{
db_bkp.Create_BackUp(pth_dst,function()
{
console.log("Done");
cli.MainMenu();
});
});
};
_DB_Restore(cli)
{
let db_bkp = new DB_BKP(this.ernest.db_name);
cli.show("Backup Source Folder (without file): ",function(src_path)
{
cli.show("Backup Source TAR.GZ File Name (without extension): ",function(tarfilename)
{
cli.show("Database name target: ",function(new_dbname)
{
let tarfile = tarfilename + ".tar.gz";
db_bkp.Restore_BackUp(src_path,tarfile,new_dbname,function(r)
{
if(r)
{
console.log("Done");
}
else
{
console.log("Error");
};
cli.MainMenu();
});
});
});
});
};
_man(cli)
{
let info = `
reloadREST
\x1b[37m reloadREST \x1b[0m
Reload all template controlers after an update in templates or views;
\x1b[37m dbCommand \x1b[0m
Executes a Obj Form Mongo Command in DB;
\x1b[37m adminCommand \x1b[0m
Executes a Obj Form Mongo Command in adminDB;
\x1b[37m serverStatus \x1b[0m
Show the DB server Status.
\x1b[37m rsStatus \x1b[0m
Show the replicaSet Status.
\x1b[37m onUser \x1b[0m
Sets the user for the next operations.
\x1b[37m outUser \x1b[0m
Unsets the user for the next operations.
\x1b[37m addUser \x1b[0m
Add a new user to your login web system.(user, password, propiertis in json format : {"name": "john doe", "age":34, level:33})
\x1b[37m deleteUser \x1b[0m
Delete a user to your login web system
\x1b[37m showUser \x1b[0m
Show user info
\x1b[37m status \x1b[0m
Show Ernest info (port - http / https)
\x1b[37m pid \x1b[0m
Show Current Ernest PID procces
\x1b[37m db \x1b[0m
Show current Mongo DB
\x1b[37m setdb \x1b[0m
Set a Mongo DB
\x1b[37m updateUserPassword \x1b[0m
Update user password
\x1b[37m updateUserProperties \x1b[0m
Update User properties
\x1b[37m _deleteUserProperty \x1b[0m
Update User properties
\x1b[37m addPagetoUser \x1b[0m
Add permission for user access to the a specific page.
\x1b[37m addPagestoUser \x1b[0m
Add permission for user access to the a many pages, separates by ",".
\x1b[37m removePageUser \x1b[0m
Remove permission for user access to the a specific page.
\x1b[37m createCollection \x1b[0m
Create a collection in the current Mongo Db.
\x1b[37m deleteCollection \x1b[0m
Delete a collection in the current Mongo Db.
\x1b[37m collectionExist \x1b[0m
Show if collection exits in the current Mongo DB.
\x1b[37m Collections \x1b[0m
Show all collections in the current Mongo DB.
\x1b[37m IsPublicAccess \x1b[0m
Show if the file has public access in the db.
\x1b[37m SetPublicAccess \x1b[0m
Set file's public access in the db.
\x1b[37m UnSetPublicAccess \x1b[0m
Unset file's public access in the db.
\x1b[37m CreatePublicAccess \x1b[0m
Create public access in DB for first time(One time per DB)
\x1b[37m ListPublicFiles \x1b[0m
Show the files in public folder.
\x1b[37m CopyPublicFile \x1b[0m
Copy one file in public folder, with other name(example: template file) inside public folder.
\x1b[37m DB_Backup \x1b[0m
Create Current Ernest DB Backup. Exports DB to a specific tar.gz file
\x1b[37m DB_Restore \x1b[0m
Restore Ernest DB from Backup. Imports DB from a specific tar.gz file
\x1b[37m man \x1b[0m
Show Ernest command info.
\x1b[37m clear \x1b[0m
Clear Ernest CLI.
\x1b[37m exit \x1b[0m
Stop Ernest an exit Ernest CLI.
`;
console.log(info);
cli.MainMenu();
};
};

@@ -911,28 +35,41 @@

function copyFile(src, dest,callback)
{
if (!fs.existsSync(src))
{
console.log("here1");
callback(true);
}
else
{
var data = fs.readFileSync(src, 'utf-8');
fs.writeFileSync(dest, data);
if (!fs.existsSync(dest))
{
callback(true);
}
else
{
callback(null);
};
};
};
function completer(line)
{
var completions = 'reloadREST dbCommand adminCommand serverStatus rsStatus addUser deleteUser deleteUserProperty showUser status pid onUser outUser db setdb updateUserPassword updateUserProperties addPagetoUser removePageUser createCollection deleteCollection collectionExist Collections IsPublicAccess SetPublicAccess UnSetPublicAccess CreatePublicAccess ListPublicFiles CopyPublicFile DB_Backup DB_Restore man clear exit'.split(' ');
var completions = [];
completions.push('addPagetoUser');
completions.push('addUser');
completions.push('adminCommand');
completions.push('clear');
completions.push('collectionExist');
completions.push('Collections');
completions.push('CopyPublicFile');
completions.push('createCollection');
completions.push('CreatePublicAccess');
completions.push('db');
completions.push('DB_Backup');
completions.push('DB_Restore');
completions.push('dbCommand');
completions.push('deleteCollection');
completions.push('deleteUser');
completions.push('deleteUserProperty');
completions.push('exit');
completions.push('IsPublicAccess');
completions.push('ListPublicFiles');
completions.push('log');
completions.push('logs');
completions.push('man');
completions.push('onUser');
completions.push('outUser');
completions.push('pid');
completions.push('reloadREST');
completions.push('removePageUser');
completions.push('rsStatus');
completions.push('serverStatus');
completions.push('setdb');
completions.push('SetPublicAccess');
completions.push('showUser');
completions.push('status');
completions.push('UnSetPublicAccess');
completions.push('updateUserPassword');
completions.push('updateUserProperties');
if(line.charAt(0)== "/")

@@ -939,0 +76,0 @@ {

@@ -158,3 +158,4 @@ "use strict";

crit[str_user] = req.session.user;
crit[url] = true;
crit[url] = {};
crit[url]['$gt']= 0;
_this.dbc.FindInCollection(crit,_this.access_col,function(e,r)

@@ -161,0 +162,0 @@ {

@@ -128,3 +128,3 @@ "use strict";

SetUserAccess(user,iurl,callback)
SetUserAccess(user,iurl,level,callback)
{

@@ -137,3 +137,3 @@ let url = iurl.replace(".","_").replace("/","");

set[str_set] = {};
set[str_set][url] = true;
set[str_set][url] = level;
_this.dbc.UpdateOneinCollec(crit,set,_this.access,function(e,d)

@@ -140,0 +140,0 @@ {

@@ -20,2 +20,4 @@ "use strict";

const Ernest_CSI = require('./Ernest_CSI');
const EventEmitter = require('events');

@@ -27,3 +29,3 @@

{
constructor(db_name,iport,jsonlimt_mb,session_name,session_secret)
constructor(db_name,iport,jsonlimt_mb,session_name,session_secret,logpath)
{

@@ -96,3 +98,3 @@ process.stdout.write('\x1Bc');

this.CLI = new Ernest_CLI(this);
this.CLI = new Ernest_CLI(this,logpath);

@@ -110,2 +112,4 @@ this.public = null;

this.templaters = [];
this.CSI = new Ernest_CSI(this,logpath,"ernestvserver","05102017");
};

@@ -340,2 +344,3 @@

_this.CLI.MainMenu();
_this.CSI.Start();
});

@@ -342,0 +347,0 @@ return this;

{
"_from": "ernest@^2.1.13",
"_id": "ernest@2.3.1",
"_from": "ernest@2.4.1",
"_id": "ernest@2.4.1",
"_inBundle": false,
"_integrity": "sha512-ms8THSUjgAS8p+wWw15r1i6jW/0mA5huL770hVbLJQI2ILEFghghk/ok4MMb+PYAzdGzPwY8uzPxTCA+DVwdoQ==",
"_integrity": "sha512-X2wFIIVEbq9/e62ML1PEt/hAiJ7ua3+zVkhi6o5FLKdZkuhDEc0Jd4Mi/Knyn6TA+USnAq9Xp8jBtfmBHatMew==",
"_location": "/ernest",
"_phantomChildren": {},
"_requested": {
"type": "range",
"type": "version",
"registry": true,
"raw": "ernest@^2.1.13",
"raw": "ernest@2.4.1",
"name": "ernest",
"escapedName": "ernest",
"rawSpec": "^2.1.13",
"rawSpec": "2.4.1",
"saveSpec": null,
"fetchSpec": "^2.1.13"
"fetchSpec": "2.4.1"
},

@@ -22,5 +22,5 @@ "_requiredBy": [

],
"_resolved": "https://registry.npmjs.org/ernest/-/ernest-2.3.1.tgz",
"_shasum": "11f6a8f4f8f60bdcc2c2c0d130ec9586544d74b6",
"_spec": "ernest@^2.1.13",
"_resolved": "https://registry.npmjs.org/ernest/-/ernest-2.4.1.tgz",
"_shasum": "4ae53a213459606d8bca62eb06393dd8916e8933",
"_spec": "ernest@2.4.1",
"_where": "/ernestv",

@@ -72,3 +72,3 @@ "author": {

},
"version": "2.4.1"
"version": "2.5.0"
}

@@ -76,3 +76,8 @@ var fs = require('fs');

};
let final = (req.session.user !== undefined) ? _this.views[originalUrl].replace("_session",JSON.stringify({userData,vars})):_this.views[originalUrl];
let prevfinal = (req.session.user !== undefined) ? _this.views[originalUrl].replace("_session",JSON.stringify({userData,vars})):_this.views[originalUrl];
let final = prevfinal;
if( (originalUrl + "_html") in userData)
{
final = _this.ByLevel(userData[originalUrl + "_html"],prevfinal);
};
return res.send( production ? final.replace(new RegExp('\n', 'g'),' ').replace(new RegExp('\t', 'g'),'') : final);

@@ -89,2 +94,34 @@ }

ByLevel(level,text)
{
let patternbegin = "_onUserLevel";
let base = text;
let pattern = RegExp(patternbegin + "\\[.*?\\]:((.|\n|\t)*?)::",'g');
let coincidences = base.match(pattern);
var pattern2 = RegExp(patternbegin + "\\[.*?\\]:",'g');
if(coincidences != null)
{
for(let i = 0; i< coincidences.length; i++ )
{
let cur = coincidences[i].match(pattern2);
let onLevel = Number(cur[0].replace(patternbegin + "[","").replace("]:",""));
if(level >= onLevel)
{
base = base.replace(coincidences[i],coincidences[i].replace(pattern2,"").replace("::",""))
}
else
{
base = base.replace(coincidences[i],"");
}
};
return base;
}
else
{
return text;
}
};
ContainsTemplatePattern(text,callback)

@@ -91,0 +128,0 @@ {