modules/utils.js
/** 
 *  Initiate a quick scan on a url via the secplugs api 
 *  Optionally takes a progress call back
 **/
Initiate a quick scan on a url via the secplugs api
Optionally takes a progress call back
Initiate a quick scan on a url via the secplugs api Optionally takes a progress call back
function doWebAnalysis(url_to_scan, tabId, local_state, capability = '/web/quickscan', scan_progress_callback = null) {
    if (isUrlExcluded(url_to_scan)) {
        console.log(`
                url '${url_to_scan}'
                excluded.
                `);
        if (scan_progress_callback) {
            const scan_status = {
                url: url_to_scan,
                status: 'failure',
                score: null,
                verdict: null,
                report_id: null,
                err_message: 'This URL is excluded from scanning.'
            };
            scan_progress_callback(scan_status);
        }
        return;
    }
    const headers = getSecplugsAPIHeaders(local_state['secplugs_api_key']);
    const request_url = buildSecplugsAPIRequestUrl(url_to_scan, local_state, capability);
    updateUIWithScanStatus(tabId, local_state, 'pending');
    fetch(request_url, { method: "GET", headers: headers })
        .then(response => {
            const secplugs_security_api = local_state['secplugs_security_api'];
            const secplugs_api_key = local_state['secplugs_api_key'];
            const secplugs_portal = local_state['secplugs_portal'];
            processAPIResponse(
                secplugs_security_api,
                secplugs_api_key,
                response,
                (scan_status) => {
                    console.log('Got status call back');
                    scan_status['url'] = url_to_scan;
                    updateUIWithScanStatus(tabId, local_state, scan_status['status']);
                    scan_progress_callback && scan_progress_callback(scan_status);
                    if (scan_status.verdict == 'malware') {
                        console.log('Received a malware verdict, redirecting...');
                        const report_id = scan_status.report_id;
                        const redirect_url = `${secplugs_portal}/plugin_landing/showalert.php?report_id=${report_id}`;
                        var redirect_script = `window.location.href = '${redirect_url}';`;
                        chrome.tabs.executeScript(
                            tabId, { code: redirect_script },
                            () => { console.log('..done.') });
                    }
                });
        })
        .catch(error => {
            console.error(error);
        });
}
function doWebAnalysis ( url_to_scan , tabId , local_state , capability = '/web/quickscan' , scan_progress_callback = null ) { if ( isUrlExcluded ( url_to_scan ) ) { console . log ( ` ${ url_to_scan } ` ) ; if ( scan_progress_callback ) { const scan_status = { url : url_to_scan , status : 'failure' , score : null , verdict : null , report_id : null , err_message : 'This URL is excluded from scanning.' } ; scan_progress_callback ( scan_status ) ; } return ; } const headers = getSecplugsAPIHeaders ( local_state [ 'secplugs_api_key' ] ) ; const request_url = buildSecplugsAPIRequestUrl ( url_to_scan , local_state , capability ) ; updateUIWithScanStatus ( tabId , local_state , 'pending' ) ; fetch ( request_url , { method : "GET" , headers : headers } ) . then ( response => { const secplugs_security_api = local_state [ 'secplugs_security_api' ] ; const secplugs_api_key = local_state [ 'secplugs_api_key' ] ; const secplugs_portal = local_state [ 'secplugs_portal' ] ; processAPIResponse ( secplugs_security_api , secplugs_api_key , response , ( scan_status ) => { console . log ( 'Got status call back' ) ; scan_status [ 'url' ] = url_to_scan ; updateUIWithScanStatus ( tabId , local_state , scan_status [ 'status' ] ) ; scan_progress_callback && scan_progress_callback ( scan_status ) ; if ( scan_status . verdict == 'malware' ) { console . log ( 'Received a malware verdict, redirecting...' ) ; const report_id = scan_status . report_id ; const redirect_url = ` ${ secplugs_portal } ${ report_id } ` ; var redirect_script = ` ${ redirect_url } ` ; chrome . tabs . executeScript ( tabId , { code : redirect_script } , ( ) => { console . log ( '..done.' ) } ) ; } } ) ; } ) . catch ( error => { console . error ( error ) ; } ) ; }
Initiate a quick scan on a url via the secplugs api
  Optionally takes a progress call back
Initiate a quick scan on a url via the secplugs api Optionally takes a progress call back
// Check for urls we should not scan // Build status // Send update // Get the headers // Build the url // Display pending status // Make the request // Local state values // Process the response // Progress call back // Update the ui // Check for detection  // Trace detection // Build redirect script // Execute redirect // Log the error