var sites_path       = process.argv[2]
    sites            = require("./" + sites_path),
    request          = require('request'),
    ignoreSelfSigned = false

for (i in process.argv) {
  if (i >= 2) {
    if (process.argv[i] == "no-certificate-check") {
      ignoreSelfSigned = true
    }
  }
}

for (s in sites) {
  testSiteAllProtocols (sites[s].site, function (site, protocols) {
    var secureState = "Undefined",
        httpSecure  = false,
        httpsSecure = false

    for (p in protocols) {
      if (protocols[p].protocol == "https") {
        httpsSecure = protocols[p].status
      } else if (protocols[p].protocol == "http") {
        httpSecure = protocols[p].status
      }
    }

    if (httpSecure && httpsSecure) {
      secureState = "High"
    } else if (httpSecure || httpsSecure) {
      secureState = "Medium"
    } else if (!httpSecure && !httpsSecure) {
      secureState = "Low"
    } else {
      secureState = "Unknown State"
    }

    console.log (secureState + "\t" + site)
  })
}

function testSiteAllProtocols (site, callback) {
  var protocols = [{
    "protocol": "http",
    "status": "",
  },{
    "protocol": "https",
    "status": "",
  }]

  for (i in protocols) {
    var host = protocols[i].protocol + "://" + site

    isSiteSslEnabled (host, i, function (isSecure, site, index) {
      var site_split = site.split("://"),
          site_protocol = site_split[0],
          site_hostname = site_split[1]

      for (p in protocols) {
        if (protocols[p].protocol == site_protocol) {
          protocols[p].status = isSecure
        }
      }

      if (index == protocols.length - 1) {
        callback (site_hostname, protocols)
      }
    })
  }
}

function isSiteSslEnabled (site, index, callback) {
  options = {
    "url": site,
    "followRedirect": false
  }

  request(options, function (error, response, body) {
    if (!error) {
      if (response.statusCode == 200 && response.request.uri.protocol == "https:") {
        callback (true, site, index)
      } else if ((response.statusCode == 301 || response.statusCode == 302) && response.headers.location.indexOf ("https") == 0) {
        callback (true, site, index)
      } else {
        callback (false, site, index)
      }
    } else {
        if (error == "Error: DEPTH_ZERO_SELF_SIGNED_CERT") {
          callback (ignoreSelfSigned, site, index)
        } else {
          callback (false, site, index)
        }
    }
  })
}
@@ -134,170 +134,74 @@
     
-ignoreSelfSigned = false%0A%0Afor (i in process.argv) %7B%0A  if (i %3E= 2) %7B%0A    if (process.argv%5Bi%5D == %22no-certificate-check%22) %7B%0A      ignoreSelfSigned = true%0A    %7D%0A  %7D%0A%7D
+argFlags         = new Array ()%0A%0AargFlags = processArgs (argFlags)
 %0A%0Afo
@@ -301,24 +301,27 @@
 secureState 
+   
 = %22Undefined
@@ -335,27 +335,73 @@
     
-httpSecure 
+protocolSecure = new Array ()%0A%0A    protocolSecure%5B%22http%22%5D
  = false
 ,%0A  
@@ -400,29 +400,36 @@
 alse
-,%0A 
+%0A
     
-   httpsSecure
+protocolSecure%5B%22https%22%5D
  = f
@@ -463,36 +463,32 @@
 ls) %7B%0A      
-if (
 protocol
 s%5Bp%5D.protoco
@@ -479,58 +479,15 @@
 ocol
-s%5Bp%5D.protocol == %22https%22) %7B%0A        https
 Secure
- = 
+%5B
 prot
@@ -499,85 +499,17 @@
 %5Bp%5D.
-status%0A      %7D else if (protocols%5Bp%5D.protocol == %22http%22) %7B%0A        httpSecure
+protocol%5D
  = p
@@ -527,24 +527,16 @@
 .status%0A
-      %7D%0A
     %7D%0A%0A 
@@ -546,313 +546,652 @@
 if (
-httpSecure && httpsSecure) %7B%0A      secureState = %22High%22%0A    %7D else if (httpSecure %7C%7C httpsSecure) %7B%0A      secureState = %22Medium%22%0A    %7D else if (!httpSecure && !httpsSecure) %7B%0A      secureState = %22Low%22%0A    %7D else %7B%0A      secureState = %22Unknown State%22%0A    %7D%0A%0A    console.log (secureState + %22%5Ct%22 + site)%0A  %7D)
+protocolSecure%5B%22http%22%5D && protocolSecure%5B%22https%22%5D) %7B%0A      secureState = %22High%22%0A    %7D else if (protocolSecure%5B%22http%22%5D %7C%7C protocolSecure%5B%22https%22%5D) %7B%0A      secureState = %22Medium%22%0A    %7D else if (!protocolSecure%5B%22http%22%5D && !protocolSecure%5B%22https%22%5D) %7B%0A      secureState = %22Low%22%0A    %7D else %7B%0A      secureState = %22Unknown State%22%0A    %7D%0A%0A    console.log (secureState + %22%5Ct%22 + site)%0A  %7D)%0A%7D%0A%0Afunction processArgs (argFlags) %7B%0A  argFlags%5B%22no-certificate-check%22%5D = false%0A%0A  for (i in process.argv) %7B%0A    if (i %3E= 2) %7B%0A      if (process.argv%5Bi%5D == %22no-certificate-check%22) %7B%0A        argFlags%5B%22no-certificate-check%22%5D = true%0A      %7D%0A    %7D%0A  %7D%0A%0A  return argFlags
 %0A%7D%0A%0A
@@ -2514,24 +2514,40 @@
 ck (
-ignoreSelfSigned
+argFlags%5B%22no-certificate-check%22%5D
 , si

refactor processArgs()