encode uri and html

This commit is contained in:
Eric A. Miller
2014-05-27 23:15:12 -04:00
parent 160756bbb6
commit 20b8de9d86
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

@@ -12,27 +12,37 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
var table = $('#data-table').dataTable({ var table = $('#data-table').dataTable({
"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 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) {
data: 'ip' return he.encode(data || '');
}, { }
data: 'contact' }, {
}, { "data": 'ip',
data: 'location' "render": function(data, type, row, meta) {
} return he.encode(data || '');
] }
}); }, {
"data": 'contact',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}, {
"data": 'location',
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}
]
});
}); });
</script> </script>

View File

@@ -47,66 +47,74 @@ function capitaliseFirstLetter(string) {
} }
$(document).ready(function() { $(document).ready(function() {
var table = $('#data-table').dataTable({ var table = $('#data-table').dataTable({
"deferRender": true, "deferRender": true,
"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) {
data: 'sw_ver' return he.encode(data || '');
}, { }
data: 'fw_ver' }, {
} "data": 'sw_ver',
[% ELSE %] { "render": function(data, type, row, meta) {
data: 'class', return he.encode(data || '');
render: function(data, type, full, meta) { }
return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + data + '">' + capitaliseFirstLetter(data) + '</a>'; }, {
} "data": 'fw_ver',
}, { "render": function(data, type, row, meta) {
data: 'count', return he.encode(data || '');
render: function(data, type, full, meta) { }
return data.replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
} [% ELSE %] {
} "data": 'class',
[% END %] "render": function(data, type, full, meta) {
] return '<a href="[% uri_for('/report/moduleinventory') %]?class=' + encodeURIComponent(data) + '">' + he.encode(capitaliseFirstLetter(data)) + '</a>';
}); }
}, {
"data": 'count',
"render": function(data, type, full, meta) {
return data.replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
}
[% END %]
]
});
}); });
</script> </script>

View File

@@ -11,31 +11,35 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(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 he.encode(row.dns || row.name || row.ip);
return (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=' + encodeURIComponent(row.ip) + '&f=' + encodeURIComponent(data) + '&c_nodes=on">' + he.encode(data) + '</a>';
return '<a href="[% device_ports %]&q=' + row.ip + '&f=' + data + '&c_nodes=on">' + data + '</a>'; }
} }, {
}, { "data": 'description',
"data": 'description' "render": function(data, type, row, meta) {
}, { return he.encode(data || '');
"data": 'up_admin', }
"orderable": false, }, {
"searchable": false, "data": 'up_admin',
} "orderable": false,
] "searchable": false,
}); "render": function(data, type, row, meta) {
return he.encode(data || '');
}
}
],
"data": [% results %]
});
}); });
</script> </script>

View File

@@ -7,46 +7,40 @@
<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">
$(document).ready(function() { $(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 %], "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) {
"data": 'stp', return he.encode(data || '');
"orderable": false, }
"searchable": false, }, {
} "data": 'stp',
] "orderable": false,
}); "searchable": false,
"render": function(data, type, row, meta) {
return he.encode(data || '');
}
}
]
});
}); });
</script> </script>