encode uri and html

This commit is contained in:
Eric A. Miller
2014-05-27 23:15:12 -04:00
parent 039e43f72e
commit efe17e96bb
6 changed files with 192 additions and 167 deletions

View File

@@ -15,18 +15,26 @@ $(document).ready(function() {
"deferRender": true, "deferRender": true,
"data": [% results %], "data": [% results %],
"columns": [{ "columns": [{
data: 'ip', "data": 'ip',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% search_device %]&q=' + data + '">' + (row.dns || row.name || row.ip) + '</a>'; return '<a href="[% search_device %]&q=' + encodeURIComponent(data) + '">' + he.encode(row.dns || row.name || row.ip) + '</a>';
} }
}, { }, {
data: 'alias' "data": 'alias',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'contact' "data": 'contact',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'location' "data": 'location',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
} }
] ]
}); });
});</script> });</script>

View File

@@ -14,37 +14,38 @@
$(document).ready(function() { $(document).ready(function() {
var table = $('#data-table').dataTable({ var table = $('#data-table').dataTable({
"deferRender": true, "deferRender": true,
"order": [[ 0, "asc" ], [2, "asc"], [ 3, "asc" ], [4, "asc"]],
"data": [% results %], "data": [% results %],
"columns": [ "columns": [
{ {
data: 'location', "data": 'location',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
if (data) { if (data) {
return '<a href="[% search_device %]&q=' + data + '&location=' + data + '">' + data + '</a>'; return '<a href="[% search_device %]&q=' + encodeURIComponent(data) + '&location=' + encodeURIComponent(data) + '">' + he.encode(data) + '</a>';
} else { } else {
return '[Not Set]'; return '[Not Set]';
} }
} }
}, { }, {
data: 'ip', "data": 'ip',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% uri_for('/device') %]?q=' + data + '">' + (row.dns || row.ip) + '</a>'; return '<a href="[% uri_for('/device') %]?q=' + encodeURIComponent(data) + '">' + he.encode(row.dns || row.ip) + '</a>';
} }
}, { }, {
data: 'name', "data": 'name',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% search_device %]&q=' + data + '&model=' + data + '">' + data + '</a>'; return '<a href="[% search_device %]&q=' + encodeURIComponent(data) + '&model=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'vendor', "data": 'vendor',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% search_device %]&q=' + data + '&model=' + data + '">' + data + '</a>'; return '<a href="[% search_device %]&q=' + encodeURIComponent(data) + '&model=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'model', "data": 'model',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% search_device %]&q=' + data + '&model=' + data + '">' + data + '</a>'; return '<a href="[% search_device %]&q=' + encodeURIComponent(data) + '&model=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
} }
] ]

View File

@@ -17,22 +17,32 @@ $(document).ready(function() {
"data": [% results %], "data": [% results %],
"columns": [ "columns": [
{ {
data: 'ip', "data": 'ip',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a search_device %]&q=' + data + '">' + (row.ip || row.name) + '</a>'; return '<a search_device %]&q=' + encodeURIComponent(data) + '">' + he.encode(row.ip || row.name) + '</a>';
} }
}, { }, {
data: 'dns' "data": 'dns',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'ip' "data": 'ip',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'contact' "data": 'contact',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'location' "data": 'location',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
} }
] ]
}); });
}); });
</script> </script>

View File

