root/branch/umitweb-ng/share/umit/umitweb_media/js/common.js @ 5415

Revision 5415, 4.9 kB (checked in by rcarvalho, 12 months ago)

Start using jQuery on login page.

In future commits, the entirely system will be ported to jQuery.
I've also added some CSS3 styles into common.css, so we can stop
setting the CSS via javascript.

Line 
1var last_host_scanned = "<target>";
2var slides = {};
3
4fillCommand = function(value){
5    $('command').value = $('command').value.replace(last_host_scanned, value);
6    last_host_scanned = value;
7}
8
9function 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
18function 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
34function 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 ];
40    }
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
56function 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
85function 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
114function 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
125function 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
141function emptyTBody(tbody){
142    for(var i = 0; i < tbody.rows.length; i++){
143        tbody.deleteRow(0);
144    }
145}
146
147window.addEvent("domready", function(){
148    var size = getViewportSize();
149    $$("div[class='tab-placeholder']").each(function(div){
150            div.style.height = (size[1]-271) + "px";
151    });
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});
Note: See TracBrowser for help on using the browser.