Mini Kabibi Habibi

Current Path : C:/Program Files/McAfee/WebAdvisor/MFW/packages/builtin/
Upload File :
Current File : C:/Program Files/McAfee/WebAdvisor/MFW/packages/builtin/wa-core.js

/* Core */
(function (wa) {
    var core = wa.Core = wa.Core || {},
        _settings = wa.Utils.Settings,
        _external = wa.Utils.External;

    //Component
    core.Component = function (name, status, key) {
        this.name = name;
        this.status = status;
        this.key = key;

        this.isIgnored = function (key) {
            var isIgnored = false;
            var startIgnore = this.settings.get("startIgnoreDate" + (key || this.key));
            var ignoreDuration = parseInt(this.settings.get("ignoreDuration"));

            if (startIgnore && ignoreDuration) {
                var today = this.settings.getToday();
                var startIgnoreDate = startIgnore.parseBasicDate();
                isIgnored = today >= startIgnoreDate && today <= startIgnoreDate.addDays(ignoreDuration);
            }

            return isIgnored;
        };

        this.isInFixGracePeriod = function (key) {
            var inGracePeriod = false;
            var gracePeriodStart = this.settings.get("fixGracePeriodStartDate" + (key || this.key));
            var gracePeriodDuration = parseInt(this.settings.get("fixGracePeriodDuration"));
            if (gracePeriodStart && gracePeriodDuration) {
                var today = this.settings.getToday();
                var gracePeriodStartDate = gracePeriodStart.parseBasicDate();
                inGracePeriod = today >= gracePeriodStartDate && today <= gracePeriodStartDate.addHours(gracePeriodDuration);
            }

            return inGracePeriod;
        };

        this.isDisabled = function () {
            return this.status === "OFF";
        };

        this.isNone = function () {
            return this.status === "NONE";
        };
    };
    core.Component.prototype.settings = WebAdvisor.Utils.Settings;
    core.Component.fix = function (actions, key) {
        _external.actionEvent(actions, 3000);
        var todayString = _settings.getToday().getBasicDateString();
        var keys = key.split(",");
        for (var i = 0; i < keys.length; i++) {
            _settings.set("fixGracePeriodStartDate" + keys[i], todayString);
        }
    };
    core.Component.ignore = function (key) {
        var today = _settings.getToday();
        var basicDateString = today.getBasicDateString();
        var keys = key.split(",");
        for (var i = 0; i < keys.length; i++) {
            _settings.set("startIgnoreDate" + keys[i], basicDateString);
        }
    };
    core.Component.getState = function () {
        var components = this.getData();

        // The keys will not exist if there was an error determining the state on native side.
        if (!components.FW || !components.AV || !components.MCSUB) {
            return;
        }

        var firewall = new core.Firewall(components.FW);
        var antivirus = new core.AntiVirus(components.AV);
        var subscription = new core.Subscription(components.MCSUB);

        if ((firewall.isDisabled() && !firewall.isIgnored() && !firewall.isInFixGracePeriod()) &&
            (antivirus.isDisabled() && !antivirus.isIgnored() && !antivirus.isInFixGracePeriod())) {
            return {
                key: this.key.FWAV,
                actions: subscription.getExpiryAction() || antivirus.key + "," + firewall.key,
                name: ["AVFW", "FW,AV"]
            };
        } else if (firewall.isDisabled() && !firewall.isIgnored() && !firewall.isInFixGracePeriod()) {
            return {
                key: this.key.FW,
                actions: subscription.getExpiryAction() || firewall.key,
                name: ["FW"]
            };
        } else if (antivirus.isDisabled() && !antivirus.isIgnored() && !antivirus.isInFixGracePeriod()) {
            return {
                key: this.key.AV,
                actions: subscription.getExpiryAction() || antivirus.key,
                name: ["AV"]
            };
        } else if (antivirus.isNone()) {
            return {
                key: this.key.AVNONE,
                actions: "AVN",
                name: ["AVN"]
            };
        }
    };
    core.Component.key = {
        FWAV: 1,
        FW: 2,
        AV: 3,
        AVNONE: 4
    };
    core.Component.getData = function () {
        return JSON.parse(_external.getArgument("checklist_data"));
    };

    //Secure Search
    core.SecureSearch = {};
    core.SecureSearch.prototype = new core.Component();
    core.SecureSearch.key = "SS";
    core.SecureSearch.enable = function () {
        _external.actionEvent("EnableSecureSearch", 0);
    };
    core.SecureSearch.disable = function () {
        _external.actionEvent("IgnoreSecureSearch", 0);
    };
    core.SecureSearch.getMode = function () {
        var annotateSecureSearchOnly = _settings.get(this.ANNOTATE_SECURE_SEARCH),
            annotateAllSearchEngines = _settings.get(this.ICONS, "0");

        if (annotateSecureSearchOnly && annotateAllSearchEngines) {
            return ['ss'];
        } else if (annotateAllSearchEngines) {
            return ['all'];
        } else {
            return ['none'];
        }
    };
    core.SecureSearch.setMode = function (mode) {
        switch (mode) {
            case 'ss':
                this.annotateSecureSearchEngine();
                break;
            case 'all':
                this.annotateAllSearchEngines();
                break;
            case 'none':
                this.annotateNone();
                break;
        }
    };
    core.SecureSearch.setDefaultMode = function () {
        var isSuiteUser = _settings.get("*Suite"),
            isDefaultAnnotationOptionSet = _settings.get(this.DEFAULT_ANNOTATION_OPTION_SET),
            isUpdateFromSAToWA = _settings.get("*IsUpdateFromSAToWA"),
            isIconsSet = _settings.exists(this.ICONS, "0");

        if (isUpdateFromSAToWA === true &&
            isDefaultAnnotationOptionSet === false) {
            if (isSuiteUser === true) {
                this.showSecureSearchAnnotations(false);
            } else {
                if (isIconsSet === true) {
                    this.showSecureSearchAnnotations(false);
                }
            }
            _settings.set(this.DEFAULT_ANNOTATION_OPTION_SET, true);
            this.notifySettingsChanged();
        }
    };
    core.SecureSearch.annotateSecureSearchEngine = function () {
        this.showSecureSearchAnnotations(true);
        this.showIcons(true);
        this.notifySettingsChanged();
    };
    core.SecureSearch.annotateAllSearchEngines = function () {
        this.showSecureSearchAnnotations(false);
        this.showIcons(true);
        this.notifySettingsChanged();
    };
    core.SecureSearch.annotateNone = function () {
        this.showSecureSearchAnnotations(false);
        this.showIcons(false);
        this.notifySettingsChanged();
    };
    core.SecureSearch.showSecureSearchAnnotations = function (show) {
        _settings.set(this.ANNOTATE_SECURE_SEARCH, show);
    };
    core.SecureSearch.showIcons = function (show) {
        _settings.set(this.ICONS, show, "0");
    };
    core.SecureSearch.notifySettingsChanged = function (show) {
        _settings.notify();
    };

    core.SecureSearch.DEFAULT_ANNOTATION_OPTION_SET = "*IsDefaultAnnotationOptionsSet";
    core.SecureSearch.ANNOTATE_SECURE_SEARCH = "*OnlyShowAnnotationsOnSecureSearch";
    core.SecureSearch.ICONS = "*Icons";
    core.SecureSearch.reset = function () {
        _settings.set("*SSDateStampShowedToast_ie", 0, "0");
        _settings.set("*SSDateStampShowedToast_ff", 0, "0");
        _settings.set("*SSDateStampShowedToast_ch", 0, "0");        
    };

    //Browser Protection
    core.BrowserProtection = function (item) {
        core.Component.call(this, item.name, item.status, core.BrowserProtection.key);
    };
    core.BrowserProtection.prototype = new core.Component();
    core.BrowserProtection.key = "BP";

    //Firewall
    core.Firewall = function (item) {
        core.Component.call(this, item.name, item.status, core.Firewall.key);
    };
    core.Firewall.prototype = new core.Component();
    core.Firewall.key = "FW";

    //AnitVirus
    core.AntiVirus = function (item) {
        core.Component.call(this, item.name, item.status, core.AntiVirus.key);
    };
    core.AntiVirus.prototype = new core.Component();
    core.AntiVirus.key = "AV";
    
    //How it works for Welcome checklist
    core.Welcome = {
        getHowItWorksUrl: function () {
            var url = _settings.get("HowItWorksUrl");
            if (url) {
                return url;
            }
            return "https://www.mcafee.com/consumer/v/wa-how.html";
        }
    };

    //Download Warning
    core.DownloadWarning = {
        allow: function () {
            _external.actionEvent("ALLOW_DOWNLOAD", 0);
        },
        uiDisplayed: function () {
            _external.setUIDisplayedEvent();
        },
        getFileName: function () {
            var url = this.getUrl();
            return JSON.parse(_external.getArgument("template_args")).fileName || url.substring(url.lastIndexOf('/') + 1);
        },
        getDomain: function () {
            var url = this.getUrl(),
                matches = url.match(/^(?:[^\/?#]+\:\/\/)?([^\/?#]+)(?:[\/?#]|$)/i);
            return matches && matches[1];
        },
        getUrl: function () {
            if (!this.url) {
                return JSON.parse(_external.getArgument("template_args")).url;
            }
            return this.url;
        },
        url: "",
        key: "DW"
    };

    //Trusted Sites
    core.TrustedSites = {
        cleanUrl: function (url) {
            var domain = url.replace(/^\s*|\s*$/g, '');
            domain = domain.replace(/^http:\/\/|^https:\/\/|^ftp:\/\/|^gopher:\/\/|^nntp:\/\/|^wais:\/\/|^file:\/\/|^prospero:\/\//gi, '');
            domain = domain.replace(/(\/|:).*/g, '');
            return domain;
        },
        isValidUrl: function (url) {
            var invalidChars = /[^\x2D\x2E\x30-\x39\x41-\x5A\x61-\x7A]/g,
                invalidDots = /^\.|\.\.|\.$/g,
                validDot = /\./g,
                validStart = /^[a-zA-Z0-9]/g,
                MIN_URL_LENGTH = 5,
                MAX_URL_LENGTH = 255;

            return url.length !== 0 &&
                !/^\s+$/g.test(url) &&
                url.length >= MIN_URL_LENGTH &&
                url.length <= MAX_URL_LENGTH &&
                !invalidChars.test(url) &&
                !invalidDots.test(url) &&
                validDot.test(url) &&
                validStart.test(url);
        },
        getCurrentUrl: function () {
            return core.TrustedSites.cleanUrl(_external.getArgument("current_url"));
        },
        get: function () {
            return _settings.get(this.WHITE_LIST, "0");
        },
        set: function (trustedSites) {
            _settings.set(this.WHITE_LIST, trustedSites.join(";"), "0");
        },
        WHITE_LIST: "*WhiteList"
    };

    //Uninstaller
    core.Uninstaller = {
        close: _external.close,
        start: _external.startUninstall,
        complete: _external.isUninstallComplete,
        isUpdaterRunning: _external.isUpdaterRunning,
        isBrowserRunning: _external.isBrowserRunning,
        shutDownBrowsers: _external.shutDownBrowsers
    };

    //Stats
    core.Stats = {
        pagesScanned: function () { return _settings.get("*CounterPagesScanned"); },
        pagesBlocked: function () { return _settings.get("*CounterPagesBlocked"); },
        downloadsScanned: function () { return _settings.get("*CounterDownloadsScanned"); },
        downloadsBlocked: function () { return _settings.get("*CounterDownloadsBlocked"); },
        cryptoBlocked: function () { return _settings.get("*CounterCryptoJackingBlocked"); },

        getHtml: function (l) {

            var cryptoItem = "";
            var cryptoBlockedCount = this.cryptoBlocked();
            if (!_settings.get("CryptojackingDisabled") && cryptoBlockedCount > 0) {
                var attemp = cryptoBlockedCount > 1 ? l("ATTEMPTS") : l("ATTEMPT");
                var cryptoLink = "<span id='wa-crypto-blocked-link' style='color: #00AEEF; cursor: pointer'>" + l("CRYPTOJACKING") + "</span>";
                var cryptoStatText = l("CRYPTO_STAT").format(cryptoLink, attemp);
                cryptoItem = this.getCryptoItemHtml("crypto-blocked", cryptoBlockedCount, cryptoStatText);
            }

            return "<ul>" +
                this.getItemHtml("downloads-scanned", this.downloadsScanned(), l("DOWNLOADS_SCANNED")) +
                this.getItemHtml("downloads-blocked", this.downloadsBlocked(), l("DOWNLOADS_BLOCKED")) +
                this.getItemHtml("pages-scanned", this.pagesScanned(), l("PAGES_SCANNED")) +
                this.getItemHtml("pages-blocked", this.pagesBlocked(), l("PAGES_BLOCKED")) +
                cryptoItem +
                "</ul>";
        },

        getUninstallHtml: function (l) {
            var scannedDownloadCount = this.downloadsScanned();
            var downloadBlockCount = this.downloadsBlocked();
            var pageScannedCount = this.pagesScanned();
            var dangerousPageCount = this.pagesBlocked();

            if (scannedDownloadCount > 0 || downloadBlockCount > 0 || pageScannedCount > 0 ||
                dangerousPageCount > 0 ) {
                return "<ul>" +
                    this.getItemHtmlWithPlural("downloads-scanned", scannedDownloadCount, l("WE_SCANNED"), scannedDownloadCount > 1 ? l("DOWNLOADS") : l("DOWNLOAD")) +
                    this.getItemHtmlWithPlural("downloads-blocked", downloadBlockCount, l("BLOCKED_UNSAFE"), downloadBlockCount > 1 ? l("DOWNLOADS") : l("DOWNLOAD")) +
                    this.getItemHtmlWithPlural("pages-scanned", pageScannedCount, l("WE_SCANNED"), pageScannedCount > 1 ? l("PAGES") : l("PAGE")) +
                    this.getItemHtmlWithPlural("pages-blocked", dangerousPageCount, l("BLOCKED_DANGEROUS"), dangerousPageCount > 1 ? l("PAGES") : l("PAGE")) +
                    "</ul>";
            } 

            return "<ul id='bulletpoints'>" +
                "<li><span>{0}</span></li>".format(l("BLOCKING_DOWNLOAD")) +
                "<li><span>{0}</span></li>".format(l("FLAGGING_SITES")) +
                "<li><span>{0}</span></li>".format(l("CHECKING_ANTIVIRUS")) +
                "<li><span>{0}</span></li>".format(l("PEACE_OF_MIND")) +
                "</ul>";
        },

        getCryptoItemHtml: function (id, counter, text) {
            return (counter ? "<li><span id='" + id + "'>{0} {1}</span></li>".format(counter, text) : "");
        },

        getItemHtml: function (id, counter, text) {
            return (counter ? "<li><span id='" + id + "'>{0}</span></li>".format(text, counter) : "");
        },

        getItemHtmlWithPlural: function (id, counter, text, textPlural) {
            return (counter ? "<li><span id='" + id + "'>{0}</span></li>".format(text, counter, textPlural) : "");
        },
    };

    //Web Advisor
    core.WebAdvisor = {
        getProductName: function () {
            var lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SHARED);
            return lang.get("PRODUCT_NAME_TRADEMARKED");
        },
        getProductLogoHtml: function (src) {
            var productNameHtml = this.getProductNameHtml(),
                imgSrc = src || "wacore:mfw\\packages\\builtin\\mcafee-logo2.png";

            return "<div class='logo'><img src='" + imgSrc + "' align='middle'>" + productNameHtml + "</div>";
        },
        getProductNameHtml: function () {
            var className = "product-name",
                lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SHARED);

            return "<span class='{0}'>".format(className) +
                lang.get("WEBADVISOR") +
            "</span>";
        },
        getProductLogoHtmlLegacy: function () {
            var style = "margin-left: 8px;color: #808080;";
            lang = wa.Utils.Lang(wa.Utils.Lang.ResType.SHARED);
            var productNameHtml = "<span class='{0}'>".format("product-name") + lang.get("COMPANY_NAME_TRADEMARKED") + "</span>";

            return "<img src='wacore:mfw\\packages\\builtin\\icn_mshield.png' align='middle'>" +
                   "<span style='{0}'>{1}</span>".format(style, productNameHtml);
        },
        isPremium: function () {
            return _settings.get("*Premium");
        },
        getVersion: _settings.getVersion,
        close: _external.close
    };

    //Window
    core.Window = {
        getWidth: _external.getWindowWidth,
        setHeight: _external.setWindowHeight,
        setWidth: _external.setWindowWidth,
        close: _external.close,
        show: _external.show,
        minimize: _external.minimize,
        isInitialized: _external.isInitialized,
        setDraggableOffset: _external.setDraggableOffset,
        ready: function (success, error) {
            var maxIterations = 20,
                interval = 50,
                _this = this,
                windowReady = setInterval(function () {
                    if (_this.isInitialized()) {
                        clearInterval(windowReady);
                        if (success && typeof success === "function") {
                            success();
                        }
                    } else {
                        if (maxIterations === 0) {
                            clearInterval(windowReady);
                            if (error && typeof error === "function") {
                                error();
                            }
                            _this.close();
                        }
                        maxIterations--;
                    }
                }, interval);
        },
        getBrowserType: function () {
            var type = _external.getBrowserType();
            switch (type) {
                case 0:
                    return "IE";
                case 1:
                    return "FF";
                case 2:
                    return "CH";
                case 3:
                    return "ED";
            }
        }
    };

    core.Browser = {
        getType: function () {
            var type = _external.getBrowserType();
            switch (type) {
                case 0:
                    return this.INTERNET_EXPLORER;
                case 1:
                    return this.FIREFOX;
                case 2:
                    return this.CHROME;
                case 3:
                    return this.EDGE;
            }
        },
        INTERNET_EXPLORER: "IE",
        FIREFOX: "FF",
        CHROME: "CH",
        SAFER: "MSB",
        EDGE: "EDGE"
    };

    //CheckList
    core.CheckList = {
        shouldSupressThreat: function (state) {
            // Business Rule: We should not show security threats when the computer has booted
            // up in the last 3 minutes, as the information we read may not be accurate.
            var key = core.Component.key;
            if (state.key === key.FWAV || state.key === key.AV || state.key === key.FW) {

                var startupTickCount = _external.getTickCount();
                var noThreatTimer = _settings.get("*McAfeeNoThreatStartupTimer");

                // Perform a string-type number comparison startupTickCount < noThreatTimer
                // As the value we get from getTickCount may be larger
                // than javascript's number limit of +/- 2^53 depending on the call used
                if (typeof startupTickCount === 'string' && typeof noThreatTimer === 'string' &&
                    (startupTickCount.length < noThreatTimer.length ||
                        (startupTickCount.length === noThreatTimer.length && startupTickCount < noThreatTimer))) {
                    return true;
                }
            }

            return false;
        },
        mapComponentsToItems: function (components, keys, lang) {
            var items = {};
            for (var i = 0; i < keys.length; i++) {
                var component = components[keys[i]];
                if (component.status === "ON") {
                    switch (keys[i]) {
                        case core.Firewall.key:
                            component.name = lang("FIREWALL");
                            break;
                        case core.AntiVirus.key:
                            component.name = lang("ANTIVIRUS");
                            break;
                        case core.BrowserProtection.key:
                            component.name = lang("BROWSER_PROTECTION");
                            break;
                    }

                    component.status = lang("ON");
                    items[keys[i]] = component;
                }
            }
            return items;
        },
        getCommand: function () {
            return JSON.parse(_external.getArgument("template_args")).commandName;
        },
        disableWelcome: function (key, value) {
            _settings.set(this["DISABLE_{0}_WELCOME".format(key)], value);
        },
        reset: function () {
            _settings.set("startIgnoreDateAV", "");
            _settings.set("startIgnoreDateFW", "");
            _settings.set("ignoreDuration", "14");
            _settings.set("fixGracePeriodStartDateAV", "");
            _settings.set("fixGracePeriodStartDateFW", "");
            _settings.set("fixGracePeriodDuration", "24");
        }
    };

    //Subscription
    core.Subscription = function (item) {
        core.Component.call(this, item.name, item.status);
        this.isInLimitedExpiry = false;
        this.isInExtendedExpiry = false;

        initialize = function (subscription, that) {
            if (subscription && subscription.expiry) {
                var today = that.settings.getToday();
                var expiry = subscription.expiry.parseBasicDate();
                var expiryDays = parseInt(that.settings.get("expiryDays"));

                that.isInLimitedExpiry = today >= expiry && today < expiry.addDays(expiryDays);
                that.isInExtendedExpiry = today >= expiry.addDays(expiryDays);
            }
        }
            (item, this);

        this.getExpiryAction = function () {
            if (this.isInLimitedExpiry) {
                return "MCSUB";
            }
            if (this.isInExtendedExpiry) {
                return "DEFAULT";
            }
        };
    };
    core.Subscription.prototype = new core.Component();

    //Data
    core.data = {
        url: {
            helpNow: "https://service.mcafee.com/default.aspx",
            twitter: "https://twitter.com/McAfee_Home",
            facebook: "https://www.facebook.com/McAfee/",
            shared: "https://www.siteadvisor.com/final/index.html",
            survey: "https://www.siteadvisor.com/uninstall.html?client=ie&client_ver={0}"
        },
        image: {
            spinner: "wacore:mfw\\packages\\builtin\\white_timer.png",
            spinnerLarge: "wacore:mfw\\packages\\builtin\\spinner_large.gif",
            questionMark: "wacore:mfw\\packages\\builtin\\white_questionmark.png",
            checkMark: "wacore:mfw\\packages\\builtin\\white_check.png",
            exclamationMark: "wacore:mfw\\packages\\builtin\\white_exclamation.gif",
            close: "wacore:mfw\\packages\\builtin\\main_close.png",
            greenCheck: "wacore:mfw\\packages\\builtin\\green_check.png",
            uninstallHeader: "wacore:mfw\\packages\\builtin\\installer_background.png"
        }
    };
}(window.WebAdvisor = window.WebAdvisor || {}));

//288AE6B6338F1AF3C1109D63EDD8E96C6130B5FFD90C2016788106F8BB44E3495CC8D52DDFCD22E28B94F43BEC441D14FF6AD0F802B55455592CFAC31F642F2E++