@@ -52,61 +52,69 @@ $(document).ready(function() {
"data": [% results %], "data": [% results %],
"columns": [ "columns": [
[% IF opt %] { [% IF opt %] {
data: 'ip', "data": 'ip',
render: function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% uri_for('/device') %]?tab=modules&q=' + data + '">' + (row.device.dns || row.device.name || row.ip) + '</a>'; return '<a href="[% uri_for('/device') %]?tab=modules&q=' + encodeURIComponent(data) + '">' + he.encode(row.device.dns || row.device.name || row.ip) + '</a>';
} }
}, { }, {
data: 'description', "data": 'description',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?description=' + data + '">' + data + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?description=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'name', "data": 'name',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?name=' + data + '">' + data + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?name=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'class', "data": 'class',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + data + '">' + capitaliseFirstLetter(data) + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + encodeURIComponent(data) + '">' + he.encode(capitaliseFirstLetter(data)) + '</a>';
} }
}, { }, {
data: 'type', "data": 'type',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?type=' + data + '">' + data + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?type=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'model', "data": 'model',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?model=' + data + '">' + data + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?model=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'serial', "data": 'serial',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?serial=' + data + '">' + data + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?serial=' + encodeURIComponent(data) + '">' + he.encode(data || '') + '</a>';
} }
}, { }, {
data: 'hw_ver' "data": 'hw_ver',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'sw_ver' "data": 'sw_ver',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
data: 'fw_ver' "data": 'fw_ver',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
} }
[% ELSE %] { [% ELSE %] {
data: 'class', "data": 'class',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + data + '">' + capitaliseFirstLetter(data) + '</a>'; return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + encodeURIComponent(data) + '">' + he.encode(capitaliseFirstLetter(data)) + '</a>';
} }
}, { }, {
data: 'count', "data": 'count',
render: function(data, type, full, meta) { "render": function(data, type, full, meta) {
return data.replace(/\B(?=(\d{3})+(?!\d))/g, ","); return data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
} }
} }
[% END %] [% END %]
] ]
}); });
}); });
</script> </script>

View File

@@ -14,28 +14,32 @@ $(document).ready(function() {
var table = $('#data-table').dataTable({ var table = $('#data-table').dataTable({
"deferRender": true, "deferRender": true,
"order": [[ 0, "asc" ], [1, "asc"]], "order": [[ 0, "asc" ], [1, "asc"]],
"data": [% results %],
"columns": [ "columns": [
{ {
"data": 'ip', "data": 'ip',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return (row.dns || row.name || row.ip); return he.encode(row.dns || row.name || row.ip);
} }
}, { }, {
"data": 'port', "data": 'port',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + row.ip + '&f=' + data + '&c_nodes=on">' + data + '</a>'; return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>';
} }
}, { }, {
"data": 'description' "data": 'description',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
"data": 'up_admin', "data": 'up_admin',
"orderable": false, "orderable": false,
"searchable": false, "searchable": false,
"render": function(data, type, row, meta) {
return he.encode(data || '');
} }
] }
],
"data": [% results %]
}); });
}); });
</script> </script>

View File

@@ -7,17 +7,6 @@
<th>STP Status</th> <th>STP Status</th>
</tr> </tr>
</thead> </thead>
</tbody>
[% FOREACH row IN results %]
<tr>
<td>[% row.dns || row.name || row.ip | html_entity %]</td>
<td class="nd_center-cell"><a href="[% device_ports %]&q=[% row.ip | uri %]&f=[% row.port | uri %]&c_nodes=on">
[% row.port | html_entity %]</a></td>
<td class="nd_center-cell">[% row.description | html_entity %]</td>
<td class="nd_center-cell">[% row.stp | html_entity %]</td>
</tr>
[% END %]
</tbody>
</table> </table>
<script type="text/javascript"> <script type="text/javascript">
@@ -30,23 +19,28 @@ $(document).ready(function() {
{ {
"data": 'ip', "data": 'ip',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return (row.dns || row.name || row.ip); return he.encode(row.dns || row.name || row.ip);
} }
}, { }, {
"data": 'port', "data": 'port',
"render": function(data, type, row, meta) { "render": function(data, type, row, meta) {
return '<a href="[% device_ports %]&q=' + row.ip + '&f=' + data + '&c_nodes=on">' + data + '</a>'; return '<a href="[% device_ports %]&q=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>';
} }
}, { }, {
"data": 'description' "data": 'description',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, { }, {
"data": 'stp', "data": 'stp',
"orderable": false, "orderable": false,
"searchable": false, "searchable": false,
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
} }
] ]
}); });
}); });
</script> </script>