summaryrefslogtreecommitdiffstats
path: root/freeradius3-editmacauthfile-html.lsp
blob: 940abf25f89f3e084d452462809c0d4aefdd83bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<% 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><td></td></tr>';

	function deleteLine(){
		$(this).parent().parent().replaceWith();
	}
	function addLine(){
		addLinks($(this).parent().parent().after('<tr><td><input type="text" value=""></td></tr>').next());
	}
	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 (/^\s*$/.test($(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").prepend(addEntry).find("a:first").click(addLine);
		$("form").submit(submitFile);
	});
</script>

<h1>Edit MAC Authentication File</h1>
<dl>
<%
htmlviewfunctions.displayitem(form.value.filename)
htmlviewfunctions.displayitem(form.value.filesize)
htmlviewfunctions.displayitem(form.value.mtime)
%>
</dl>
<h2>Entries</h2>
<dl>
<%
	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>
<%
	if form.descr then io.write('<p class="descr">' .. string.gsub(html.html_escape(form.descr), "\n", "<br/>") .. '</p>') end
	if form.errtxt then io.write('<p class="error">' .. string.gsub(html.html_escape(form.errtxt), "\n", "<br/>") .. '</p>') end
	htmlviewfunctions.displayformend(form)
%>
</dl>