From aadac1879616b0fa5b984158de493024d862f93f Mon Sep 17 00:00:00 2001 From: hummypkg Date: Wed, 22 Feb 2012 01:14:12 +0000 Subject: [PATCH] add editor git-svn-id: file:///root/webif/svn/humax/pkg/src/webif/trunk@753 2a923420-c742-0410-a762-8d5b09965624 --- var/mongoose/cgi-bin/browse.jim | 1 + var/mongoose/cgi-bin/browse/browse.js | 20 ----------- var/mongoose/cgi-bin/edit/edit.jim | 43 ++++++++++++++++++++++ var/mongoose/cgi-bin/edit/get.jim | 24 +++++++++++++ var/mongoose/cgi-bin/edit/put.jim | 23 ++++++++++++ var/mongoose/cgi-bin/edit/script.js | 51 +++++++++++++++++++++++++++ var/mongoose/cgi-bin/edit/style.css | 18 ++++++++++ var/mongoose/html/diag.shtml | 23 ++++++++++-- var/mongoose/html/js/enadis.js | 20 +++++++++++ var/mongoose/html/js/tabsupport.js | 23 ++++++++++++ 10 files changed, 224 insertions(+), 22 deletions(-) create mode 100755 var/mongoose/cgi-bin/edit/edit.jim create mode 100755 var/mongoose/cgi-bin/edit/get.jim create mode 100755 var/mongoose/cgi-bin/edit/put.jim create mode 100644 var/mongoose/cgi-bin/edit/script.js create mode 100644 var/mongoose/cgi-bin/edit/style.css create mode 100755 var/mongoose/html/js/enadis.js create mode 100644 var/mongoose/html/js/tabsupport.js diff --git a/var/mongoose/cgi-bin/browse.jim b/var/mongoose/cgi-bin/browse.jim index 4e88f7f..38a05ef 100755 --- a/var/mongoose/cgi-bin/browse.jim +++ b/var/mongoose/cgi-bin/browse.jim @@ -217,6 +217,7 @@ puts { + } diff --git a/var/mongoose/cgi-bin/browse/browse.js b/var/mongoose/cgi-bin/browse/browse.js index f3e71e1..350724d 100755 --- a/var/mongoose/cgi-bin/browse/browse.js +++ b/var/mongoose/cgi-bin/browse/browse.js @@ -1,23 +1,3 @@ -(function($) -{ - $.fn.enable = function() - { - return this.each(function() { - $(this) - .removeClass('ui-state-disabled') - .removeProp('disabled'); - }); - }; - - $.fn.disable = function() - { - return this.each(function() { - $(this) - .addClass('ui-state-disabled') - .prop('disabled', true); - }); - }; -})(jQuery); var dir; diff --git a/var/mongoose/cgi-bin/edit/edit.jim b/var/mongoose/cgi-bin/edit/edit.jim new file mode 100755 index 0000000..41fcae1 --- /dev/null +++ b/var/mongoose/cgi-bin/edit/edit.jim @@ -0,0 +1,43 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/var/mongoose/lib/setup + +puts "Content-Type: text/html" +puts "" + +header + +cgi_input +#cgi_dump +set file [cgi_get file "/tmp/hosts"] + +puts " + + + + + +
+File Editor +
+ Editing: $file +
+ + +
+ + +
+
+
+ +
+" + +footer + diff --git a/var/mongoose/cgi-bin/edit/get.jim b/var/mongoose/cgi-bin/edit/get.jim new file mode 100755 index 0000000..735044b --- /dev/null +++ b/var/mongoose/cgi-bin/edit/get.jim @@ -0,0 +1,24 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/var/mongoose/lib/setup +require chunked + +cgi_input +#cgi_dump + +set file [cgi_get file "/tmp/hosts"] +if {$file eq "-"} { exit } + +start_chunked + +if {![file exists $file]} { + chunk ">>> File $file does not exist.\r\n" +} else { + set fp [open $file r] + chunk [read $fp] + close $fp +} + +end_chunked + diff --git a/var/mongoose/cgi-bin/edit/put.jim b/var/mongoose/cgi-bin/edit/put.jim new file mode 100755 index 0000000..eb318da --- /dev/null +++ b/var/mongoose/cgi-bin/edit/put.jim @@ -0,0 +1,23 @@ +#!/mod/bin/jimsh + +package require cgi +source /mod/var/mongoose/lib/setup + +puts "Content-Type: text/html" +puts "" + +cgi_input +#cgi_dump + +set file [cgi_get file "/tmp/testfile"] +if {$file eq "-"} { exit } +set data [cgi_get data] + +if {[catch {set fp [open $file w]} msg]} { + puts "Error, $msg" +} else { + $fp puts -nonewline $data + close $fp + puts "File saved." +} + diff --git a/var/mongoose/cgi-bin/edit/script.js b/var/mongoose/cgi-bin/edit/script.js new file mode 100644 index 0000000..d33f9a4 --- /dev/null +++ b/var/mongoose/cgi-bin/edit/script.js @@ -0,0 +1,51 @@ + +$(function() { + +var file = $('#filename').text(); + +function loadfile() +{ + $('button.afterload').disable(); + $('#editor') + .addClass('loading') + .val('Loading file...'); + $.get('get.jim?file=' + encodeURIComponent(file), function(data) { + $('#editor') + .removeClass('loading') + .val(data); + $('button.afterload').enable(); + }); +} + +$('#save') + .button() + .click(function() { + $.post('put.jim', { + 'file': file, + 'data': $('#editor').val() + }, function(data) { + $('#result') + .html(data) + .slideDown('slow') + .delay(5000) + .slideUp('slow'); + }); + }); + +$('#revert') + .button() + .click(function() { + loadfile(); + }); + +$('#back') + .button() + .click(function() { + window.location = '/diag.shtml'; + }); + +$('#editor').tabsupport(); +loadfile(); + +}); + diff --git a/var/mongoose/cgi-bin/edit/style.css b/var/mongoose/cgi-bin/edit/style.css new file mode 100644 index 0000000..06a07fd --- /dev/null +++ b/var/mongoose/cgi-bin/edit/style.css @@ -0,0 +1,18 @@ +textarea +{ + background: white; + font-color: black; +} + +#filename +{ + font-style: italic; +} + +.loading +{ + font-style: italic; + color: #aaa; + background: white; +} + diff --git a/var/mongoose/html/diag.shtml b/var/mongoose/html/diag.shtml index 75af1f1..919ccd7 100644 --- a/var/mongoose/html/diag.shtml +++ b/var/mongoose/html/diag.shtml @@ -1,6 +1,8 @@ -
+ + +
Diagnostics Diagnostic: Run Diagnostic
-
+
+File Editor +File: + + +
+ +
Log Files
@@ -27,6 +38,14 @@ $('#rundiag').button().click(function() { $('#results').wrapInner('
');
 	    });
 });
