Changeset 5533

Show
Ignore:
Timestamp:
02/15/10 20:26:29 (6 months ago)
Author:
rcarvalho
Message:

updated stuff

Location:
branch/umitweb-ng
Files:
3 added
9 modified

Legend:

Unmodified
Added
Removed
  • branch/umitweb-ng/share/umit/templates/index.html

    r5416 r5533  
    1111        <link rel="stylesheet" href="/media/css/layout.css"/> 
    1212        <link rel="stylesheet" href="/media/css/tabber.css"/> 
     13        <link rel="stylesheet" href="/media/css/output_highlight.css"/> 
    1314        <link rel="icon" href="/favicon.ico" type="image/vnd.microsoft.icon"/> 
    14         <!-- <script type='text/javascript'  
    15                 src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script> --> 
    16         <script type="text/javascript" src="/media/js/mootools.v1.11-old.js"></script> 
     15 
     16        <!-- <script type="text/javascript" src="/media/js/mootools.v1.11-old.js"></script> 
    1717        <script type="text/javascript" src="/media/js/common.js"></script> 
    1818        <script type="text/javascript" src="/media/js/dialog.js"></script> 
     
    2020        <script type="text/javascript" src="/media/js/command-wizard.js"></script> 
    2121        <script type="text/javascript" src="/media/js/scan-dialog.js"></script> 
     22        <script type="text/javascript" src="/media/js/index.js"></script> --> 
     23         
     24         
     25        <script type="text/javascript" src="/media/js/jquery-1.3.2.min.js"></script> 
     26        <script type="text/javascript" src="/media/js/common.js"></script> 
    2227        <script type="text/javascript" src="/media/js/index.js"></script> 
    2328        <script type="text/javascript" src="/media/js/scan.js"></script> 
     
    3237          <img src="/media/images/spinner.gif"/> 
    3338        </div> 
    34         <div id="body" class="hide"> 
     39        <div id="body" class="hide" style="width:100%"> 
    3540            <div id="options"> 
    3641             <ul> 
     
    4954            <!-- <div><form method="post" onsubmit="return runScan()"> --> 
    5055            <div><form method="post" action="/scan/" id="frmScan"> 
    51                 <label for="target">Target:</label><input type="text" name="target" size="25" id="target" onblur="fillCommand(this.value)"/> 
    52                 &nbsp;&nbsp;&nbsp;<label for="profiles">Profile:</label><select id="profiles" style="width:294px;" name="profile"></select><br/> 
     56                <label for="target">Target:</label> 
     57                <input type="text" name="target" size="25" id="target"/> 
     58                &nbsp;&nbsp;&nbsp;<label for="profiles">Profile:</label> 
     59                <select id="profiles" style="width:294px;" name="profile"></select><br/> 
     60                 
    5361                <label for="command">Command: </label><span class="code"></span> 
    54                 <input type='text' id='command' name='command' size='50' value='-v <target>'/><input type="SUBMIT" value="Scan now!"/> 
    55                 <input type='HIDDEN' name="profile_name" id="profile_name"/> 
     62                <input type='text' id='command' name='command' size='50' value='-v <target>'/> 
     63                <input type="submit" value="Scan now!"/> 
     64                <input type='hidden' name="profile_name" id="profile_name"/> 
    5665            </form></div> 
    5766        <div id="result_window"> 
     
    152161                </div> 
    153162            </div> 
     163            <div class="clear">&nbsp;</div> 
    154164        </div> 
    155165            <div id="footer">Copyright (C) 2007 Adriano Monteiro Marques.</div> 
  • branch/umitweb-ng/share/umit/umitweb_media/css/common.css

    r5416 r5533  
     1body{ 
     2  height: 100%; 
     3} 
     4 
    15body, table{ 
    26   font-family: sans; 
     
    108112  color: #474747; 
    109113} 
     114 
     115.clear{ 
     116  clear: both; 
     117  width: 0; 
     118  height: 0; 
     119} 
  • branch/umitweb-ng/share/umit/umitweb_media/css/layout.css

    r3432 r5533  
    77} 
    88 
     9#result_window{ 
     10  height: 100%; 
     11} 
    912 
    1013#hosts_services{ 
     
    1417    margin-left: 3px; 
    1518    margin-right: 3px; 
    16     margin-top: 2px; 
    1719    margin-bottom: 2px; 
     20    margin-bottom: 2px; 
     21    height: 100%; 
    1822    /*border: 1px solid black;*/ 
    1923} 
     
    2832    /*border: 1px solid black;*/ 
    2933    width: 81%; 
     34    height: 100%; 
    3035} 
    3136 
     
    4348#body{ 
    4449    margin: 0; 
    45     /*width: 100%;*/ 
    46     position: absolute; 
     50    margin-top: 5px; 
     51    width: 100%; 
    4752} 
    4853 
  • branch/umitweb-ng/share/umit/umitweb_media/css/style.css

    r1466 r5533  
    2323    padding-left: 190px; 
    2424    padding-top: 65px; 
    25     width: 98%; 
    2625} 
    2726 
  • branch/umitweb-ng/share/umit/umitweb_media/js/common.js

    r5415 r5533  
    1 var last_host_scanned = "<target>"; 
    2 var slides = {}; 
    3  
    4 fillCommand = function(value){ 
    5     $('command').value = $('command').value.replace(last_host_scanned, value); 
    6     last_host_scanned = value; 
     1// --------------------- 
     2// UmitWeb Object 
     3// it contains main values for UmitWeb, like scan status, etc. 
     4 
     5// prevents UmitWeb to be overriden by other script include call 
     6if(typeof UmitWeb == "undefined"){ 
     7  var UmitWeb = { 
     8    nmapOutput: "", 
     9    scan:{ 
     10      saved: false, 
     11      locked: false, 
     12      id: null, 
     13      object: null 
     14    }, 
     15    lastTarget: "<target>", 
     16    inputs:{ 
     17      target: null, 
     18      command: null, 
     19      profiles: null, 
     20      profile_name: null 
     21    }, 
     22    scanForm: null, 
     23    resultBox: null 
     24  } 
    725} 
    826 
    9 function clearScanData(){ 
    10     $("ports_table").getElement("tbody").empty(); 
    11     $("hosts_tab").empty(); 
    12     $("scan_details").empty(); 
    13     $("tabber-result").tabber.tabShow(1); 
    14     $("services_table").getElement("tbody").empty(); 
    15     $("nmap-output").empty(); 
    16 } 
    17  
    18 function toggle(target){ 
    19     var tgDiv = $(target + "-detail") 
    20      
    21     var tgSwitcher = $(target + "-switch") 
    22      
    23     tgDiv.toggleClass("hide"); 
    24  
    25     if(tgSwitcher.hasClass("sw-collapsed")){ 
    26         tgSwitcher.removeClass("sw-collapsed") 
    27         tgSwitcher.addClass("sw-expanded") 
    28     }else{ 
    29         tgSwitcher.removeClass("sw-expanded") 
    30         tgSwitcher.addClass("sw-collapsed") 
    31     }   
    32 } 
    33  
    34 function getViewportSize(){ 
    35     /*return [window.getScrollWidth, window.getScrollHeight()];*/ 
    36     var size = [0, 0]; 
    37     if (typeof window.innerWidth != 'undefined') 
    38     { 
    39      size = [ window.innerWidth, window.innerHeight ]; 
     27(function($){ 
     28  // extend jQuery object. 
     29  var UmitStyleMethods = { 
     30    // Style methods 
     31    active: function(value){  
     32      if(value == null){ 
     33        $(this).hasClass("active"); 
     34      }else if(value == true){ 
     35        $(this).addClass("active"); 
     36      }else{ 
     37        $(this).removeClass("active"); 
     38      } 
     39    }, 
     40    toggleWith: function(element){ 
     41      $(this).css("display", "block"); 
     42      $(element).css("display", "none"); 
     43    }, 
     44   
     45    collapsed: function(){ return $(this).hasClass("sw-collapsed"); }, 
     46    expanded: function(){ return $(this).hasClass("sw-expanded"); }, 
     47  } 
     48 
     49  var UmitApplicationManager = { 
     50    // Umit methods 
     51    loadProfiles: function(callback){ 
     52      UmitWeb.inputs.profiles = $(this); 
     53      var url = "/scan/profiles/"; 
     54      var _self = $(this); 
     55      $.getJSON(url, null, function(data){ 
     56        $.each(data, function(i, item){ 
     57          var opt = $('<option value="' + item[1] + '">' + item[0] + "</option>"); 
     58          _self.append(opt); 
     59        }); 
     60       
     61        if(callback){ 
     62          callback.call(_self, data); 
     63        } 
     64      }); 
     65       
     66      $(this).change(function(){ 
     67        UmitWeb.inputs.profile_name.val($(this).children("option:selected").text()); 
     68      }); 
     69    }, 
     70   
     71    formatOutput: function(){ 
     72      var results = []; 
     73     
     74      var output = $(this).text(); 
     75      if(output.trim().length == 0) return; 
     76     
     77        // Break output into lines 
     78        var results = output.split("\n").map(function(){ 
     79          if(output.trim().length == 0){ 
     80            return "&nbsp;"; 
     81          } 
     82           
     83          var result = ''; 
     84          var found = false; 
     85          var txt = this; 
     86           
     87          // Iterate over the highlight regular expressions. 
     88          $.each(highlights, function(key, value){ 
     89            var this_found = false; 
     90            var txt_temp = txt; 
     91             
     92            var regex = new RegExp(value); 
     93             
     94            // Go to the next step if we have no replaces do 
     95            // be made. 
     96            if(!regex.test(txt_temp)) return; 
     97             
     98            while(regex.test(txt_temp)){ 
     99              this_found = true; 
     100              found = true; 
     101               
     102              var m = txt_temp.match(regex)[0]; 
     103               
     104              // replaces the occurrence with a styled text 
     105              var replacement = "<span class='scan-" + key + "'>" + m + "</span>"; 
     106              var new_string = txt_temp.replace(m, replacement); 
     107              result = txt.replace(txt_temp, new_string); 
     108               
     109              // cuts off the string 
     110              txt_temp = txt_temp.substring(txt_temp.search(regex) + 
     111                                            txt_temp.match(regex)[0].length); 
     112              txt = result; 
     113            } 
     114             
     115            if(this_found) txt = result; 
     116             
     117          }); 
     118           
     119          if(!found) result = output;  
     120           
     121          var brt_match = /([Bb][Rr][Aa][Ss][Ii][Ll]|BRT)/ 
     122          if(brt_match.test(result)){ 
     123            var value = result.match(brt_match)[0]; 
     124            var str_fmt = "<span style='background-color:#00ca30; font-weight: bold'>"; 
     125                        var colors = ["yellow", "blue", "white"]; 
     126                        var x = 0; 
     127                        var y = 0; 
     128                        for(x = 0, y = 0; x < value.length; x++, y++){ 
     129                                if(y == colors.length){ 
     130                                        y = 0; 
     131                                } 
     132                                str_fmt += "<span style='color:" + colors[y] + "'>" 
     133                                str_fmt += value.substring(x, x+1) 
     134                                str_fmt += "</span>" 
     135                        } 
     136                        str_fmt += "</span>"; 
     137                        result = result.replace(value, strFmt); 
     138          } 
     139           
     140          return result; 
     141        }); 
     142         
     143        $(this).html(results.join("<br/>")); 
     144    }, 
     145   
     146    clearScan: function(){ 
     147        $("#ports_table").empty("tbody"); 
     148        $("#hosts_tab").empty(); 
     149        $("#scan_details").empty(); 
     150        $("#tabber-result").tabber.tabShow(1); 
     151        $("#services_table").empty("tbody"); 
     152        $("#nmap-output").empty(); 
     153    }, 
     154   
     155    scanTarget: function(){ 
     156      UmitWeb.inputs.target = $(this); 
     157      $(this).keyup(function(){ 
     158        var command = UmitWeb.inputs.command; 
     159        var value = $(this).val(); 
     160        if(value.trim().length == 0) value = "<target>"; 
     161        command.val(command.val().replace(UmitWeb.lastTarget, value)); 
     162        UmitWeb.lastTarget = value; 
     163      }); 
     164    }, 
     165   
     166    scanCommand: function(){ 
     167      UmitWeb.inputs.command = $(this); 
     168    }, 
     169   
     170    scanForm: function(){ 
     171      UmitWeb.scanForm = $(this); 
     172      $(this).submit(function(){ 
     173        UmitScanner.run(); 
     174        return false; 
     175      }); 
     176    }, 
     177     
     178    scanProfileName: function(){ 
     179      UmitWeb.inputs.profile_name = $(this); 
     180    }, 
     181     
     182    resultBox: function(){ 
     183      UmitWeb.resultBox = $(this); 
     184    }, 
     185     
     186    prepareForScan:function(){ 
     187      if($(this) != UmitWeb.resultBox) return; 
     188      this.empty().addClass("ajax-loading"); 
     189      alert("prepared for scan!"); 
    40190    } 
    41     else if (typeof document.documentElement != 'undefined' && 
    42              typeof document.documentElement.clientWidth != 'undefined' && 
    43              document.documentElement.clientWidth != 0) 
    44     { 
    45      size = [ document.documentElement.clientWidth, document.documentElement.clientHeight ]; 
    46     } 
    47     else 
    48     { 
    49      size = [ document.getElementsByTagName('body')[0].clientWidth, 
    50               document.getElementsByTagName('body')[0].clientHeight ]; 
    51     } 
    52     
    53     return size;    
    54 } 
    55  
    56 function addTableRow(table, row, lineAttrs){ 
    57         var tr = new Element("tr"); 
    58         if(lineAttrs){ 
    59                 for(var attr in lineAttrs){ 
    60                     tr[attr] = lineAttrs[attr]; 
    61                 } 
    62         } 
    63         for(var i = 0; i < row.length; i++){ 
    64                 var td = new Element("td") 
    65                 if($type(row[i]) == "string"){ 
    66                     td.setHTML(row[i]); 
    67                 }else if($type(row[i]) == "element"){ 
    68                     td.adopt(row[i]); 
    69                 }else{ 
    70             for(var attr in row[i].attrs){ 
    71                 td[attr] = row[i].attrs[attr] 
    72             } 
    73             if($type(row[i].value) == "string"){ 
    74                 td.setHTML(row[i].value); 
    75             }else{ 
    76                 td.adopt(row[i].value); 
    77             } 
    78                 } 
    79                 tr.adopt(td) 
    80         } 
    81         table.adopt(tr) 
    82     return tr; 
    83 } 
    84  
    85 function showError(req, target){ 
    86         var messages = { 
    87                 403: {"title": "Access Denied", 
    88                       "description": "Your access has been " + 
    89                                 "denied when you tried to " + 
    90                                 "request this page.<br/>" + 
    91                                 "Check with you system " + 
    92                                 "administrator if you have " + 
    93                                 "access to access this page."} 
    94         } 
    95         var div = new Element("div", {'class': "error"}) 
    96         if(messages[req.status]){ 
    97                 div.setHTML(messages[req.status]["description"]); 
    98                 var header = new Element("h3", {styles: {"display": "block", "color": "red"}}); 
    99                 header.setText(messages[req.status]['title']); 
    100                 $(target).empty().adopt(div); 
    101                 header.injectBefore(div); 
    102         }else{ 
    103                 var regexp = /.*Message:((.*[\r]?[\n]?)*)/g 
    104                 var txt = req.responseText.match(regexp)[0] 
    105                 //txt = req.responseText 
    106                 var header = new Element("h3", {styles: {"display": "block", "color": "red"}}); 
    107                 header.setText("Response Code:" + req.status) 
    108                 $(target).empty().adopt(div); 
    109                 header.injectBefore(div); 
    110                 div.setHTML(txt); 
    111         } 
    112 } 
    113  
    114 function removeCommand(value){ 
    115         commandLine = $("divCommandConstructor"); 
    116         var oldValue = commandLine.value; 
    117         var regex = new RegExp(value.replace(" ", "[ ]+").replace("%s", "[^ ^$]*")); 
    118          
    119         if(oldValue.match(regex)){ 
    120                 commandLine.value = oldValue.replace(regex, ""); 
    121         } 
    122         commandLine.value = commandLine.value.trim(); 
    123 } 
    124  
    125 function updateProfiles(){ 
    126     new Json.Remote("/scan/profiles/", {onComplete: function(result){ 
    127         $("profiles").empty(); 
    128                 for(var i = 0; i < result.length; i++){ 
    129                         var opt = new Element("option", {"value": result[i][1]}) 
    130                         opt.setText(result[i][0]); 
    131                         $("profiles").adopt(opt); 
    132                 } 
    133                 var cmd = $("profiles").options[0].value; 
    134                 if($("target").value != ""){ 
    135                         cmd = cmd.replace("<target>", $("target").value); 
    136                 } 
    137                 $("command").value = cmd; 
    138         }}).send(); 
    139 } 
    140  
    141 function emptyTBody(tbody){ 
    142     for(var i = 0; i < tbody.rows.length; i++){ 
    143         tbody.deleteRow(0); 
    144     } 
    145 } 
    146  
    147 window.addEvent("domready", function(){ 
    148     var size = getViewportSize(); 
    149     $$("div[class='tab-placeholder']").each(function(div){ 
    150             div.style.height = (size[1]-271) + "px"; 
     191  } 
     192 
     193  $.fn.extend(UmitStyleMethods); 
     194  $.fn.extend(UmitApplicationManager); 
     195  $.expander = function(selectors){ 
     196    $(selectors).live("click", function(){ 
     197      var target = $("#" + $(this).attr("id") + "-detail"); 
     198     
     199      var source = $(this); 
     200     
     201      target.toggleClass("hide"); 
     202     
     203      if(source.collapsed()){ 
     204        source.removeClass("sw-collapsed").addClass("sw-expanded"); 
     205      }else{ 
     206        source.removeClass("sw-expanded").addClass("sw-collapsed"); 
     207      } 
    151208    }); 
    152          
    153     if($defined($("hosts"))) 
    154             $("hosts").style.height = (size[1]-220) + "px"; 
    155     if($defined($("services"))) 
    156             $("services").style.height = (size[1]-220) + "px"; 
    157          
    158     if($defined($("body"))){ 
    159             $("body").setStyle("width", (size[0]) + "px"); 
    160         $("umit-title").setStyle("width", size[0]-60 + "px"); 
    161     } 
    162     if($defined($("footer"))) 
    163        $("footer").injectInside($("body")); 
    164     if($defined($("nmap-output"))){ 
    165         $("nmap-output").style.height = size[1]-320 + "px"; 
    166     } 
    167 }); 
     209  } 
     210})(jQuery); 
  • branch/umitweb-ng/share/umit/umitweb_media/js/index.js

    r3432 r5533  
     1/* 
    12var varData = ""; 
    23 
     
    5455        rs.run(); 
    5556} 
     57*/ 
    5658 
    57 window.addEvent("domready", function(){ 
    58     if($defined($("frmScan"))){ 
    59         $("frmScan").addEvent("submit", runScan); 
    60          
    61             $("toggleHosts").addEvent("click", function(e){ 
    62                     if(!this.hasClass("active")){ 
    63                     var ts = $("toggleServices"); 
    64                     this.addClass("active"); 
    65                     ts.removeClass("active"); 
    66                     $("hosts").setStyle("display", "block"); 
    67                     $("services").setStyle("display", "none"); 
    68                 } 
    69                 new Event(e).stop(); 
    70         }); 
    71          
    72             $("toggleServices").addEvent("click", function(e){ 
    73             if(!this.hasClass("active")){ 
    74                     var th = $("toggleHosts"); 
    75                     this.addClass("active"); 
    76                     th.removeClass("active"); 
    77                     $("hosts").setStyle("display", "none"); 
    78                     $("services").setStyle("display", "block"); 
    79                 } 
    80                 new Event(e).stop(); 
    81         }); 
    82  
    83         $("toggleHosts").addClass("active"); 
    84         $("services").setStyle("display", "none"); 
    85          
    86         updateProfiles(); 
    87          
    88             $("profiles").addEvent("change", function(event){ 
    89                 var cmd = this.options[this.selectedIndex].value; 
    90                 if($("target").value != ""){ 
    91                         cmd = cmd.replace("<target>", $("target").value); 
    92                 } 
    93                 $("command").value = cmd; 
    94                 new Event(event).stop(); 
    95         }); 
    96         $("divSpinner").addClass("hide"); 
    97         $("body").removeClass("hide"); 
     59$(function(){ 
     60  $("#frmScan").scanForm();  
     61  $("#target").scanTarget(); 
     62  $("#command").scanCommand(); 
     63  $("#result_window").resultBox(); 
     64  $("#profile_name").scanProfileName(); 
     65  $("#profiles").loadProfiles(function(data){ 
     66    var cmd = $(this).children("option:first").val(); 
     67    if(UmitWeb.inputs.target.val().length > 0){ 
     68      cmd = cmd.replace("<target>", UmitWeb.inputs.target.val()); 
    9869    } 
    99  
    100    $("highlight_out").addEvent("change", function(e){ 
    101             new Event(e).stop(); 
    102         if(!nmapOutput || nmapOutput.trim().length == 0){ return } 
    103         if(this.checked){ 
    104                 $("nmap-output").setHTML(formatNmapOutput(nmapOutput)); 
    105         }else{ 
    106                 $("nmap-output").setText(nmapOutput); 
    107         } 
    108    }); 
     70     
     71    $("#command").val(cmd); 
     72  }); 
     73   
     74  $("#toggleHosts").click("click", function(){ 
     75    if($(this).active()) return false; 
     76     
     77    $(this).active(true); 
     78    $("#toggleServices").active(false); 
     79    $("#hosts").toggleWith("#services"); 
     80    return false; 
     81  }); 
     82   
     83  $("#toggleServices").click(function(){ 
     84    if($(this).active()) return false; 
     85    $(this).active(true); 
     86     
     87    $("#toggleHosts").active(false); 
     88    $("#services").toggleWith("#hosts"); 
     89    return false; 
     90  }); 
     91   
     92  $("#toggleHosts").active(true); 
     93  $("#hosts").toggleWith("#services"); 
     94   
     95  $("#profiles").change(function(){ 
     96    var cmd = $(this).children("option:selected").val(); 
     97    if($("#target")[0] != undefined && $("#target")[0].value.length > 0){ 
     98      cmd = cmd.replace("<target>", $("#target").val()); 
     99    } 
     100    $("#command").val(cmd); 
     101    return false; 
     102  }); 
     103   
     104  $("#divSpinner").fadeOut(1000, function(){$("#body").fadeIn(500)}); 
     105   
     106  $("#highlight_out").change(function(){ 
     107    if(nmapOutput.trim().length == 0) return; 
     108    $("#nmap-output").text(nmapOutput); 
     109    if(this.checked) $("#nmap-output").formatScanOutput(); 
     110  }); 
     111   
     112  $.expander(".sw-expanded, .sw-collapsed"); 
    109113}); 
  • branch/umitweb-ng/share/umit/umitweb_media/js/scan.js

    r5439 r5533  
    1 var h; 
     1var UmitScanner = new Object(); 
    22 
    3 function loadHosts(html){ 
    4   $("hosts").setHTML(html); 
    5   attachHostsEvents(); 
     3UmitScanner.run = function(){ 
     4  send = true; 
     5  if(!UmitWeb.scan.saved && UmitWeb.scan.id){ 
     6    var text = "The given scan has unsaved changes!\n" + 
     7               "If you want to continue, click 'OK'.\n" + 
     8               "WARNING: all unsaved data will be lost."; 
     9    if(!confirm(text)) send = false; 
     10  } 
     11   
     12  if(!send) return; 
     13   
     14  var resultBox = UmitWeb.resultBox; 
     15  if(!resultBox) return; 
     16   
     17  resultBox.prepareForScan(); 
     18   
     19  this.post(); 
    620} 
    721 
    8 function loadServices(html){ 
    9   $("services").setHTML(html); 
    10   attachServiceEvents(); 
     22UmitScanner.prepareForScan = function(){ 
     23  var rb = UmitWeb.resultBox; 
     24  rb.children("#nmap-output").empty().addClass("ajax-loading"); 
     25  var loading_line = $("<tr><td><img src='/media/images/spinner.gif'/></td>" +  
     26                     "<td>Running...</td></tr>"); 
     27  rb.children("#hosts_table").children("tbody").empty().append(loading_line); 
     28   
     29  rb.children("#hosts_tab").empty(); 
     30  rb.children("#scan_details").empty(); 
     31  rb.children("#tabber-result").tabber.tabShow(1); 
     32  rb.children("#ports_table").children("tbody").empty(); 
     33  rb.children("#services_table").children("tbody").empty(); 
    1134} 
    1235 
    13 function attachHostsEvents(){ 
    14   $("hosts").getElements("a").each(function(lnk){ 
    15     lnk.addEvent("click", function(e){ 
    16       var event = new Event(e); 
    17       selectHost(this.getAttribute("href")); 
    18       event.stop(); 
    19       return false; 
    20     }); 
     36UmitScanner.post = function(){ 
     37  var _self = this; 
     38  $.post("/scan/", UmitWeb.scanForm.serialize(), function(data, textStatus){  
     39    _self.formPosted(data, textStatus) 
     40  }, "json"); 
     41} 
     42 
     43var _e = "hey"; 
     44UmitScanner.formPosted = function(data, textStatus){ 
     45  _e = this; 
     46  if(data.result == "OK"){ 
     47    this.checkStatus(data.id); 
     48  } 
     49} 
     50 
     51// TODO: implement failure http 
     52UmitScanner.checkStatus = function(id){ 
     53  var url = "/scan/" + id + "/check/"; 
     54  var _self = this; 
     55  $.getJSON(url, function(data, textStatus){ 
     56    if(data.result != "OK"){ 
     57      _self.showErrorMessage(data.status); 
     58      return; 
     59    } 
     60     
     61    if(data.status == "FINISHED"){ 
     62      _self.loadResult(id, data); 
     63    }else if(result.status == "RUNNING"){ 
     64      UmitWeb.nmapOutput = data.output.text; 
     65      UmitWeb.resultBox.text(UmitWeb.nmapOutput).formatOutput(); 
     66      setTimeout(function(){_self.checkStatus(id)}, 1000); 
     67    } 
     68     
     69    UmitWeb.scan.locked = false; 
    2170  }); 
    2271} 
    2372 
    24 function attachServiceEvents(){ 
    25   $("services").getElements("a").each(function(lnk){ 
    26     lnk.addEvent("click", function(e){ 
    27       var event = new Event(e); 
    28       try{selectService(this.getAttribute("href"));}catch(e){alert(e)} 
    29       event.stop(); 
    30       return false; 
    31     }) 
     73UmitScanner.showErrorMessage = function(text){ 
     74  UmitWeb.resultBox.addClass("ajax-error").text(text); 
     75} 
     76 
     77UmitScanner.loadResult = function(id, data){ 
     78  UmitWeb.resultBox.removeClass("ajax-loading"); 
     79  UmitWeb.resultBox.text(data.output.plain).formatOutput(); 
     80  UmitWeb.scan.id = id; 
     81  UmitWeb.scan.object = data; 
     82  this.renderResponse(); 
     83} 
     84 
     85UmitScanner.renderResponse = function(){ 
     86  var tabs = UmitWeb.scan.object.output.tabs; 
     87  this.loadHosts(tabs.hosts); 
     88  this.loadServices(tabs.services); 
     89   
     90  $("#ports_table_placeholder").html(tabs.ports); // ports tab 
     91  $("#hosts_tab").html(tabs.host_details);        // host details tab 
     92  $("#scan_details").html(tabs.scan_info);        // scan info tab 
     93  try{this.selectHost(0);}catch(e){}              // Select the first host 
     94  UmitWeb.scan.saved = false; 
     95} 
     96 
     97UmitScanner.loadHosts = function(html){ 
     98  $("#hosts").html(html); 
     99  var _self = this; 
     100  $("#hosts").children("a").click(function(){ 
     101    _self.selectHost(parseInt($(this).attr("href"))); 
     102    return false; 
    32103  }); 
    33104} 
    34105 
    35 function selectHost(index){ 
    36   index = parseInt(index); 
    37   $("ports_table_placeholder").setStyle("display", "block"); 
    38   $("hosts_s_table_placeholder").setStyle("display", "none"); 
     106UmitScanner.loadServices = function(html){ 
     107  $("#services").html(html); 
     108  var _self = this; 
     109  $("#services").children("a").click(function(){ 
     110    _self.selectService(parseInt($(this).attr("href"))); 
     111    return false; 
     112  }); 
     113} 
    39114 
     115UmitScanner.selectHost = function(id){ 
     116  $("#ports_table_placeholder").toggleWith("#hosts_s_table_placeholder"); 
     117   
    40118  // TODO: implement Ctrl/Command and Shift key modifiers 
     119  if(!$("#host-" + id)) return; 
    41120   
    42   if(!$defined($("host-" + index))) return; 
    43121  // cleanup previously selected items 
    44   $("hosts_table").getElements("tr").removeClass("selected"); 
    45   $("host-" + index).toggleClass("selected"); 
     122  $("#hosts_table").children("tr").removeClass("selected"); 
     123  $("#host-" + id).toggleClass("selected"); 
    46124   
    47125  // Show the message that tells to select a host, while we are rendering 
    48126  // the screen details. 
    49   $("none-host-detail-selected").removeClass("hide"); 
    50   $("none-host-selected").removeClass("hide"); 
     127  $("#none-host-detail-selected, #none-host-selected").removeClass("hide"); 
    51128   
    52129  // Show hosts tab 
    53   $("hosts_tab").getElements(".host_detail_tab_element").addClass("hide"); 
    54   $$(".ports-table, .services-table, #none-host-selected").addClass("hide"); 
    55   $("host" + index + "-detail").removeClass("hide");   
     130  $("#hosts_tab").children(".host_detail_tab_element").addClass("hide"); 
     131  $("#host" + id + "-detail").removeClass("hide");   
    56132   
    57133  // Show ports/services tab 
    58   $("ports_table_placeholder").getElements(".ports-table").addClass("hide"); 
    59   $("host-" + index + "-ports-div").removeClass("hide"); 
     134  $("#ports_table_placeholder").children(".ports-table").addClass("hide"); 
     135  $("#host-" + id + "-ports-div").removeClass("hide"); 
    60136 
    61137  // Hide the message that tells to select a host 
    62   $("none-host-selected").addClass("hide"); 
    63   $("none-host-detail-selected").addClass("hide"); 
     138  $("#none-host-selected, #none-host-detail-selected, .ports-table, .services-table").addClass("hide"); 
     139  return false; 
    64140} 
    65141 
    66 function selectService(service_id){ 
    67  
     142UmitScanner.selectService = function(id){ 
    68143  // TODO: implement Ctrl / Shift behavior 
    69144   
    70   $("services_table").getElement("tBody").getElements("tr").each(function(el){ 
    71     el.removeClass("selected"); 
    72   }); 
    73  
    74   $("service-" + service_id).toggleClass("selected"); 
     145  $("#services_table").children("tr").removeClass("selected"); 
     146  $("#service-" + id).toggleClass("selected"); 
    75147   
    76148  // hide other port tables 
    77   $$(".ports-table, .services-table, #none-host-selected").addClass("hide"); 
     149  $(".ports-table, .services-table, #none-host-selected").addClass("hide"); 
    78150   
    79151  // show this table 
    80   $("service-" + service_id + "-services-div").removeClass("hide"); 
     152  $("#service-" + id + "-services-div").removeClass("hide"); 
    81153 
    82154  return false; 
    83155} 
    84  
    85 function loadPortsTab(html){ $("ports_table_placeholder").setHTML(html); } 
    86  
    87 function loadHostsTab(html){ $("hosts_tab").setHTML(html); } 
    88  
    89 function loadScanInfo(html){ $("scan_details").setHTML(html); } 
    90  
    91 var _e; 
    92 function loadScanData(scan){ 
    93   var tabs = scan.output.tabs; 
    94   loadHosts(tabs.hosts); 
    95   loadServices(tabs.services); 
    96   loadPortsTab(tabs.ports); 
    97   loadHostsTab(tabs.host_details); 
    98   loadScanInfo(tabs.scan_info); 
    99   try{selectHost(0);}catch(e){} 
    100   saved = false; 
    101 } 
    102  
    103 function checkScanStatus(scanID){ 
    104     checkUrl = "/scan/" + scanID + "/check/" 
    105     new Json.Remote(checkUrl, {onComplete: function(result){ 
    106         if(result.result == "OK"){ 
    107             resultBox = $("nmap-output"); 
    108             if(result.status == "FINISHED"){ 
    109               resultBox.removeClass("ajax-loading"); 
    110               nmapOutput = result.output.plain; 
    111               if(!$("highlight_out").checked){ 
    112                 resultBox.setText(nmapOutput) 
    113               }else{ 
    114                 resultBox.setHTML(formatNmapOutput(nmapOutput)) 
    115               } 
    116               scanId = scanID 
    117               varData = result.output.full 
    118               loadScanData(result) 
    119             }else if(result.status == "RUNNING"){ 
    120               setTimeout("checkScanStatus('" + scanID + "')", 1000) 
    121               nmapOutput = result.output.text 
    122               if(!$("highlight_out").checked){ 
    123                 resultBox.empty().setText(nmapOutput) 
    124               }else{ 
    125                 resultBox.empty().setHTML(formatNmapOutput(nmapOutput)) 
    126               } 
    127             } 
    128         }else{ 
    129             resultBox.addClass("ajax-error").setText(result.status); 
    130         } 
    131         scanLock = false; 
    132             }, 
    133             onFailure: function(req){ 
    134               $("nmap-output").removeClass("ajax-loading"); 
    135               emptyTBody($("hosts_table").getElement("tbody")); 
    136                
    137         if(req.status == 200){ 
    138           $("nmap-output").setHTML(req.responseText); 
    139         }else{ 
    140           showError(req, $("nmap-output").empty()) 
    141         } 
    142         scanLock = false; 
    143             } 
    144             }).send(); 
    145 } 
    146  
    147 function runScan(e){ 
    148   e = new Event(e); 
    149   isToBeSent = true; 
    150   if(saved == false && scanId != null){ 
    151     text = "The given scan has unsaved changes!\n" + 
    152       "If you want to continue, click 'OK'.\n" + 
    153       "WARNING: all unsaved data will be lost."; 
    154     if(!confirm(text)){ 
    155       isToBeSent = false; 
    156     } 
    157   } 
    158    
    159   if(isToBeSent){ 
    160     scanEvent = e; 
    161     result_box = $("nmap-output"); 
    162     result_box.empty().addClass("ajax-loading"); 
    163     tbHosts = $("hosts_table").getElement("tbody"); 
    164     emptyTBody(tbHosts); 
    165     tr = new Element("tr"); 
    166     td1 = new Element("td"); 
    167     td1.adopt(new Element("img", {'src': '/media/images/spinner.gif'})); 
    168     tr.adopt(td1); 
    169     td2 = new Element("td"); 
    170     td2.setText("Running..."); 
    171     tr.adopt(td2); 
    172     tbHosts.adopt(tr); 
    173     //tr2 = tr.cloneNode(); 
    174      
    175     emptyTBody($("ports_table").getElement("tbody")); 
    176     $("hosts_tab").empty(); 
    177     $("scan_details").empty(); 
    178     $("tabber-result").tabber.tabShow(1); 
    179     emptyTBody($("services_table").getElement("tbody")); 
    180     var txtContent = $("profiles")[$("profiles").selectedIndex].textContent; 
    181     $("profile_name").value = txtContent; 
    182    
    183     args = { 
    184       target: $("target").value, 
    185       command: $("command").value, 
    186       profile: $("profiles")[$("profiles").selectedIndex].value, 
    187       profile_name: $("profiles")[$("profiles").selectedIndex].textContent 
    188     } 
    189      
    190     reqObj = new XHR("post"); 
    191     reqObj.send("/scan/", Object.toQueryString(args)); 
    192     checkIfFinished(); 
    193   } 
    194   e.stop(); 
    195 } 
    196 var reqObj = null; 
    197 function checkIfFinished(){ 
    198   response = null; 
    199   try{ 
    200     eval("response = " + reqObj.transport.responseText); 
    201     reqObj.cancel(); 
    202     checkScanStatus(response.id); 
    203   }catch(e){ 
    204     setTimeout("checkIfFinished()", 1000); 
    205   } 
    206 } 
  • branch/umitweb-ng/umit/web/Urls.py

    r5400 r5533  
    6767    (r'^media/js/output_highlight.js$', 'umit.web.views.main.output_highlight'), 
    6868    (r'^media/js/diff_colors.js$', 'umit.web.views.compare_results.diff_colors'), 
     69    (r'^media/css/output_highlight.css$', 'umit.web.views.main.output_highlight_css'), 
    6970    (r'^media/(?P<path>.*)$', 'umit.web.views.main.serve_media'), 
    7071    (r'^docs/(?P<path>.*)$', 'umit.web.views.main.serve_docs') 
  • branch/umitweb-ng/umit/web/views/main.py

    r5208 r5533  
    2929from umit.web.WebPaths import WPath as Path 
    3030from umit.web.Security import Context 
     31from umit.web import simplejson as json 
    3132import mimetypes 
    3233 
     
    4445@authenticate(ERROR) 
    4546def output_highlight(req): 
     47    """Generates automatically a Javascript file containing the 
     48    regular expression definitions for scan highlights. 
     49    """ 
    4650    response = HttpResponse() 
    4751    response['Content-type'] = "text/javascript; charset=utf-8" 
     
    4953    attrDic = {} 
    5054 
    51     response.write("highlights = {};\n") 
     55    out = {} 
    5256    for attr in ["closed_port", "date", "details", "filtered_port", 
    5357                 "hostname", "ip", "open_port", "port_list"]: 
    5458        attribute = getattr(highlight, attr) 
    55         response.write("highlights['%s'] = {};\n" % attr) 
    56         for index, value in enumerate(['bold', 'italic', 'underline', 'text', 'highlight', 'regex']): 
    57             if type(attribute[index]) == ListType: 
    58                 propValue = "#%s%s%s" % tuple(map(lambda value: "%0.2x" % floor(sqrt(value)), attribute[index])) 
    59             elif type(attribute[index]) == StringType: 
    60                 propValue = attribute[index].replace("\\", "\\\\") 
    61             else: 
    62                 propValue = attribute[index] 
    63             response.write("highlights['%s']['%s'] = '%s';\n" % (attr, value, propValue)) 
     59        out[attr] = attribute[-1] 
     60    response.write("var highlights = " + json.dumps(out)) 
     61    return response 
     62 
     63@authenticate(ERROR) 
     64def output_highlight_css(req): 
     65    """Generates automatically a CSS file containing the style 
     66    definitions for scan highlight. 
     67    """ 
     68    response = HttpResponse() 
     69    response['Content-type'] = "text/css; charset=utf-8" 
     70    highlights = JsOutputHighlight() 
     71    for attr in ["closed_port", "date", "details", "filtered_port", 
     72                 "hostname", "ip", "open_port", "port_list"]: 
     73        attribute = getattr(highlights, attr) 
     74        response.write(".scan-%s{" % attr) 
     75         
     76        color = "#%s%s%s" % tuple(map(lambda value: "%0.2x" % floor(sqrt(value)), attribute[3])) 
     77        response.write("color: %s; " % color) 
     78         
     79        bgcolor = "#%s%s%s" % tuple(map(lambda value: "%0.2x" % floor(sqrt(value)), attribute[4])) 
     80        response.write("background-color: %s; " % bgcolor) 
     81         
     82        # bold 
     83        if attribute[0]: 
     84            response.write("font-weight: bold; "); 
     85        # italic 
     86        if attribute[1]: 
     87            response.write("font-style: italic; "); 
     88        # underline 
     89        if attribute[2]: 
     90            response.write("text-decoration: underline; "); 
     91        response.write("}\n") 
    6492    return response 
    6593