summaryrefslogtreecommitdiffstats
path: root/freeradius3-editmacauthfile-html.lsp
diff options
context:
space:
mode:
Diffstat (limited to 'freeradius3-editmacauthfile-html.lsp')
-rw-r--r--freeradius3-editmacauthfile-html.lsp96
1 files changed, 96 insertions, 0 deletions
diff --git a/freeradius3-editmacauthfile-html.lsp b/freeradius3-editmacauthfile-html.lsp
new file mode 100644
index 0000000..756abf3
--- /dev/null
+++ b/freeradius3-editmacauthfile-html.lsp
@@ -0,0 +1,96 @@
+<% local form, viewlibrary, page_info = ... %>
+<% htmlviewfunctions = require("htmlviewfunctions") %>
+<% html = require("acf.html") %>
+
+<script type="text/javascript">
+ if (typeof jQuery == 'undefined') {
+ document.write('<script type="text/javascript" src="<%= html.html_escape(page_info.wwwprefix) %>/js/jquery-latest.js"><\/script>');
+ }
+</script>
+
+<script type="text/javascript">
+ var editEntry = '<td> \
+ <a href="javascript:;"><img src="<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-remove.png" width="16" height="16" title="Remove entry"></a> \
+ </td>';
+ var addEntry = '<tr><td> \
+ <a href="javascript:;"><img src="<%= html.html_escape(page_info.wwwprefix..page_info.staticdir) %>/tango/16x16/actions/list-add.png" width="16" height="16" title="Insert entry"></a> \
+ </td></tr>';
+
+ function deleteLine(){
+ $(this).parent().parent().replaceWith();
+ }
+ function addLine(){
+ addLinks($(this).parent().parent().before('<tr><td><input type="text" value=""></td></tr>').prev());
+ }
+ function addLinks(rows){
+ rows.each(function(){
+ $(this).prepend(editEntry);
+ $(this).find("td > a:last").click(deleteLine);
+ $(this).find("input").change(validateLine);
+ });
+ }
+ function validateLine(){
+ var regex = /^[0-9a-f]{12}$/;
+ var text = $(this).val().trim().replace(/[-:\s]/g, "").toLowerCase();
+ if (regex.test(text)) {
+ text = text.match(/.{2}/g).join("-");
+ $(this).val(text);
+ $(this).removeClass("error");
+ } else {
+ $(this).addClass("error");
+ }
+ }
+ function submitFile(){
+ var success = true;
+ var file = "";
+ var lines = $("#entries").find("input").each(function(index){
+ if ($(this).val() == "") {
+ $(this).parent().parent().replaceWith();
+ } else {
+ file = file + $(this).val() + "\n";
+ if ($(this).hasClass("error")) {
+ success = false;
+ }
+ }
+ });
+ $("input[name='filecontent']").val(file);
+ if ( ! success ) {
+ return false;
+ }
+ }
+
+ $(function(){
+ $("#entries").find("td:empty").parent().replaceWith();
+ $("#entries").find("td").contents().each(function(){
+ $(this).replaceWith("<input type='text' value='" + $(this).text() + "'>");
+ });
+ $("#entries").find("input").each(validateLine);
+ addLinks($("#entries").find("tr"));
+ $("#entries").append(addEntry).find("a:last").click(addLine);
+ $("form").submit(submitFile);
+ });
+</script>
+
+<%
+local header_level = htmlviewfunctions.displaysectionstart(cfe({label="Edit MAC Authentication File"}), page_info)
+htmlviewfunctions.displayitem(form.value.filename)
+htmlviewfunctions.displayitem(form.value.filesize)
+htmlviewfunctions.displayitem(form.value.mtime)
+local header_level2 = htmlviewfunctions.displaysectionstart(cfe({label="Entries"}), page_info, htmlviewfunctions.incrementheader(header_level))
+ htmlviewfunctions.displayformstart(form, page_info)
+ form.value.filename.type = "hidden"
+ htmlviewfunctions.displayformitem(form.value.filename, "filename")
+ form.value.filecontent.type = "hidden"
+ htmlviewfunctions.displayformitem(form.value.filecontent, "filecontent")
+%>
+<table id="entries">
+<% for line in string.gmatch(html.html_escape(form.value.filecontent.value), "([^\n]*)\n?") do %>
+ <tr><td><%= line %></td></tr>
+<% end %>
+</table>
+<%
+ htmlviewfunctions.displayinfo(form.value.filecontent)
+ htmlviewfunctions.displayformend(form)
+htmlviewfunctions.displaysectionend(header_level2)
+htmlviewfunctions.displaysectionend(header_level)
+%>