wiseService/wiseService.js
// If newSrc is defined will add it to already defined types as src to query.
If newSrc is defined will add it to already defined types as src to query.
If newSrc is defined will add it to already defined types as src to query .
function addType (type, newSrc) {
  let typeInfo = internals.types[type];
  if (!typeInfo) {
    typeInfo = internals.types[type] = {
      name: type,
      excludeName: 'exclude' + type[0].toUpperCase() + type.slice(1) + 's',
      funcName: funcName(type),
      sources: [],
      requestStats: 0,
      foundStats: 0,
      cacheHitStats: 0,
      cacheSrcHitStats: 0,
      cacheSrcMissStats: 0,
      cacheSrcRefreshStats: 0,
      excludes: [],
      globalAllowed: globalAllowed,
      sourceAllowed: sourceAllowed
    };
    if (type === 'url') {
      typeInfo.excludeName = 'excludeURLs';
    }
    if (type === 'ip') {
      typeInfo.excludeName = 'excludeIPs';
      typeInfo.globalAllowed = globalIPAllowed;
      typeInfo.sourceAllowed = sourceIPAllowed;
    }
    for (const src in internals.sources) {
      if (internals.sources[src][typeInfo.funcName]) {
        typeInfo.sources.push(internals.sources[src]);
        internals.sources[src].srcInProgress[type] = [];
      }
    }
    const items = getConfig('wiseService', typeInfo.excludeName, '');
    if (type === 'ip') {
      typeInfo.excludes = new iptrie.IPTrie();
      items.split(';').map(item => item.trim()).filter(item => item !== '').forEach((item) => {
        const parts = item.split('/');
        try {
          typeInfo.excludes.add(parts[0], +parts[1] || (parts[0].includes(':') ? 128 : 32), true);
        } catch (e) {
          console.log(`Error for '${item}'`, e);
          process.exit();
        }
      });
    } else {
      typeInfo.excludes = items.split(';').map(item => item.trim()).filter(item => item !== '').map(item => RegExp.fromWildExp(item, 'ailop'));
    }
  } else if (newSrc !== undefined) {
    typeInfo.sources.push(newSrc);
    newSrc.srcInProgress[type] = [];
  }
  return typeInfo;
}
function addType ( type , newSrc ) { let typeInfo = internals . types [ type ] ; if ( ! typeInfo ) { typeInfo = internals . types [ type ] = { name : type , excludeName : 'exclude' + type [ 0 ] . toUpperCase ( ) + type . slice ( 1 ) + 's' , funcName : funcName ( type ) , sources : [ ] , requestStats : 0 , foundStats : 0 , cacheHitStats : 0 , cacheSrcHitStats : 0 , cacheSrcMissStats : 0 , cacheSrcRefreshStats : 0 , excludes : [ ] , globalAllowed : globalAllowed , sourceAllowed : sourceAllowed } ; if ( type === 'url' ) { typeInfo . excludeName = 'excludeURLs' ; } if ( type === 'ip' ) { typeInfo . excludeName = 'excludeIPs' ; typeInfo . globalAllowed = globalIPAllowed ; typeInfo . sourceAllowed = sourceIPAllowed ; } for ( const src in internals . sources ) { if ( internals . sources [ src ] [ typeInfo . funcName ] ) { typeInfo . sources . push ( internals . sources [ src ] ) ; internals . sources [ src ] . srcInProgress [ type ] = [ ] ; } } const items = getConfig ( 'wiseService' , typeInfo . excludeName , '' ) ; if ( type === 'ip' ) { typeInfo . excludes = new iptrie . IPTrie ( ) ; items . split ( ';' ) . map ( item => item . trim ( ) ) . filter ( item => item !== '' ) . forEach ( ( item ) => { const parts = item . split ( '/' ) ; try { typeInfo . excludes . add ( parts [ 0 ] , + parts [ 1 ] || ( parts [ 0 ] . includes ( ':' ) ? 128 : 32 ) , true ) ; } catch ( e ) { console . log ( ` ${ item } ` , e ) ; process . exit ( ) ; } } ) ; } else { typeInfo . excludes = items . split ( ';' ) . map ( item => item . trim ( ) ) . filter ( item => item !== '' ) . map ( item => RegExp . fromWildExp ( item , 'ailop' ) ) ; } } else if ( newSrc !== undefined ) { typeInfo . sources . push ( newSrc ) ; newSrc . srcInProgress [ type ] = [ ] ; } return typeInfo ; }
If newSrc is defined will add it to already defined types as src to query.
If newSrc is defined will add it to already defined types as src to query .