2015-11-11 06:05:42 +00:00
|
|
|
|
|
|
|
{
|
2015-11-11 06:16:14 +00:00
|
|
|
var client = options.client;
|
2015-11-12 07:31:25 +00:00
|
|
|
var user = options.client.user;
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
var _ = require('lodash');
|
2015-11-14 19:22:21 +00:00
|
|
|
var assert = require('assert');
|
2015-11-12 07:31:25 +00:00
|
|
|
|
2015-11-13 23:13:20 +00:00
|
|
|
function checkAccess(acsCode, value) {
|
2015-11-13 03:47:34 +00:00
|
|
|
try {
|
|
|
|
return {
|
2015-11-13 23:13:20 +00:00
|
|
|
LC : function isLocalConnection() {
|
2015-11-13 03:47:34 +00:00
|
|
|
return client.isLocal();
|
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
AG : function ageGreaterOrEqualThan() {
|
2015-11-13 03:47:34 +00:00
|
|
|
return !isNaN(value) && user.getAge() >= value;
|
|
|
|
},
|
2015-11-14 19:22:21 +00:00
|
|
|
AS : function accountStatus() {
|
2016-02-03 04:35:59 +00:00
|
|
|
if(!_.isArray(value)) {
|
2015-11-14 19:22:21 +00:00
|
|
|
value = [ value ];
|
|
|
|
}
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
const userAccountStatus = parseInt(user.properties.account_status, 10);
|
|
|
|
value = value.map(n => parseInt(n, 10)); // ensure we have integers
|
|
|
|
return value.indexOf(userAccountStatus) > -1;
|
2015-11-14 19:22:21 +00:00
|
|
|
},
|
2015-11-13 03:47:34 +00:00
|
|
|
EC : function isEncoding() {
|
|
|
|
switch(value) {
|
|
|
|
case 0 : return 'cp437' === client.term.outputEncoding.toLowerCase();
|
|
|
|
case 1 : return 'utf-8' === client.term.outputEncoding.toLowerCase();
|
|
|
|
default : return false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
GM : function isOneOfGroups() {
|
|
|
|
if(!_.isArray(value)) {
|
|
|
|
return false;
|
2015-11-12 07:31:25 +00:00
|
|
|
}
|
|
|
|
|
2015-11-14 19:22:21 +00:00
|
|
|
return _.findIndex(value, function cmp(groupName) {
|
|
|
|
return user.isGroupMember(groupName);
|
|
|
|
}) > - 1;
|
2015-11-13 03:47:34 +00:00
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
NN : function isNode() {
|
2015-11-13 03:47:34 +00:00
|
|
|
return client.node === value;
|
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
NP : function numberOfPosts() {
|
2015-11-13 03:47:34 +00:00
|
|
|
// :TODO: implement me!!!!
|
|
|
|
return false;
|
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
NC : function numberOfCalls() {
|
2015-11-13 03:47:34 +00:00
|
|
|
// :TODO: implement me!!
|
|
|
|
return false;
|
|
|
|
},
|
2016-02-03 04:35:59 +00:00
|
|
|
SC : function isSecureConnection() {
|
2015-11-13 03:47:34 +00:00
|
|
|
return client.session.isSecure;
|
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
ML : function minutesLeft() {
|
2015-11-13 03:47:34 +00:00
|
|
|
// :TODO: implement me!
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
TH : function termHeight() {
|
|
|
|
return !isNaN(value) && client.term.termHeight >= value;
|
|
|
|
},
|
|
|
|
TM : function isOneOfThemes() {
|
|
|
|
if(!_.isArray(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-12 07:31:25 +00:00
|
|
|
|
2015-11-13 03:47:34 +00:00
|
|
|
return value.indexOf(client.currentTheme.name) > -1;
|
|
|
|
},
|
|
|
|
TT : function isOneOfTermTypes() {
|
|
|
|
if(!_.isArray(value)) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-11-12 07:31:25 +00:00
|
|
|
|
2015-11-13 03:47:34 +00:00
|
|
|
return value.indexOf(client.term.termType) > -1;
|
|
|
|
},
|
|
|
|
TW : function termWidth() {
|
|
|
|
return !isNaN(value) && client.term.termWidth >= value;
|
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
ID : function isUserId(value) {
|
2016-02-03 04:35:59 +00:00
|
|
|
if(!_.isArray(value)) {
|
2015-11-15 00:51:05 +00:00
|
|
|
value = [ value ];
|
|
|
|
}
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
value = value.map(n => parseInt(n, 10)); // ensure we have integers
|
|
|
|
return value.indexOf(user.userId) > -1;
|
2015-11-13 03:47:34 +00:00
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
WD : function isOneOfDayOfWeek() {
|
2016-02-03 04:35:59 +00:00
|
|
|
if(!_.isArray(value)) {
|
2015-11-15 00:51:05 +00:00
|
|
|
value = [ value ];
|
|
|
|
}
|
2015-11-12 07:31:25 +00:00
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
value = value.map(n => parseInt(n, 10)); // ensure we have integers
|
|
|
|
return value.indexOf(new Date().getDay()) > -1;
|
2015-11-13 03:47:34 +00:00
|
|
|
},
|
2015-11-13 23:13:20 +00:00
|
|
|
MM : function isMinutesPastMidnight() {
|
2015-11-13 03:47:34 +00:00
|
|
|
// :TODO: return true if value is >= minutes past midnight sys time
|
|
|
|
return false;
|
2015-11-12 07:31:25 +00:00
|
|
|
}
|
2015-11-13 23:13:20 +00:00
|
|
|
}[acsCode](value);
|
2015-11-13 03:47:34 +00:00
|
|
|
} catch (e) {
|
2015-11-13 23:13:20 +00:00
|
|
|
client.log.warn( { acsCode : acsCode, value : value }, 'Invalid ACS string!');
|
2015-11-13 03:47:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
2015-11-11 06:05:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
start
|
2015-11-12 07:31:25 +00:00
|
|
|
= expr
|
2015-11-11 06:05:42 +00:00
|
|
|
|
|
|
|
expr
|
2015-11-12 07:31:25 +00:00
|
|
|
= orExpr
|
|
|
|
|
|
|
|
OR
|
|
|
|
= '|'
|
|
|
|
|
|
|
|
AND
|
|
|
|
= '&'
|
|
|
|
|
|
|
|
NOT
|
|
|
|
= '!'
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
groupOpen
|
|
|
|
= '('
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
groupClose
|
|
|
|
= ')'
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
orExpr
|
|
|
|
= left:andExpr OR right:expr { return left || right; }
|
|
|
|
/ andExpr
|
|
|
|
|
|
|
|
andExpr
|
|
|
|
= left:notExpr AND? right:expr { return left && right; }
|
|
|
|
/ notExpr
|
|
|
|
|
|
|
|
notExpr
|
|
|
|
= NOT value:atom { return !value; }
|
|
|
|
/ atom
|
2015-11-11 06:05:42 +00:00
|
|
|
|
|
|
|
atom
|
2015-11-12 07:31:25 +00:00
|
|
|
= acsCheck
|
|
|
|
/ groupOpen value:expr groupClose { return value; }
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
comma
|
|
|
|
= ','
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
ws
|
|
|
|
= ' '
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
optWs
|
|
|
|
= ws*
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
listOpen
|
|
|
|
= '['
|
|
|
|
|
|
|
|
listClose
|
|
|
|
= ']'
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
acsCheck
|
2015-11-13 23:13:20 +00:00
|
|
|
= acs:acsCode a:arg { return checkAccess(acs, a); }
|
2015-11-12 07:31:25 +00:00
|
|
|
|
2015-11-13 23:13:20 +00:00
|
|
|
acsCode
|
2015-11-13 03:47:34 +00:00
|
|
|
= c:([A-Z][A-Z]) { return c.join(''); }
|
2015-11-11 06:05:42 +00:00
|
|
|
|
|
|
|
argVar
|
2015-11-12 07:31:25 +00:00
|
|
|
= a:[A-Za-z0-9\-_\+]+ { return a.join('') }
|
2015-11-11 06:05:42 +00:00
|
|
|
|
|
|
|
commaList
|
2015-11-12 07:31:25 +00:00
|
|
|
= start:(v:argVar optWs comma optWs { return v; })* last:argVar { return start.concat(last); }
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
list
|
|
|
|
= listOpen l:commaList listClose { return l; }
|
2015-11-11 06:05:42 +00:00
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
number
|
|
|
|
= d:([0-9]+) { return parseInt(d.join(''), 10); }
|
2015-11-11 06:05:42 +00:00
|
|
|
|
|
|
|
arg
|
2015-11-12 07:31:25 +00:00
|
|
|
= list
|
|
|
|
/ num:number?
|
|
|
|
|
2015-11-11 06:05:42 +00:00
|
|
|
|