+
+$('#runedit').button().click(function() {
+	if ($('#editfile').val().length)
+		window.location = '/cgi-bin/edit/edit.jim?file=' +
+		    encodeURIComponent($('#editfile').val());
+});
+
+
 $('a.log').click(function() {
 	$('#results')
 	    .slideDown()
diff --git a/var/mongoose/html/js/enadis.js b/var/mongoose/html/js/enadis.js
new file mode 100755
index 0000000..fb91ac1
--- /dev/null
+++ b/var/mongoose/html/js/enadis.js
@@ -0,0 +1,20 @@
+(function($)
+{
+	$.fn.enable = function()
+	{
+		return this.each(function() {
+			$(this)
+			    .removeClass('ui-state-disabled')
+			    .removeProp('disabled');
+		});
+	};
+
+	$.fn.disable = function()
+	{
+		return this.each(function() {
+			$(this)
+			    .addClass('ui-state-disabled')
+			    .prop('disabled', true);
+		});
+	};
+})(jQuery);
diff --git a/var/mongoose/html/js/tabsupport.js b/var/mongoose/html/js/tabsupport.js
new file mode 100644
index 0000000..0b7f525
--- /dev/null
+++ b/var/mongoose/html/js/tabsupport.js
@@ -0,0 +1,23 @@
+(function($)
+{
+	$.fn.tabsupport = function()
+	{
+		return this.each(function() {
+		    $(this).keydown(function(e) {
+			if (e.keyCode == 9)
+			{
+				var el = $(this).get(0);
+				var start = el.selectionStart;
+				var end = el.selectionEnd;
+				$(this).val(
+				    $(this).val().substring(0, start) +
+				    "\t" +
+				    $(this).val().substring(end)
+				);
+				el.selectionStart = el.selectionEnd = start + 1;
+				return false;
+			}
+		    });
+		});
+	}
+})(jQuery);