'use strict'; 'require fs'; 'require rpc'; 'require ui'; document.head.append(E('style', {'type': 'text/css'}, ` .label-status { display: inline; margin: 0px 2px 0px 0 !important; padding: 1px 4px 2px 4px; -webkit-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; font-weight: bold; color: #fff !important; } .starting { background-color: #a7b668 !important; } .running { background-color: #2ea256 !important; } .updating { background-color: #1e82ff !important; } .stopped { background-color: #acacac !important; } .error { background-color: #ff4e54 !important; } .total-proxy { background-color: #ffb937 !important; } `)); return L.Class.extend({ appName : 'ruantiblock', execPath : '/usr/bin/ruantiblock', tokenFile : '/var/run/ruantiblock.token', parsersDir : '/usr/bin', torrcFile : '/etc/tor/torrc', userEntriesFile : '/etc/ruantiblock/user_entries', fqdnFilterFile : '/etc/ruantiblock/fqdn_filter', ipFilterFile : '/etc/ruantiblock/ip_filter', crontabFile : '/etc/crontabs/root', infoLabelStarting: '' + _('Starting') + '', infoLabelRunning : '' + _('Enabled') + '', infoLabelUpdating: '' + _('Updating') + '', infoLabelStopped : '' + _('Disabled') + '', infoLabelError : '' + _('Error') + '', blacklistSources: { 'rublacklist': 'https://rublacklist.net', 'zapret-info': 'https://github.com/zapret-info/z-i', 'antifilter' : 'https://antifilter.download', }, callInitStatus: rpc.declare({ object: 'luci', method: 'getInitList', params: [ 'name' ], expect: { '': {} } }), callInitAction: rpc.declare({ object: 'luci', method: 'setInitAction', params: [ 'name', 'action' ], expect: { result: false } }), getInitStatus: function(name) { return this.callInitStatus(name).then(res => { if(res) { return res[name].enabled; } else { throw _('Command failed'); } }).catch(e => { ui.addNotification(null, E('p', _('Failed to get %s init status: %s').format(name, e))); }); }, handleServiceAction: function(name, action) { return this.callInitAction(name, action).then(success => { if(!success) { throw _('Command failed'); }; return true; }).catch(e => { ui.addNotification(null, E('p', _('Service action failed "%s %s": %s').format(name, action, e))); }); }, normalizeValue: function(v) { return (v && typeof(v) === 'string') ? v.trim().replace(/\r?\n/g, '') : v; }, makeStatusString: function( app_status_code, proxy_mode, bllist_mode, bllist_module, bllist_source, tp_status_code, vpn_route_status_code) { let app_status_label; let spinning = ''; switch(app_status_code) { case 0: app_status_label = this.infoLabelRunning; break; case 2: app_status_label = this.infoLabelStopped; break; case 3: app_status_label = this.infoLabelStarting; spinning = ' spinning'; break; case 4: app_status_label = this.infoLabelUpdating; spinning = ' spinning'; break; default: app_status_label = this.infoLabelError; return `