| 1 | /* |
| 2 | Copyright 2021 Intel Corporation |
| 3 | |
| 4 | Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | you may not use this file except in compliance with the License. |
| 6 | You may obtain a copy of the License at |
| 7 | |
| 8 | http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | |
| 10 | Unless required by applicable law or agreed to in writing, software |
| 11 | distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | See the License for the specific language governing permissions and |
| 14 | limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | var seccenter = null; |
| 18 | var WSC_SECURITY_PROVIDER_FIREWALL = 0x1; |
| 19 | var WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS = 0x2; |
| 20 | var WSC_SECURITY_PROVIDER_ANTIVIRUS = 0x4; |
| 21 | var WSC_SECURITY_PROVIDER_ANTISPYWARE = 0x8; |
| 22 | |
| 23 | var WSC_SECURITY_PROVIDER_HEALTH_GOOD = 0; // Green pillar in English locales |
| 24 | var WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED = 1; // Yellow pillar in English locales |
| 25 | var WSC_SECURITY_PROVIDER_HEALTH_POOR = 2; // Red pillar in English locales |
| 26 | var WSC_SECURITY_PROVIDER_HEALTH_SNOOZE = 3; // Yellow pillar in English locales |
| 27 | |
| 28 | try |
| 29 | { |
| 30 | seccenter = require('_GenericMarshal').CreateNativeProxy('Wscapi.dll'); |
| 31 | seccenter.CreateMethod('WscGetSecurityProviderHealth'); |
| 32 | seccenter.CreateMethod('WscRegisterForChanges'); |
| 33 | seccenter.CreateMethod('WscUnRegisterChanges'); |
| 34 | } |
| 35 | catch(e) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | function statusString(val) |
| 40 | { |
| 41 | var ret = 'UNKNOWN'; |
| 42 | |
| 43 | switch (val) |
| 44 | { |
| 45 | case 0: |
| 46 | ret = 'OK'; |
| 47 | break; |
| 48 | case 1: |
| 49 | case 3: |
| 50 | ret = 'WARNING'; |
| 51 | break; |
| 52 | case 2: |
| 53 | ret = 'PROBLEM'; |
| 54 | break; |
| 55 | default: |
| 56 | ret = 'UNKNOWN'; |
| 57 | break; |
| 58 | } |
| 59 | return (ret); |
| 60 | } |
| 61 | function getStatus() |
| 62 | { |
| 63 | var ret = { firewall: 'UNKNOWN', antiVirus: 'UNKNOWN', autoUpdate: 'UNKNOWN' }; |
| 64 | if (seccenter != null) |
| 65 | { |
| 66 | var status = require('_GenericMarshal').CreateVariable(4); |
| 67 | if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_FIREWALL, status).Val == 0) { ret.firewall = statusString(status.toBuffer().readUInt32LE()); } |
| 68 | if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ANTIVIRUS, status).Val == 0) { ret.antiVirus = statusString(status.toBuffer().readUInt32LE()); } |
| 69 | if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS, status).Val == 0) { ret.autoUpdate = statusString(status.toBuffer().readUInt32LE()); } |
| 70 | } |
| 71 | return (ret); |
| 72 | } |
| 73 | |
| 74 | if (process.platform == 'win32' && seccenter != null) |
| 75 | { |
| 76 | var j = { status: getStatus }; |
| 77 | require('events').EventEmitter.call(j, true) |
| 78 | .createEvent('changed'); |
| 79 | j._H = require('_GenericMarshal').CreatePointer(); |
| 80 | j._EV = require('_GenericMarshal').GetGenericGlobalCallback(1); |
| 81 | j._EV.parent = j; |
| 82 | j._EV.on('GlobalCallback', function (p) |
| 83 | { |
| 84 | if (!this.ObjectToPtr_Verify(this.parent, p)) { return; } // This event is not for us |
| 85 | this.parent.emit('changed'); |
| 86 | }); |
| 87 | j.on('~', function () |
| 88 | { |
| 89 | if (seccenter.WscUnRegisterChanges(this._H).Val == 0) { } |
| 90 | }); |
| 91 | |
| 92 | if (seccenter.WscRegisterForChanges(0, j._H, j._EV, require('_GenericMarshal').ObjectToPtr(j)).Val == 0) |
| 93 | { |
| 94 | j._H = j._H.Deref(); |
| 95 | } |
| 96 | module.exports = j; |
| 97 | } |
| 98 | else |
| 99 | { |
| 100 | throw ('win-securitycenter not supported on this platform'); |
| 101 | } |