mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-14 17:58:02 -05:00
ignore unlisted TG
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -50,7 +50,8 @@ exports.listSystems = function (req, res, next) {
|
|||||||
country,
|
country,
|
||||||
userId,
|
userId,
|
||||||
key,
|
key,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}) => ({
|
}) => ({
|
||||||
name,
|
name,
|
||||||
shortName,
|
shortName,
|
||||||
@@ -62,7 +63,8 @@ exports.listSystems = function (req, res, next) {
|
|||||||
country,
|
country,
|
||||||
userId,
|
userId,
|
||||||
key,
|
key,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}))(obj);
|
}))(obj);
|
||||||
if (obj.showScreenName) {
|
if (obj.showScreenName) {
|
||||||
rObj.screenName = req.user.screenName;
|
rObj.screenName = req.user.screenName;
|
||||||
@@ -203,11 +205,7 @@ exports.ownSystem = async function (req, res, next) {
|
|||||||
console.error("System: " + system.userId + " User: " + req.user._id);
|
console.error("System: " + system.userId + " User: " + req.user._id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.test = "Yoho!"
|
|
||||||
res.locals.system = system;
|
res.locals.system = system;
|
||||||
console.log(system);
|
|
||||||
console.log(res.locals);
|
|
||||||
next();
|
next();
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -280,6 +278,7 @@ exports.updateSystem = async function (req, res, next) {
|
|||||||
res.locals.system.description = res.locals.description;
|
res.locals.system.description = res.locals.description;
|
||||||
res.locals.system.systemType = res.locals.systemType;
|
res.locals.system.systemType = res.locals.systemType;
|
||||||
res.locals.system.showScreenName = res.locals.showScreenName;
|
res.locals.system.showScreenName = res.locals.showScreenName;
|
||||||
|
res.locals.system.ignoreUnknownTalkgroup = res.locals.ignoreUnknownTalkgroup;
|
||||||
|
|
||||||
res.locals.system.save(function (err) {
|
res.locals.system.save(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
@@ -300,7 +299,8 @@ exports.updateSystem = async function (req, res, next) {
|
|||||||
country,
|
country,
|
||||||
userId,
|
userId,
|
||||||
key,
|
key,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}) => ({
|
}) => ({
|
||||||
name,
|
name,
|
||||||
shortName,
|
shortName,
|
||||||
@@ -312,7 +312,8 @@ exports.updateSystem = async function (req, res, next) {
|
|||||||
country,
|
country,
|
||||||
userId,
|
userId,
|
||||||
key,
|
key,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}))(res.locals.system);
|
}))(res.locals.system);
|
||||||
returnSys.id = res.locals.system._id;
|
returnSys.id = res.locals.system._id;
|
||||||
res.json({
|
res.json({
|
||||||
@@ -329,7 +330,7 @@ exports.updateSystem = async function (req, res, next) {
|
|||||||
exports.validateSystem = async function (req, res, next) {
|
exports.validateSystem = async function (req, res, next) {
|
||||||
try {
|
try {
|
||||||
res.locals.showScreenName = req.body.showScreenName;
|
res.locals.showScreenName = req.body.showScreenName;
|
||||||
|
res.locals.ignoreUnknownTalkgroup = req.body.ignoreUnknownTalkgroup ;
|
||||||
if (!req.body.name || (req.body.name.length < 2)) {
|
if (!req.body.name || (req.body.name.length < 2)) {
|
||||||
console.error("ERROR: Validate System - req.body.name");
|
console.error("ERROR: Validate System - req.body.name");
|
||||||
res.json({
|
res.json({
|
||||||
@@ -456,7 +457,8 @@ exports.createSystem = async function (req, res, next) {
|
|||||||
state,
|
state,
|
||||||
county,
|
county,
|
||||||
country,
|
country,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}) => ({
|
}) => ({
|
||||||
name,
|
name,
|
||||||
shortName,
|
shortName,
|
||||||
@@ -466,7 +468,8 @@ exports.createSystem = async function (req, res, next) {
|
|||||||
state,
|
state,
|
||||||
county,
|
county,
|
||||||
country,
|
country,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}))(res.locals);
|
}))(res.locals);
|
||||||
system.key = key;
|
system.key = key;
|
||||||
system.userId = mongoose.Types.ObjectId(req.user._id);
|
system.userId = mongoose.Types.ObjectId(req.user._id);
|
||||||
@@ -490,6 +493,7 @@ exports.createSystem = async function (req, res, next) {
|
|||||||
country,
|
country,
|
||||||
userId,
|
userId,
|
||||||
showScreenName,
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup ,
|
||||||
key
|
key
|
||||||
}) => ({
|
}) => ({
|
||||||
name,
|
name,
|
||||||
@@ -502,6 +506,7 @@ exports.createSystem = async function (req, res, next) {
|
|||||||
country,
|
country,
|
||||||
userId,
|
userId,
|
||||||
showScreenName,
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup ,
|
||||||
key
|
key
|
||||||
}))(newSys);
|
}))(newSys);
|
||||||
returnSys.id = newSys._id;
|
returnSys.id = newSys._id;
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ var systemSchema = mongoose.Schema({
|
|||||||
state: String,
|
state: String,
|
||||||
description: String,
|
description: String,
|
||||||
showScreenName: Boolean,
|
showScreenName: Boolean,
|
||||||
|
ignoreUnknownTalkgroup : Boolean,
|
||||||
userId: mongoose.Schema.Types.ObjectId,
|
userId: mongoose.Schema.Types.ObjectId,
|
||||||
key: String
|
key: String
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ class SystemForm extends Component {
|
|||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.handleInputChange = this.handleInputChange.bind(this);
|
this.handleInputChange = this.handleInputChange.bind(this);
|
||||||
this.handleCheckboxChange = this.handleCheckboxChange.bind(this);
|
this.handleScreenNameCheckboxChange = this.handleScreenNameCheckboxChange.bind(this);
|
||||||
|
this.handleTalkgroupCheckboxChange = this.handleTalkgroupCheckboxChange.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.handleSubmit = this.handleSubmit.bind(this);
|
||||||
this.checkInputs = this.checkInputs.bind(this);
|
this.checkInputs = this.checkInputs.bind(this);
|
||||||
this.render = this.render.bind(this);
|
this.render = this.render.bind(this);
|
||||||
@@ -30,6 +31,7 @@ class SystemForm extends Component {
|
|||||||
county: "",
|
county: "",
|
||||||
country: "",
|
country: "",
|
||||||
showScreenName: false,
|
showScreenName: false,
|
||||||
|
ignoreUnknownTalkgroup: false,
|
||||||
nameError: false,
|
nameError: false,
|
||||||
shortNameError: false,
|
shortNameError: false,
|
||||||
descriptionError: false,
|
descriptionError: false,
|
||||||
@@ -51,6 +53,7 @@ class SystemForm extends Component {
|
|||||||
this.state.county = this.props.system.county;
|
this.state.county = this.props.system.county;
|
||||||
this.state.country = this.props.system.country;
|
this.state.country = this.props.system.country;
|
||||||
this.state.showScreenName = this.props.system.showScreenName;
|
this.state.showScreenName = this.props.system.showScreenName;
|
||||||
|
this.state.ignoreUnknownTalkgroup = this.props.system.ignoreUnknownTalkgroup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If we directly to an updating url, the system fetch will come back after the constructer, so we need to catch this and update the values
|
// If we directly to an updating url, the system fetch will come back after the constructer, so we need to catch this and update the values
|
||||||
@@ -66,6 +69,7 @@ class SystemForm extends Component {
|
|||||||
county: this.props.system.county,
|
county: this.props.system.county,
|
||||||
country: this.props.system.country,
|
country: this.props.system.country,
|
||||||
showScreenName: this.props.system.showScreenName,
|
showScreenName: this.props.system.showScreenName,
|
||||||
|
ignoreUnknownTalkgroup: this.props.system.ignoreUnknownTalkgroup,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -148,10 +152,13 @@ class SystemForm extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
handleInputChange = (e, { name, value }) => this.setState({ [name]: value });
|
||||||
handleCheckboxChange() {
|
handleScreenNameCheckboxChange() {
|
||||||
this.setState({ showScreenName: !this.state.showScreenName });
|
this.setState({ showScreenName: !this.state.showScreenName });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleTalkgroupCheckboxChange() {
|
||||||
|
this.setState({ ignoreUnknownTalkgroup: !this.state.ignoreUnknownTalkgroup });
|
||||||
|
}
|
||||||
handleSubmit(event) {
|
handleSubmit(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
let inputError = this.checkInputs();
|
let inputError = this.checkInputs();
|
||||||
@@ -166,7 +173,8 @@ class SystemForm extends Component {
|
|||||||
state,
|
state,
|
||||||
county,
|
county,
|
||||||
country,
|
country,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}) => ({
|
}) => ({
|
||||||
name,
|
name,
|
||||||
shortName,
|
shortName,
|
||||||
@@ -176,7 +184,8 @@ class SystemForm extends Component {
|
|||||||
state,
|
state,
|
||||||
county,
|
county,
|
||||||
country,
|
country,
|
||||||
showScreenName
|
showScreenName,
|
||||||
|
ignoreUnknownTalkgroup
|
||||||
}))(this.state);
|
}))(this.state);
|
||||||
this.props.onSubmit(system);
|
this.props.onSubmit(system);
|
||||||
}
|
}
|
||||||
@@ -294,13 +303,16 @@ class SystemForm extends Component {
|
|||||||
</Form.Group>
|
</Form.Group>
|
||||||
<Divider horizontal />
|
<Divider horizontal />
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
|
|
||||||
<p>Your Screen Name: {this.props.screenName}</p>
|
|
||||||
<Checkbox
|
<Checkbox
|
||||||
onChange={this.handleCheckboxChange}
|
onChange={this.handleScreenNameCheckboxChange}
|
||||||
checked={this.state.showScreenName}
|
checked={this.state.showScreenName}
|
||||||
label="Show in System Listing" />
|
label="Display Screen Name in System Listing" />
|
||||||
|
</Form.Field>
|
||||||
|
<Form.Field>
|
||||||
|
<Checkbox
|
||||||
|
onChange={this.handleTalkgroupCheckboxChange}
|
||||||
|
checked={this.state.ignoreUnknownTalkgroup}
|
||||||
|
label="Ignore Unknown Talkgroups" />
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
<Divider horizontal />
|
<Divider horizontal />
|
||||||
<Form.TextArea
|
<Form.TextArea
|
||||||
@@ -386,19 +398,19 @@ class SystemForm extends Component {
|
|||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
) : (
|
) : (
|
||||||
<Form.Field>
|
<Form.Field>
|
||||||
<Form.Dropdown
|
<Form.Dropdown
|
||||||
name="state"
|
name="state"
|
||||||
onChange={this.handleInputChange}
|
onChange={this.handleInputChange}
|
||||||
error={this.state.stateError}
|
error={this.state.stateError}
|
||||||
value={this.state.state}
|
value={this.state.state}
|
||||||
options={stateOptions}
|
options={stateOptions}
|
||||||
scrolling
|
scrolling
|
||||||
label="State"
|
label="State"
|
||||||
placeholder="Select State..."
|
placeholder="Select State..."
|
||||||
/>
|
/>
|
||||||
</Form.Field>
|
</Form.Field>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ const system = (
|
|||||||
key: action.data.key,
|
key: action.data.key,
|
||||||
userId: action.data.userId,
|
userId: action.data.userId,
|
||||||
id: action.data.id,
|
id: action.data.id,
|
||||||
showScreenName: action.data.showScreenName
|
showScreenName: action.data.showScreenName,
|
||||||
|
ignoreUnknownTalkgroup : action.data.ignoreUnknownTalkgroup
|
||||||
});
|
});
|
||||||
return Object.assign({}, state, { isWaiting: false,
|
return Object.assign({}, state, { isWaiting: false,
|
||||||
items: newItems});
|
items: newItems});
|
||||||
|
|||||||
@@ -64,9 +64,11 @@ process.nextTick(function() {
|
|||||||
var shortName = req.params.shortName.toLowerCase();
|
var shortName = req.params.shortName.toLowerCase();
|
||||||
var apiKey = req.body.api_key;
|
var apiKey = req.body.api_key;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
System.findOne({
|
System.findOne({
|
||||||
'shortName': shortName
|
'shortName': shortName
|
||||||
}, async function(err, item) {
|
},["key", "ignoreUnknownTalkgroup"], async function(err, item) {
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
console.warn("[" + req.params.shortName + "] Error /:shortName/upload - Error: " + err);
|
console.warn("[" + req.params.shortName + "] Error /:shortName/upload - Error: " + err);
|
||||||
@@ -96,8 +98,31 @@ process.nextTick(function() {
|
|||||||
}
|
}
|
||||||
var startTime = req.body.start_time;
|
var startTime = req.body.start_time;
|
||||||
var emergency = parseInt(req.body.emergency);
|
var emergency = parseInt(req.body.emergency);
|
||||||
|
|
||||||
|
|
||||||
|
if (item.ignoreUnknownTalkgroup == true) {
|
||||||
|
console.log("ignore unknown talkgroup ");
|
||||||
|
//await Talkgroup.findOne({ answer: 42 }).select({ _id: 1 }).lean().then(doc => !!doc)
|
||||||
|
talkgroupExists = await Talkgroup.exists({
|
||||||
|
'shortName': shortName,
|
||||||
|
'num': talkgroupNum
|
||||||
|
});
|
||||||
|
console.log("In talkgroup: " + talkgroupExists);
|
||||||
|
//talkgroupExists = await Talkgroup.findOne({ 'shortName': shortName, 'num': talkgroupNum }).select({ _id: 1 }).lean().then(doc => !!doc).exec();
|
||||||
|
if (!talkgroupExists) {
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(req.file.path)
|
||||||
|
//file removed
|
||||||
|
} catch(err) {
|
||||||
|
console.log("[" + call.shortName + "] error deleting: " + req.file.path);
|
||||||
|
}
|
||||||
|
|
||||||
|
res.status(500);
|
||||||
|
res.send("Talkgroup does not exist, skipping.\n");
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
// Add in an API Key check
|
// Add in an API Key check
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -107,7 +132,6 @@ process.nextTick(function() {
|
|||||||
// Mongoose does not allow 'errors' to be used in the Schema for call. need to rename to error.
|
// Mongoose does not allow 'errors' to be used in the Schema for call. need to rename to error.
|
||||||
var badFreqList = JSON.parse(req.body.freq_list);
|
var badFreqList = JSON.parse(req.body.freq_list);
|
||||||
var freqList = badFreqList.map(obj =>{
|
var freqList = badFreqList.map(obj =>{
|
||||||
|
|
||||||
obj.error = obj.errors;
|
obj.error = obj.errors;
|
||||||
delete obj.errors;
|
delete obj.errors;
|
||||||
return obj;
|
return obj;
|
||||||
|
|||||||
395
backend/index.js
395
backend/index.js
@@ -44,9 +44,9 @@ io.origins((origin, callback) => {
|
|||||||
callback(null, true);
|
callback(null, true);
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
io.on('connection', function(socket){
|
io.on('connection', function (socket) {
|
||||||
//console.log('a user connected');
|
//console.log('a user connected');
|
||||||
socket.on('disconnect', function(){
|
socket.on('disconnect', function () {
|
||||||
//console.log('user disconnected');
|
//console.log('user disconnected');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -64,47 +64,47 @@ const client = new Twitter({
|
|||||||
client
|
client
|
||||||
.get("account/verify_credentials")
|
.get("account/verify_credentials")
|
||||||
.then(results => {
|
.then(results => {
|
||||||
console.log("results", results);
|
console.log("Connected to Twitter");
|
||||||
})
|
})
|
||||||
.catch(console.error);
|
.catch(console.error);
|
||||||
|
|
||||||
function getRole(req) {
|
function getRole(req) {
|
||||||
if (req.params.shortName && req.user) {
|
if (req.params.shortName && req.user) {
|
||||||
var short_name = req.params.shortName.toLowerCase();
|
var short_name = req.params.shortName.toLowerCase();
|
||||||
var userId = req.user._id;
|
var userId = req.user._id;
|
||||||
Permission.findOne({'userId': userId, 'shortName': short_name}, function(err, permission) {
|
Permission.findOne({ 'userId': userId, 'shortName': short_name }, function (err, permission) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error - getRole userId: ' + userId + ' shortName: ' + short_name + ' error: ' + err);
|
console.error('Error - getRole userId: ' + userId + ' shortName: ' + short_name + ' error: ' + err);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
console.log('Found - getRole userId: ' + userId + ' shortName: ' + short_name + ' role: ' + permission.role);
|
console.log('Found - getRole userId: ' + userId + ' shortName: ' + short_name + ' role: ' + permission.role);
|
||||||
|
|
||||||
return permission.role;
|
return permission.role;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function isUser(req, res, next) {
|
function isUser(req, res, next) {
|
||||||
if (req.params.shortName) {
|
if (req.params.shortName) {
|
||||||
var short_name = req.params.shortName.toLowerCase();
|
var short_name = req.params.shortName.toLowerCase();
|
||||||
System.findOne({'shortName': short_name}, function(err, system) {
|
System.findOne({ 'shortName': short_name }, function (err, system) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error - System not found: ' + short_name);
|
console.error('Error - System not found: ' + short_name);
|
||||||
res.status(505).send({
|
res.status(505).send({
|
||||||
|
success: false,
|
||||||
|
message: "System Not Found"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!system.private) return next();
|
||||||
|
|
||||||
|
// Looks like the system is private...
|
||||||
|
|
||||||
|
if (getRole(req) > 0) return next();
|
||||||
|
res.status(401).send({
|
||||||
success: false,
|
success: false,
|
||||||
message: "System Not Found"
|
message: "Insufficent Permission."
|
||||||
});
|
});
|
||||||
}
|
|
||||||
if (!system.private) return next();
|
|
||||||
|
|
||||||
// Looks like the system is private...
|
|
||||||
|
|
||||||
if (getRole(req) > 0) return next();
|
|
||||||
res.status(401).send({
|
|
||||||
success: false,
|
|
||||||
message: "Insufficent Permission."
|
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,13 +118,13 @@ configureExpress(app, passport)
|
|||||||
|
|
||||||
|
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
mongoose.connect(secrets.db, (err, res) => {
|
mongoose.connect(secrets.db, (err, res) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(`Error connecting to ${secrets.db}. ${err}`)
|
console.log(`Error connecting to ${secrets.db}. ${err}`)
|
||||||
} else {
|
} else {
|
||||||
console.log(`Successfully connected to ${secrets.db}.`)
|
console.log(`Successfully connected to ${secrets.db}.`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
connect()
|
connect()
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ mongoose.connection.on("disconnected", connect)
|
|||||||
|
|
||||||
|
|
||||||
var upload = multer({
|
var upload = multer({
|
||||||
dest: config.uploadDirectory
|
dest: config.uploadDirectory
|
||||||
});
|
});
|
||||||
|
|
||||||
var clients = [];
|
var clients = [];
|
||||||
@@ -141,7 +141,7 @@ var clients = [];
|
|||||||
function addSystemClients(req, res, next) {
|
function addSystemClients(req, res, next) {
|
||||||
var systemClients = {};
|
var systemClients = {};
|
||||||
for (var key in clients) {
|
for (var key in clients) {
|
||||||
if (clients.hasOwnProperty(key)) {
|
if (clients.hasOwnProperty(key)) {
|
||||||
const client = clients[key];
|
const client = clients[key];
|
||||||
const shortName = client.shortName;
|
const shortName = client.shortName;
|
||||||
if (client.active) {
|
if (client.active) {
|
||||||
@@ -168,20 +168,20 @@ app.get('/:shortName/calls/newer', calls.get_newer_calls);
|
|||||||
app.get('/:shortName/calls/older', calls.get_older_calls);
|
app.get('/:shortName/calls/older', calls.get_older_calls);
|
||||||
app.get('/:shortName/calls/:time/older', calls.get_iphone_calls);
|
app.get('/:shortName/calls/:time/older', calls.get_iphone_calls);
|
||||||
app.get('/:shortName/calls', calls.get_calls);
|
app.get('/:shortName/calls', calls.get_calls);
|
||||||
app.post('/:shortName/star/:id', calls.add_star, function(req,res) {
|
app.post('/:shortName/star/:id', calls.add_star, function (req, res) {
|
||||||
notify_clients(req.call);
|
notify_clients(req.call);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
/*------ UPLOADS ---------- upload.single('call'), uploads.upload,*/
|
/*------ UPLOADS ---------- upload.single('call'), uploads.upload,*/
|
||||||
app.post('/:shortName/upload', upload.single('call'), uploads.upload, async function(req,res) {
|
app.post('/:shortName/upload', upload.single('call'), uploads.upload, async function (req, res) {
|
||||||
notify_clients(req.call);
|
notify_clients(req.call);
|
||||||
if ((req.call.shortName=="dcfd") && (req.call.talkgroupNum==101) ) {
|
if ((req.call.shortName == "dcfd") && (req.call.talkgroupNum == 101)) {
|
||||||
var call_time = new Date(req.call.time);
|
var call_time = new Date(req.call.time);
|
||||||
var call_link = "https://openmhz.com/system/dcfd?call-id=" + req.call._id + "&time=" + call_time.getTime();
|
var call_link = "https://openmhz.com/system/dcfd?call-id=" + req.call._id + "&time=" + call_time.getTime();
|
||||||
|
|
||||||
var call_time_label = call_time.toLocaleDateString('en-US', {timeZone: "America/New_York"}) + " " + call_time.toLocaleTimeString('en-US', {timeZone: "America/New_York"})
|
var call_time_label = call_time.toLocaleDateString('en-US', { timeZone: "America/New_York" }) + " " + call_time.toLocaleTimeString('en-US', { timeZone: "America/New_York" })
|
||||||
var status = req.call.len +" sec transmission\n" + call_time_label + "\n" + call_link;
|
var status = req.call.len + " sec transmission\n" + call_time_label + "\n" + call_link;
|
||||||
const response = await client.post('statuses/update', {
|
const response = await client.post('statuses/update', {
|
||||||
status: status,
|
status: status,
|
||||||
});
|
});
|
||||||
@@ -200,41 +200,41 @@ app.get('/:shortName/groups', groups.get_groups);
|
|||||||
|
|
||||||
|
|
||||||
/*------ STATS ----------*/
|
/*------ STATS ----------*/
|
||||||
app.get('/:shortName/errors',stats.get_errors);
|
app.get('/:shortName/errors', stats.get_errors);
|
||||||
app.get('/:shortName/stats', stats.get_stats);
|
app.get('/:shortName/stats', stats.get_stats);
|
||||||
|
|
||||||
|
|
||||||
function get_clients(req, res) {
|
function get_clients(req, res) {
|
||||||
if (req.params.shortName) {
|
if (req.params.shortName) {
|
||||||
var short_name = req.params.shortName.toLowerCase();
|
var short_name = req.params.shortName.toLowerCase();
|
||||||
} else {
|
} else {
|
||||||
var short_name = null;
|
var short_name = null;
|
||||||
}
|
}
|
||||||
var total = 0;
|
var total = 0;
|
||||||
var response = [];
|
var response = [];
|
||||||
for (var key in clients) {
|
for (var key in clients) {
|
||||||
if (clients.hasOwnProperty(key)) {
|
if (clients.hasOwnProperty(key)) {
|
||||||
total++;
|
total++;
|
||||||
if (!short_name || (clients[key].shortName == short_name)) {
|
if (!short_name || (clients[key].shortName == short_name)) {
|
||||||
var age = (Date.now() - clients[key].timestamp) / 1000;
|
var age = (Date.now() - clients[key].timestamp) / 1000;
|
||||||
var obj = {
|
var obj = {
|
||||||
shortName: clients[key].shortName,
|
shortName: clients[key].shortName,
|
||||||
filterCode: clients[key].filterCode,
|
filterCode: clients[key].filterCode,
|
||||||
filterName: clients[key].filterName,
|
filterName: clients[key].filterName,
|
||||||
filterType: clients[key].filterType,
|
filterType: clients[key].filterType,
|
||||||
filterStarred: clients[key].filterStarred,
|
filterStarred: clients[key].filterStarred,
|
||||||
active: clients[key].active,
|
active: clients[key].active,
|
||||||
talkgroupNums: clients[key].talkgroupNums,
|
talkgroupNums: clients[key].talkgroupNums,
|
||||||
timestamp: age
|
timestamp: age
|
||||||
}
|
|
||||||
response.push(obj);
|
|
||||||
}
|
}
|
||||||
|
response.push(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response.push({"total": total});
|
}
|
||||||
|
response.push({ "total": total });
|
||||||
|
|
||||||
res.contentType('json');
|
res.contentType('json');
|
||||||
res.send(JSON.stringify(response));
|
res.send(JSON.stringify(response));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*------ CLIENTS ----------*/
|
/*------ CLIENTS ----------*/
|
||||||
@@ -243,75 +243,73 @@ app.get('/:shortName/clients', get_clients);
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.use(function(err, req, res, next) {
|
app.use(function (err, req, res, next) {
|
||||||
console.error("Caught an error");
|
console.error("Caught an error");
|
||||||
console.error(err.stack);
|
console.error(err.stack);
|
||||||
/*
|
/*
|
||||||
res.status(err.status || 500);
|
res.status(err.status || 500);
|
||||||
res.contentType('json');
|
res.contentType('json');
|
||||||
res.send(JSON.stringify({
|
res.send(JSON.stringify({
|
||||||
message: err.message,
|
message: err.message,
|
||||||
error: err
|
error: err
|
||||||
}));*/
|
}));*/
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
app.get('/:shortName/clients', get_clients);
|
app.get('/:shortName/clients', get_clients);
|
||||||
app.get('/clients', get_clients);
|
app.get('/clients', get_clients);
|
||||||
|
|
||||||
function notify_clients(call) {
|
function notify_clients(call) {
|
||||||
call.type = "calls";
|
call.type = "calls";
|
||||||
var sent = 0;
|
var sent = 0;
|
||||||
|
|
||||||
for (var key in clients) {
|
for (var key in clients) {
|
||||||
if (clients.hasOwnProperty(key)) {
|
if (clients.hasOwnProperty(key)) {
|
||||||
var client = clients[key];
|
var client = clients[key];
|
||||||
if (client.active) {
|
if (client.active) {
|
||||||
if (client.shortName == call.shortName.toLowerCase()) {
|
if (client.shortName == call.shortName.toLowerCase()) {
|
||||||
// if client is not filtering for stars, or if the client is filtering and the call has stars
|
// if client is not filtering for stars, or if the client is filtering and the call has stars
|
||||||
if (!client.filterStarred || call.star) {
|
if (!client.filterStarred || call.star) {
|
||||||
if (client.filterCode == "") {
|
if (client.filterCode == "") {
|
||||||
sent++;
|
sent++;
|
||||||
|
client.socket.emit("new message", JSON.stringify(call));
|
||||||
|
} else if (client.filterType == "unit") {
|
||||||
|
var codeArray = client.filterCode.split(',');
|
||||||
|
var success = false;
|
||||||
|
for (var j = 0; j < codeArray.length; ++j) {
|
||||||
|
for (var k = 0; k < call.srcList.length; k++) {
|
||||||
|
if (codeArray[j] == call.srcList[k]) {
|
||||||
|
sent++;
|
||||||
|
client.socket.emit("new message", JSON.stringify(call));
|
||||||
|
success = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (success) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
var codeArray = client.talkgroupNums;
|
||||||
|
for (var j = 0; j < codeArray.length; ++j) {
|
||||||
|
if (codeArray[j] == call.talkgroupNum) {
|
||||||
client.socket.emit("new message", JSON.stringify(call));
|
client.socket.emit("new message", JSON.stringify(call));
|
||||||
} else if (client.filterType == "unit") {
|
sent++
|
||||||
var codeArray = client.filterCode.split(',');
|
break;
|
||||||
var success = false;
|
}
|
||||||
for (var j = 0; j < codeArray.length; ++j) {
|
|
||||||
for (var k = 0; k < call.srcList.length; k++) {
|
|
||||||
if (codeArray[j] == call.srcList[k]) {
|
|
||||||
sent++;
|
|
||||||
client.socket.emit("new message", JSON.stringify(call));
|
|
||||||
success = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (success) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
var codeArray = client.talkgroupNums;
|
|
||||||
for (var j = 0; j < codeArray.length; ++j) {
|
|
||||||
if (codeArray[j] == call.talkgroupNum) {
|
|
||||||
client.socket.emit("new message", JSON.stringify(call));
|
|
||||||
sent++
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sent > 0) {
|
||||||
if (sent > 0) {
|
//console.log("[" + call.shortName.toLowerCase() + "] Sent call to " + sent + " clients");
|
||||||
//console.log("[" + call.shortName.toLowerCase() + "] Sent call to " + sent + " clients");
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -321,93 +319,90 @@ function notify_clients(call) {
|
|||||||
|
|
||||||
|
|
||||||
io.sockets.on('connection', function (client) {
|
io.sockets.on('connection', function (client) {
|
||||||
clients[client.id] = {socket: client, active: false};
|
clients[client.id] = { socket: client, active: false };
|
||||||
clients[client.id].timestamp = new Date();
|
clients[client.id].timestamp = new Date();
|
||||||
client.on('start', function (data) {
|
client.on('start', function (data) {
|
||||||
if (clients[client.id] && data.shortName) {
|
if (clients[client.id] && data.shortName) {
|
||||||
clients[client.id].active = true;
|
clients[client.id].active = true;
|
||||||
clients[client.id].shortName = data.shortName.toLowerCase();
|
clients[client.id].shortName = data.shortName.toLowerCase();
|
||||||
clients[client.id].filterCode = String(data.filterCode);
|
clients[client.id].filterCode = String(data.filterCode);
|
||||||
clients[client.id].filterName = data.filterName;
|
clients[client.id].filterName = data.filterName;
|
||||||
clients[client.id].filterStarred = data.filterStarred;
|
clients[client.id].filterStarred = data.filterStarred;
|
||||||
clients[client.id].filterType = String(data.filterType);
|
clients[client.id].filterType = String(data.filterType);
|
||||||
clients[client.id].talkgroupNums = [];
|
clients[client.id].talkgroupNums = [];
|
||||||
clients[client.id].timestamp = new Date();
|
clients[client.id].timestamp = new Date();
|
||||||
if ((data.filterType == "group") && (data.filterCode.indexOf(',') == -1)) {
|
if ((data.filterType == "group") && (data.filterCode.indexOf(',') == -1)) {
|
||||||
db.get().collection("groups", function(err, groupCollection) {
|
db.get().collection("groups", function (err, groupCollection) {
|
||||||
if (err || !groupCollection) {
|
if (err || !groupCollection) {
|
||||||
console.error("Error - unable to open groups collection: " + err);
|
console.error("Error - unable to open groups collection: " + err);
|
||||||
delete clients[client.id];
|
delete clients[client.id];
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
if (!ObjectID.isValid(data.filterCode)) {
|
|
||||||
console.error("Error - Socket - Invalid Group ID: " + data.filterCode);
|
|
||||||
delete clients[client.id];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
groupCollection.findOne({
|
|
||||||
'shortName': data.shortName.toLowerCase(),
|
|
||||||
'_id': ObjectID.createFromHexString(data.filterCode)
|
|
||||||
}, function(err, group) {
|
|
||||||
if (err) {
|
|
||||||
console.warn("[" + data.shortName.toLowerCase() + "] Error - WebSocket Group ID not Found! Error: " + err + " Group ID: " + data.filterCode);
|
|
||||||
delete clients[client.id];
|
|
||||||
return;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (group && clients[client.id]) {
|
|
||||||
|
|
||||||
clients[client.id].talkgroupNums = group.talkgroups;
|
|
||||||
} else {
|
|
||||||
console.error("Error - Socket: Invalid group or Client: " + data.filterCode + " Shortname: " + data.shortName + " ClientID: " + client.id);
|
|
||||||
delete clients[client.id];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
} if ((data.filterType == "talkgroup") && Array.isArray(data.filterCode)) {
|
|
||||||
|
|
||||||
clients[client.id].talkgroupNums = data.filterCode;
|
|
||||||
}
|
|
||||||
//console.log("[" + data.shortName.toLowerCase() + "] WebSocket Updating - Client: " + client.id + " code set to: " + data.filterCode + " type set to: " + data.filterType + " TGS: " + clients[client.id].talkgroupNums);
|
|
||||||
} else{
|
|
||||||
console.error("Error - Socket.io [Start] either client not found or no Short Name");
|
|
||||||
}
|
}
|
||||||
});
|
if (!ObjectID.isValid(data.filterCode)) {
|
||||||
client.on('stop', function (data) {
|
console.error("Error - Socket - Invalid Group ID: " + data.filterCode);
|
||||||
if (clients[client.id] ) {
|
delete clients[client.id];
|
||||||
clients[client.id].active = false;
|
return;
|
||||||
} else{
|
}
|
||||||
console.error("Error - Socket.io [Stop] either client not found ");
|
groupCollection.findOne({
|
||||||
|
'shortName': data.shortName.toLowerCase(),
|
||||||
|
'_id': ObjectID.createFromHexString(data.filterCode)
|
||||||
|
}, function (err, group) {
|
||||||
|
if (err) {
|
||||||
|
console.warn("[" + data.shortName.toLowerCase() + "] Error - WebSocket Group ID not Found! Error: " + err + " Group ID: " + data.filterCode);
|
||||||
|
delete clients[client.id];
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
if (group && clients[client.id]) {
|
||||||
|
clients[client.id].talkgroupNums = group.talkgroups;
|
||||||
|
} else {
|
||||||
|
console.error("Error - Socket: Invalid group or Client: " + data.filterCode + " Shortname: " + data.shortName + " ClientID: " + client.id);
|
||||||
|
delete clients[client.id];
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
} if ((data.filterType == "talkgroup") && Array.isArray(data.filterCode)) {
|
||||||
|
clients[client.id].talkgroupNums = data.filterCode;
|
||||||
}
|
}
|
||||||
});
|
//console.log("[" + data.shortName.toLowerCase() + "] WebSocket Updating - Client: " + client.id + " code set to: " + data.filterCode + " type set to: " + data.filterType + " TGS: " + clients[client.id].talkgroupNums);
|
||||||
client.on('disconnect', function() {
|
} else {
|
||||||
delete clients[client.id];
|
console.error("Error - Socket.io [Start] either client not found or no Short Name");
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
client.on('stop', function (data) {
|
||||||
|
if (clients[client.id]) {
|
||||||
|
clients[client.id].active = false;
|
||||||
|
} else {
|
||||||
|
console.error("Error - Socket.io [Stop] either client not found ");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
client.on('disconnect', function () {
|
||||||
|
delete clients[client.id];
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
//console.log("stats: " + util.inspect(call_stats));
|
//console.log("stats: " + util.inspect(call_stats));
|
||||||
// Connect to Mongo on start
|
// Connect to Mongo on start
|
||||||
db.connect(function(err) {
|
db.connect(function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log('Unable to connect to Mongo.')
|
console.log('Unable to connect to Mongo.')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
} else {
|
} else {
|
||||||
stats.init_stats();
|
stats.init_stats();
|
||||||
|
|
||||||
server.listen(app.get("port"), (err) => {
|
server.listen(app.get("port"), (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.err(err.stack)
|
console.err(err.stack)
|
||||||
} else {
|
} else {
|
||||||
console.log(`App listening on port ${app.get("port")} [${process.env.NODE_ENV} mode]`)
|
console.log(`App listening on port ${app.get("port")} [${process.env.NODE_ENV} mode]`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ var systemSchema = mongoose.Schema({
|
|||||||
showScreenName: Boolean,
|
showScreenName: Boolean,
|
||||||
callAvg: Number,
|
callAvg: Number,
|
||||||
callCount: Number,
|
callCount: Number,
|
||||||
|
ignoreUnknownTalkgroup : Boolean,
|
||||||
active: {type: Boolean, default: false},
|
active: {type: Boolean, default: false},
|
||||||
planType: {type: Number, default: 0},
|
planType: {type: Number, default: 0},
|
||||||
userId: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
userId: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
var mongoose = require('mongoose');
|
var mongoose = require('mongoose');
|
||||||
var bcrypt = require('bcrypt-nodejs');
|
|
||||||
|
|
||||||
var talkgroupSchema = mongoose.Schema({
|
var talkgroupSchema = mongoose.Schema({
|
||||||
shortName: String,
|
shortName: String,
|
||||||
|
|||||||
2313
backend/package-lock.json
generated
2313
backend/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -20,7 +20,7 @@
|
|||||||
"get-folder-size": "^1.0.0",
|
"get-folder-size": "^1.0.0",
|
||||||
"mkdirp": "^0.5.1",
|
"mkdirp": "^0.5.1",
|
||||||
"mongodb": "2.2.36",
|
"mongodb": "2.2.36",
|
||||||
"mongoose": "5.3.12",
|
"mongoose": "5.12.3",
|
||||||
"multer": "1.3.0",
|
"multer": "1.3.0",
|
||||||
"node-ffprobe": "github:ListenerApproved/node-ffprobe",
|
"node-ffprobe": "github:ListenerApproved/node-ffprobe",
|
||||||
"node-schedule": "1.2.4",
|
"node-schedule": "1.2.4",
|
||||||
|
|||||||
1386
backend/yarn.lock
1386
backend/yarn.lock
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user