EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
win-securitycenter.js
Go to the documentation of this file.
1/*
2Copyright 2021 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17var seccenter = null;
18var WSC_SECURITY_PROVIDER_FIREWALL = 0x1;
19var WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS = 0x2;
20var WSC_SECURITY_PROVIDER_ANTIVIRUS = 0x4;
21var WSC_SECURITY_PROVIDER_ANTISPYWARE = 0x8;
22
23var WSC_SECURITY_PROVIDER_HEALTH_GOOD = 0; // Green pillar in English locales
24var WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED = 1; // Yellow pillar in English locales
25var WSC_SECURITY_PROVIDER_HEALTH_POOR = 2; // Red pillar in English locales
26var WSC_SECURITY_PROVIDER_HEALTH_SNOOZE = 3; // Yellow pillar in English locales
27
28try
29{
30 seccenter = require('_GenericMarshal').CreateNativeProxy('Wscapi.dll');
31 seccenter.CreateMethod('WscGetSecurityProviderHealth');
32 seccenter.CreateMethod('WscRegisterForChanges');
33 seccenter.CreateMethod('WscUnRegisterChanges');
34}
35catch(e)
36{
37}
38
39function 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}
61function 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
74if (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}
98else
99{
100 throw ('win-securitycenter not supported on this platform');
101}