Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Dependencies
node_modules/

# Build output
dist/
build/

# Logs
logs/
*.log
npm-debug.log*

# OS files
.DS_Store
Thumbs.db

# IDE
.idea/
.vscode/
*.swp
*.swo

# Environment
.env
.env.local
.env.*.local

# Test
coverage/
.nyc_output/

# Temporary files
tmp/
temp/
*.tmp
12 changes: 6 additions & 6 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#!/usr/bin/env node
require('../settings');
var path = require('path'),
const path = require('path'),
fs = require('fs'),
os = require('os'),
osHomedir = os.homedir(),
package = require("../package.json"),
Spinner = require('cli-spinner').Spinner,
altSettings = path.resolve(osHomedir,"."+package.name+".json");

var spinner = new Spinner();
const spinner = new Spinner();
spinner.setSpinnerString('|/-\\');

const colors = require('colors'),
emoji = require('node-emoji'),
name = package.name;


var daemon = require("daemonize2").setup({
const daemon = require("daemonize2").setup({
main: path.resolve(__dirname,'..','index.js'),
name: name,
silent:true,
Expand Down Expand Up @@ -61,9 +61,9 @@ switch((process.argv[2]||"").replace(/^(-|--|\/)/,"")){
daemon.on("started",function(){
spinner.stop();
process.stdout.write(emoji.get('+1')+' \n');
var interfaces = os.getNetworkInterfaces();
interfaces = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family == 'IPv4').map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");
console.log("Web interfaces at : http://"+interfaces+":"+settings.httpPort);
const interfaces = os.networkInterfaces();
const interfacesList = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family === 'IPv4').map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

In Node.js versions 18.0.0 through 18.3.0, the family property returned by os.networkInterfaces() is a number (4 or 6) rather than a string ('IPv4' or 'IPv6'). Since the project's engines field in package.json now specifies node: ">=18.0.0", using strict equality x.family === 'IPv4' will fail to match any IPv4 interfaces on those Node.js versions. To ensure compatibility across all Node.js 18+ versions, check for both 'IPv4' and 4.

Suggested change
const interfacesList = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family === 'IPv4').map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");
const interfacesList = Object.keys(interfaces).map(x=>interfaces[x].filter(x=>x.family === 'IPv4' || x.family === 4).map(x=>x.address).join(":"+settings.httpPort+", http://")).filter(x=>x).join(":"+settings.httpPort+", http://");

console.log("Web interfaces at : http://"+interfacesList+":"+settings.httpPort);
process.exit();
})
spinner.setSpinnerTitle('%s Server start... ');
Expand Down
6 changes: 3 additions & 3 deletions bin/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ boxSMS.on('submit', function(data) {
'source_addr': from,
'destination_addr': to,
'sm_length': Buffer.byteLength(message),
'short_message': new Buffer(message)
'short_message': Buffer.from(message)
});
log('Submit message[id:'+id+']', 'to', client,':',message);
boxSMS.render();
Expand Down Expand Up @@ -470,7 +470,7 @@ async function main(){
// 'source_addr': from,
// 'destination_addr': to,
// 'sm_length': Buffer.byteLength(message),
// 'short_message': new Buffer(message)
// 'short_message': Buffer.from(message)
// });
// log("SMS sent");
// }
Expand Down Expand Up @@ -508,7 +508,7 @@ async function main(){
// 'source_addr': parts[0],
// 'destination_addr': parts[1],
// 'sm_length': Buffer.byteLength(message),
// 'short_message': new Buffer(message)
// 'short_message': Buffer.from(message)
// });
// });

Expand Down
30 changes: 15 additions & 15 deletions connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function initVm(j){
VMs[j].send({type:"settings", data:settings});
VMs[j].on('message', (function(m) {
if (m.type === 'sms'){
this.sendSMS(m,new Buffer(m.receiver).toString());
this.sendSMS(m,Buffer.from(m.receiver).toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If m.receiver is undefined or null, calling Buffer.from(m.receiver) will throw a TypeError and crash the process. Provide a fallback value (such as an empty string) to prevent runtime exceptions.

Suggested change
this.sendSMS(m,Buffer.from(m.receiver).toString());
this.sendSMS(m,Buffer.from(m.receiver || "").toString());

}
}).bind(this));
VMs[j].on('error',(function(j){
Expand Down Expand Up @@ -121,7 +121,7 @@ Object.defineProperties(Connector.prototype, {
},
sendSMS : {
value: function(data,id){
console.log("send SMS",new Buffer(data.receiver).toString(),new Buffer(data.sender).toString(),data.msgdata.toString());
console.log("send SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If data.receiver or data.sender is undefined or null, Buffer.from() will throw a TypeError. Additionally, if data.msgdata is undefined or null, calling .toString() on it will throw a TypeError. Use defensive guards or fallback values to prevent potential runtime crashes.

Suggested change
console.log("send SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());
console.log("send SMS",Buffer.from(data && data.receiver || "").toString(),Buffer.from(data && data.sender || "").toString(),(data && data.msgdata || "").toString());

this.emit("stats++",id);
this._sendSMS(data);
},
Expand All @@ -134,10 +134,10 @@ Object.defineProperties(Connector.prototype, {
try{this.emit("sendSMS",data);}catch(e){console.log("Error",e)}
new Models.SMS({
pdu: data,
sms : new Buffer(data.msgdata || "").toString(),
from: new Buffer(data.sender || "").toString(),
to: new Buffer(data.receiver || "").toString(),
SMSC: new Buffer(data.smsc_id || "").toString(),
sms : Buffer.from(data.msgdata || "").toString(),
from: Buffer.from(data.sender || "").toString(),
to: Buffer.from(data.receiver || "").toString(),
SMSC: Buffer.from(data.smsc_id || "").toString(),
MotCle : "",
success : false,
received : false
Expand All @@ -156,10 +156,10 @@ Object.defineProperties(Connector.prototype, {
try{this.emit("failSMS",data,raison);}catch(e){};
var save = {
pdu: data,
sms : new Buffer(data.msgdata || "").toString(),
from: new Buffer(data.sender || "").toString(),
to: new Buffer(data.receiver || "").toString(),
SMSC: new Buffer(data.smsc_id || "").toString(),
sms : Buffer.from(data.msgdata || "").toString(),
from: Buffer.from(data.sender || "").toString(),
to: Buffer.from(data.receiver || "").toString(),
SMSC: Buffer.from(data.smsc_id || "").toString(),
MotCle : "",
success : false,
raison : raison
Expand All @@ -178,10 +178,10 @@ Object.defineProperties(Connector.prototype, {
try{this.emit("successSMS",data);}catch(e){}
new Models.SMS({
pdu: data,
sms : new Buffer(data.msgdata || "").toString(),
from: new Buffer(data.sender || "").toString(),
to: new Buffer(data.receiver || "").toString(),
SMSC: new Buffer(data.smsc_id || "").toString(),
sms : Buffer.from(data.msgdata || "").toString(),
from: Buffer.from(data.sender || "").toString(),
to: Buffer.from(data.receiver || "").toString(),
SMSC: Buffer.from(data.smsc_id || "").toString(),
MotCle : keyword,
script : script,
success : true
Expand All @@ -197,7 +197,7 @@ Object.defineProperties(Connector.prototype, {
runSMS : {
value : function(data,err,items){
var id = (data && data.receiver ? data.receiver : "unknow").toString();
console.log("receive SMS",new Buffer(data.receiver).toString(),new Buffer(data.sender).toString(),data.msgdata.toString());
console.log("receive SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If data is null/undefined, or if data.receiver or data.sender is null/undefined, calling Buffer.from() or .toString() will throw a TypeError and crash the application. Since line 199 explicitly guards against data and data.receiver being undefined, line 200 must also be made safe to prevent runtime crashes.

Suggested change
console.log("receive SMS",Buffer.from(data.receiver).toString(),Buffer.from(data.sender).toString(),data.msgdata.toString());
console.log("receive SMS",Buffer.from(data && data.receiver || "").toString(),Buffer.from(data && data.sender || "").toString(),(data && data.msgdata || "").toString());

this.emit("stats--",id);
if(err || !items)
return this.failSMS(data, err ? err : "Pas d'items" );
Expand Down
2 changes: 1 addition & 1 deletion memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ Client.prototype.store = function(cmd, key, value, callback, lifetime, flags)

var set_flags = flags || 0;
var exp_time = lifetime || 0;
var tml_buf = new Buffer(value.toString());
var tml_buf = Buffer.from(value.toString());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If value is null or undefined, calling value.toString() will throw a TypeError. Guard against null or undefined values before calling toString().

Suggested change
var tml_buf = Buffer.from(value.toString());
var tml_buf = Buffer.from((value !== undefined && value !== null ? value : "").toString());

var value_len = tml_buf.length || 0;
var query = [cmd, this.scope+key, set_flags, exp_time, value_len];

Expand Down
69 changes: 31 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scriptbox",
"version": "0.0.4",
"version": "0.0.5",
"description": "Scriptbox is a full VAS application",
"author": "Ulrich Badinga <badinga.ulrich@gmail.com>",
"preferGlobal": true,
Expand All @@ -26,61 +26,54 @@
"script"
],
"engines": {
"node": ">=0.8.0"
"node": ">=18.0.0"
},
"repository": {
"type": "git",
"url": "http://github.com/badlee/scriptbox.git"
},
"dependencies": {
"MD5": "^1.2.1",
"alasql": "^0.4.11",
"arango": "^1.3.4",
"MD5": "^1.3.0",
"alasql": "^0.7.0",
"blessed": "^0.1.81",
"body-parser": "^1.0.2",
"body-parser": "^1.20.2",
"caminte": "^0.2.3",
"cassandra-driver": "^3.5.0",
"cli-spinner": "^0.2.6",
"coffee-script": "1.7.1",
"colors": "^0.6.2",
"compression": "^1.0.1",
"cassandra-driver": "^4.7.0",
"cli-spinner": "^0.2.10",
"coffee-script": "^1.12.7",
"colors": "^1.4.0",
"compression": "^1.7.4",
"connect-caminte": "0.0.3-2",
"connect-flash": "^0.1.1",
"connect-session-file": "^1.0.4",
"cookie-parser": "^1.0.1",
"couchbase": "^2.5.1",
"cookie-parser": "^1.4.6",
"couchbase": "^11.0.0",
"daemonize2": "^0.4.2",
"express": "^4.0.0",
"express-session": "^1.8.2",
"inquirer": "^6.2.0",
"express": "^4.18.2",
"express-session": "^1.17.3",
"inquirer": "^8.2.5",
"inquirer-select-line": "^1.1.1",
"kannel": "0.0.5",
"method-override": "^2.3.10",
"modem": "^1.0.3",
"mongodb": "^3.1.4",
"mongoose": "^5.7.5",
"morgan": "^1.9.1",
"mysql": "^2.16.0",
"nano": "^7.0.0",
"neo4j": "^2.0.0-RC2",
"node-emoji": "^1.8.1",
"node-firebird": "^0.8.6",
"nodejs-gravatar": "^1.0.2",
"passport": "^0.2.0",
"md5": "^2.3.0",
"method-override": "^3.0.0",
"mongodb": "^6.3.0",
"mongoose": "^8.0.3",
"morgan": "^1.10.0",
"mysql": "^2.18.1",
"nano": "^11.0.0",
"node-emoji": "^2.1.0",
"passport": "^0.7.0",
"passport-local": "^1.0.0",
"pg": "^7.4.3",
"randomstring": "^1.0.3",
"redis": "^2.8.0",
"rethinkdb": "^2.3.3",
"riak-js": "^1.1.0",
"serve-favicon": "^2.1.4",
"pg": "^8.11.3",
"randomstring": "^1.3.0",
"redis": "^4.6.11",
"serve-favicon": "^2.5.0",
"shorty": "https://github.com/badlee/shorty/archive/0.5.6.tar.gz",
"smpp": "^0.1.0",
"socket.io": "^2.1.1",
"sqlite3": "^4.0.2",
"string": "^1.8.1",
"socket.io": "^4.7.4",
"sqlite3": "^5.1.6",
"string": "^3.3.3",
"swig": "https://github.com/badlee/swig/archive/0.1.0.tar.gz",
"tasktimer": "^1.0.0",
"tingodb": "^0.2.2"
},
"bugs": {
Expand Down
8 changes: 4 additions & 4 deletions vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,9 @@ var lang = false;
}else if (m.type === 'sms'){
// console.log("recieve SMS",m.time);
m.msgdata_orig = m.msgdata;
m.msgdata = new Buffer(m.msgdata).toString().trim();
m.receiver = new Buffer(m.receiver).toString().toLowerCase();
m.sender = new Buffer(m.sender).toString().toLowerCase();
m.msgdata = Buffer.from(m.msgdata).toString().trim();
m.receiver = Buffer.from(m.receiver).toString().toLowerCase();
m.sender = Buffer.from(m.sender).toString().toLowerCase();
Comment on lines +146 to +148

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If m.msgdata, m.receiver, or m.sender is undefined or null, Buffer.from() will throw a TypeError and crash the VM process. Use fallback values to ensure robustness.

Suggested change
m.msgdata = Buffer.from(m.msgdata).toString().trim();
m.receiver = Buffer.from(m.receiver).toString().toLowerCase();
m.sender = Buffer.from(m.sender).toString().toLowerCase();
m.msgdata = Buffer.from(m.msgdata || "").toString().trim();
m.receiver = Buffer.from(m.receiver || "").toString().toLowerCase();
m.sender = Buffer.from(m.sender || "").toString().toLowerCase();

var priv = Symbol(m.sender);
m[priv] = true;
m.fileType = m.script.type;
Expand All @@ -168,7 +168,7 @@ var lang = false;
}).bind(null,m.file,sendError));
}
/* definition de la session et du storage */
var _id = new Buffer(m.sender).toString();
var _id = Buffer.from(m.sender).toString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If m.sender is undefined or null, Buffer.from(m.sender) will throw a TypeError. Provide a fallback value to prevent runtime crashes.

Suggested change
var _id = Buffer.from(m.sender).toString();
var _id = Buffer.from(m.sender || "").toString();

m.filename = path.basename(m.file);
var MSG = function(conf){
conf = conf || {};
Expand Down