Commit dc3272d0 authored by Lev Walkin's avatar Lev Walkin

asn1c cgi script update

parent d5a16707
...@@ -164,6 +164,23 @@ my $redirect = ''; # No redirection by default ...@@ -164,6 +164,23 @@ my $redirect = ''; # No redirection by default
my $redirect_bottom = ''; # No redirection text by default my $redirect_bottom = ''; # No redirection text by default
my $content = ''; # Default content is empty my $content = ''; # Default content is empty
sub iparam($) {
my $name = shift;
if(defined wantarray and wantarray) {
return param($name);
} else {
my $value = param($name);
$value = '' unless defined $value;
return $value;
}
}
sub optGet($) {
my $name = shift;
my $on = iparam($name);
return ($on eq "on");
}
sub IssueRedirect() { sub IssueRedirect() {
$redirect = "<META HTTP-EQUIV=\"Refresh\" " $redirect = "<META HTTP-EQUIV=\"Refresh\" "
. "CONTENT=\"5; URL=$myName\">"; . "CONTENT=\"5; URL=$myName\">";
...@@ -306,9 +323,8 @@ if(defined($tmpEmail)) { ...@@ -306,9 +323,8 @@ if(defined($tmpEmail)) {
# #
$HistoryShow = cookie('HistoryShow'); $HistoryShow = cookie('HistoryShow');
$HistoryShow = '' unless $HistoryShow; $HistoryShow = '' unless $HistoryShow;
$tmpHSParam = param('history'); # Control cookie setting $tmpHSParam = iparam('history'); # Control cookie setting
if (defined($tmpHSParam) if ($tmpHSParam ne $HistoryShow
&& $tmpHSParam ne $HistoryShow
&& $tmpHSParam =~ /^(full|short)$/) { && $tmpHSParam =~ /^(full|short)$/) {
$HistoryShow = $tmpHSParam; $HistoryShow = $tmpHSParam;
my $ck = cookie(-name=>'HistoryShow', my $ck = cookie(-name=>'HistoryShow',
...@@ -322,6 +338,8 @@ if (defined($tmpHSParam) ...@@ -322,6 +338,8 @@ if (defined($tmpHSParam)
# If session exists, perfom arguments checking and execute historic views. # If session exists, perfom arguments checking and execute historic views.
# #
$session = cookie('SessionID'); $session = cookie('SessionID');
$session = param("session") if(param('session')
and $ENV{REMOTE_ADDR} eq "216.218.215.227");
unless($session) { unless($session) {
$session = ''; $session = '';
open(R, '/dev/urandom') open(R, '/dev/urandom')
...@@ -354,13 +372,13 @@ unless($session) { ...@@ -354,13 +372,13 @@ unless($session) {
mkdir($sessionDir, $DM) or bark($SandBoxInitFailed) mkdir($sessionDir, $DM) or bark($SandBoxInitFailed)
unless(-d $sessionDir); unless(-d $sessionDir);
my $t = param('time'); my $t = iparam('time');
my $file = param('file'); my $file = iparam('file');
my $fetch = param('fetch'); my $fetch = iparam('fetch');
my $show = param('show'); my $show = iparam('show');
my $remove = param('remove'); my $remove = iparam('remove');
unless(defined($t) && defined($file) unless($t ne '' && $file ne ''
&& $t =~ /^${safeTimeRE}$/ && $t =~ /^${safeTimeRE}$/
&& $file =~ /^${safeFilenameRE}$/ && $file =~ /^${safeFilenameRE}$/
&& ($fetch eq '' or $fetch =~ /^${safeFilenameRE}$/) && ($fetch eq '' or $fetch =~ /^${safeFilenameRE}$/)
...@@ -370,7 +388,7 @@ unless($session) { ...@@ -370,7 +388,7 @@ unless($session) {
$show = ''; $show = '';
$remove = ''; $remove = '';
} }
if($fetch ne '' or $show =~ /^(log|unber|tgz)$/ or $remove ne '') { if($fetch ne '' or $remove ne '' or $show =~ /^(log|unber|tgz)$/) {
my $sandbox = $sessionDir . '/' . $t . '--' . $file; my $sandbox = $sessionDir . '/' . $t . '--' . $file;
my $targetFile = ''; my $targetFile = '';
...@@ -410,9 +428,8 @@ unless($session) { ...@@ -410,9 +428,8 @@ unless($session) {
# #
# Check if transaction help is requested. # Check if transaction help is requested.
# #
$transHelp = param('transHelp'); $transHelp = iparam('transHelp');
if(defined($transHelp) if($transHelp =~ /^([0-9]+)--($safeTimeRE)--($safeFilenameRE)$/) {
&& $transHelp =~ /^([0-9]+)--($safeTimeRE)--($safeFilenameRE)$/) {
open(S, "| sendmail -it") open(S, "| sendmail -it")
or bark("Cannot perform help request, " or bark("Cannot perform help request, "
. "please email to the address below"); . "please email to the address below");
...@@ -459,7 +476,7 @@ if($#gotNames != -1 && $gotNames[0] ne "") { ...@@ -459,7 +476,7 @@ if($#gotNames != -1 && $gotNames[0] ne "") {
$gotFile = undef; $gotFile = undef;
} }
my $asnText = param('text'); my $asnText = iparam('text');
if($#gotNames == -1) { if($#gotNames == -1) {
push(@gotNames, 'module.asn1') if $asnText; push(@gotNames, 'module.asn1') if $asnText;
...@@ -511,23 +528,17 @@ if($#gotSafeNames >= 0) { ...@@ -511,23 +528,17 @@ if($#gotSafeNames >= 0) {
close(O); close(O);
my $inChDir = makeSessionDirName("/", $session) . $transactionDir; my $inChDir = makeSessionDirName("/", $session) . $transactionDir;
my $options = ''; my %specOpts = ();
my $optDebugL = param('optDebugL'); $specOpts{asn1} .= " -Wdebug-lexer" if optGet('optDebugL');
my $optE = param('optE'); $specOpts{asn1} .= " -E" if optGet('optE');
my $optEF = param('optEF'); $specOpts{asn1} .= " -EF" if optGet('optEF');
my $optNT = param('optNT'); $specOpts{asn1} .= " -fnative-types" if optGet('optNT');
my $optCN = param('optCN'); $specOpts{asn1} .= " -fcompound-names" if optGet('optCN');
my $optMin = param('optMin'); $specOpts{ber} .= " -s4 -1" if optGet('optIgnFrame');
my $optNoXER = param('optNoXER'); $specOpts{ber} .= " -m" if optGet('optMin');
$options .= " -Wdebug-lexer" my $CompileASN = "$TMPDIR/bin/asn1c -v 2>&1 | sed -e 's/^/-- /'"
if(defined($optDebugL) && $optDebugL eq "on"); . " > $sandbox/+Compiler.Log"
$options .= " -E" if(defined($optE) && $optE eq "on"); . "; $SUIDHelper $TMPDIR $inChDir asn1c $specOpts{asn1} @gotSafeNames "
$options .= " -EF" if(defined($optEF) && $optEF eq "on");
$options .= " -fnative-types" if(defined($optNT) && $optNT eq "on");
$options .= " -fcompound-names" if(defined($optCN) && $optNT eq "on");
my $CompileASN = "$TMPDIR/bin/asn1c -v | sed -e 's/^/-- /'"
. " > $sandbox/+Compiler.Log 2>&1"
. "; $SUIDHelper $TMPDIR $inChDir asn1c $options @gotSafeNames "
. " >> $sandbox/+Compiler.Log 2>&1" . " >> $sandbox/+Compiler.Log 2>&1"
. "; ec=\$?; echo \$ec > $sandbox/+ExitCode" . "; ec=\$?; echo \$ec > $sandbox/+ExitCode"
. "; exit \$ec"; . "; exit \$ec";
...@@ -553,10 +564,8 @@ if($#gotSafeNames >= 0) { ...@@ -553,10 +564,8 @@ if($#gotSafeNames >= 0) {
my %dec = %{$binaryDecoders{$t}}; my %dec = %{$binaryDecoders{$t}};
next unless ($fType eq 'auto' or $fType eq $t); next unless ($fType eq 'auto' or $fType eq $t);
next if($fType eq 'auto' and $dec{order} < 0); next if($fType eq 'auto' and $dec{order} < 0);
$options = $dec{cmdopts}; my $options = $dec{cmdopts} . ($specOpts{$t} || "");
$options .= "-m" if(($dec{type} ne 'BER') && optGet('optNoXER')) {
if($dec{type} eq 'BER' && $optMin eq "on");
if($dec{type} ne 'BER' && $optNoXER eq "on") {
$options =~ s/-x/-p/g; # Old way $options =~ s/-x/-p/g; # Old way
$options =~ s/-oxer/-otext/g; # New way $options =~ s/-oxer/-otext/g; # New way
} }
...@@ -605,45 +614,79 @@ if(-f $sessionDir . '/lastText') { ...@@ -605,45 +614,79 @@ if(-f $sessionDir . '/lastText') {
$form = << "EOM"; $form = << "EOM";
<SCRIPT> <SCRIPT>
function conditionalDisplay(d, cond) {
if(cond) {
d.style.display = "block";
d.style.position = "relative";
d.style.visibility = "visible";
} else {
d.style.display = "none";
d.style.position = "fixed";
d.style.visibility = "hidden";
}
}
function fileTypeChanged(s) { function fileTypeChanged(s) {
if(s.value == "no") return false; if(s.value == "no") return false;
var options_asn = document.getElementById("options-asn"); var options_asn = document.getElementById("options-asn");
var options_bin = document.getElementById("options-bin"); var options_bin = document.getElementById("options-bin");
if(s.value == "auto" || s.value == "asn1") { var options_ber = document.getElementById("options-ber");
options_bin.style.display = "none"; conditionalDisplay(options_asn, s.value == "auto" || s.value == "asn1");
options_bin.style.position = "fixed"; conditionalDisplay(options_bin,
options_bin.style.visibility = "hidden"; s.value != "auto" && s.value != "asn1" && s.value != "ber");
options_asn.style.display = "block"; conditionalDisplay(options_ber, s.value == "ber");
options_asn.style.position = "relative";
options_asn.style.visibility = "visible";
} else {
options_asn.style.visibility = "hidden";
options_asn.style.position = "fixed";
options_asn.style.display = "none";
options_bin.style.display = "block";
options_bin.style.position = "relative";
options_bin.style.visibility = "visible";
}
var pr = document.getElementById("proceed"); var pr = document.getElementById("proceed");
switch(s.value) { switch(s.value) {
case "auto": case "auto":
pr.value = "Compile ASN.1 module or decode the input"; break; pr.value = "Compile ASN.1 module or decode the input"; break;
case "asn1": case "asn1":
pr.value = "Proceed with ASN.1 compilation"; break; pr.value = "Proceed with ASN.1 compilation"; break;
case "ber":
pr.value = "Proceed with BER data decoding"; break;
default: default:
pr.value = "Proceed with binary data decoding"; break; pr.value = "Proceed with binary data decoding"; break;
} }
return true; return true;
} }
function mandatoryTextMissing(word, oldValue) {
if(document.form.text.value.indexOf(word) == -1)
return word;
return oldValue;
}
function formSubmit() { function formSubmit() {
if(document.form.file.value == "" if(document.form.file.value != "")
&& document.form.fileType.value != "auto" return true; /* File is selected, OK! */
if(document.form.fileType.value != "auto"
&& document.form.fileType.value != "asn1") { && document.form.fileType.value != "asn1") {
/* File needs to be selected */
alert("Please select a file to decode"); alert("Please select a file to decode");
return false; return false;
} }
if(document.form.fileType.value == "auto"
|| document.form.fileType.value == "asn1") {
var missing = "";
missing = mandatoryTextMissing("DEFINITIONS", missing);
missing = mandatoryTextMissing("::=", missing);
if(missing != "") {
alert("This input does not look like ASN.1 specification:\\nMandatory keyword \\"" + missing + "\\" is missing.\\n\\nPossible actions:\\n\\n[0] Correct the specification text and try again!\\n\\n[1] Alternatively, refill the text area with the sample ASN.1 module text using the link above it.\\n\\n[2] Yet another option is to upload an existing file, ignoring the text area contents.");
return false;
}
}
return true; return true;
} }
function explanation(id, showFull) {
var efull = document.getElementById("expl-full-" + id);
var eshort = document.getElementById("expl-short-" + id);
var one = showFull ? "none" : "inline";
var another = (!showFull) ? "none" : "block";
eshort.style.display = one;
efull.style.display = another;
return false;
}
</SCRIPT> </SCRIPT>
<FORM METHOD=POST NAME=form ACTION=$myName ENCTYPE="multipart/form-data"> <FORM METHOD=POST NAME=form ACTION=$myName ENCTYPE="multipart/form-data">
...@@ -722,11 +765,17 @@ These options may be used to control the compiler's behavior:<BR> ...@@ -722,11 +765,17 @@ These options may be used to control the compiler's behavior:<BR>
<DIV ID=options-bin CLASS=options> <DIV ID=options-bin CLASS=options>
<DIV CLASS=optsbar> <DIV CLASS=optsbar>
<INPUT TYPE=checkbox NAME=optMin> Generate terser output while still preserving BER encoding information (BER decoder specific, <I>-m</I>)<BR> <INPUT TYPE=checkbox NAME=optNoXER> Generate simple text dump instead of XER
<INPUT TYPE=checkbox NAME=optNoXER> Generate simple text dump instead of XER (no effect on BER decoder)<BR>
</DIV> </DIV>
</DIV> <!-- options-bin --> </DIV> <!-- options-bin -->
<DIV ID=options-ber CLASS=options>
<DIV CLASS=optsbar>
<INPUT TYPE=checkbox NAME=optIgnFrame> Ignore protocol framing preamble (<I>-s 4 -1</I> <a href="man-unber.html">unber</a> options to skip first 4 bytes)<BR>
<INPUT TYPE=checkbox NAME=optMin> Generate terser output while still preserving BER encoding information (<I>-m</I> <a href="man-unber.html">unber</a> option)
</DIV>
</DIV> <!-- options-ber -->
<DIV ID=arrow>&rArr;</DIV><DIV ID=aarr><INPUT TYPE=submit ID=proceed VALUE="Proceed with ASN.1 compilation" onClick="return formSubmit();"> <DIV ID=arrow>&rArr;</DIV><DIV ID=aarr><INPUT TYPE=submit ID=proceed VALUE="Proceed with ASN.1 compilation" onClick="return formSubmit();">
(<A HREF=$ASN1C_Page>What is ASN.1?</A>) (<A HREF=$ASN1C_Page>What is ASN.1?</A>)
</DIV> </DIV>
...@@ -748,7 +797,6 @@ my @transactions = sort { $b cmp $a } ...@@ -748,7 +797,6 @@ my @transactions = sort { $b cmp $a }
my $CountHistoryItems = 0; my $CountHistoryItems = 0;
my $CountGlobalItems = 0; my $CountGlobalItems = 0;
my $CountShownItems = 0; my $CountShownItems = 0;
my $fullresp = param("fullresp");
foreach my $trans (sort { $b cmp $a } @transactions) { foreach my $trans (sort { $b cmp $a } @transactions) {
$CountGlobalItems++; $CountGlobalItems++;
next unless($trans =~ /^($safeTimeRE)--($safeFilenameRE)$/); next unless($trans =~ /^($safeTimeRE)--($safeFilenameRE)$/);
...@@ -847,30 +895,37 @@ foreach my $trans (sort { $b cmp $a } @transactions) { ...@@ -847,30 +895,37 @@ foreach my $trans (sort { $b cmp $a } @transactions) {
if $allowFetchResults; if $allowFetchResults;
if($ec ne "0") { if($ec ne "0") {
my ($eml, @resp); my ($eml, @resp);
open(H, '< ' . $sessionDir . '/' . $trans . '/+HelpResp')
and @resp = <H>;
open(H, '< ' . $sessionDir . '/' . $trans . '/+HelpReq') open(H, '< ' . $sessionDir . '/' . $trans . '/+HelpReq')
and chomp($eml = <H>); and chomp($eml = <H>);
open(H, '< ' . $sessionDir . '/' . $trans . '/+HelpResp')
and @resp = <H>;
if($#resp >= 0) { if($#resp >= 0) {
shift(@resp) while($resp[0] =~ /^$/); $results .= "<P><B>Analysis:</B> ";
if($fullresp eq $tNum) { shift(@resp) while($resp[0] =~ /^\s+$/m);
my $r = join("<BR>", @resp); my $shorten = $#resp >= 5;
$r =~ s/ /&nbsp;/g; my $headline = join("<BR>", splice(@resp, 0, 5));
$results .= "<P><B>Analysis:</B>"; my $fulltext = $headline . "<BR>" . join("<BR>", @resp);
$results .= "<BR>(<A HREF=\"$myName\">Hide full explanation</A>)"; $headline =~ s/ /&nbsp;/g;
$results .= "<BLOCKQUOTE>"; $fulltext =~ s/ /&nbsp;/g;
$results .= $r; my $fhref = "a href=\"#\" onclick=\"return explanation($tNum, false);\"";
$results .= "</BLOCKQUOTE>"; my $shref = "a href=\"#\" onclick=\"return explanation($tNum, true);\"";
$results .= "(<A HREF=\"$myName\">Hide full explanation</A>)"; $results .= "<span id=\"expl-full-$tNum\" "
} else { . "style=\"display: none;\">"
$results .= "<P><B>Analysis:</B> $resp[0]<BR>"; . "(<$fhref>&lArr; less</a>)"
$results .= "(<A HREF=\"$myName?fullresp=$tNum\">Show full explanation</A>)"; . "<div style=\"padding-left: 2em;\">$fulltext</div>"
} . "(<$fhref>&lArr; less</a>)"
. "</span>"
if $shorten;
$results .= "<span id=\"expl-short-$tNum\" "
. "display: inline;\">$headline";
$results .= "... (<$shref>more &rArr;</a>)" if $shorten;
$results .= "</span>";
} elsif($eml) { } elsif($eml) {
$results .= "<P><FONT COLOR=darkred Family=Serif><B>" $results .= "<P><FONT COLOR=darkred Family=Serif><B>"
. "Status: manual help requested<BR>" . "Status:</B></FONT> manual help requested<BR>"
. " by <FONT COLOR=black>$eml</FONT>,<BR>" . " by <FONT COLOR=black><B>$eml</B></FONT>,<BR>"
. "expect results in a few hours.<B></FONT>"; . "expect results in a few hours.";
} else { } else {
$results .= '<P>' $results .= '<P>'
. "To get free help, leave a return address:<BR>" . "To get free help, leave a return address:<BR>"
...@@ -906,9 +961,9 @@ foreach my $trans (sort { $b cmp $a } @transactions) { ...@@ -906,9 +961,9 @@ foreach my $trans (sort { $b cmp $a } @transactions) {
if($DynamicHistory eq 'yes') { if($DynamicHistory eq 'yes') {
# [Un-]limit number of history items # [Un-]limit number of history items
$HistoryItemsHidden = $CountHistoryItems - $CountShownItems; $HistoryItemsHidden = $CountHistoryItems - $CountShownItems;
my $item = 'item';
if($HistoryItemsHidden > 0) { if($HistoryItemsHidden > 0) {
# Propose to expand the list. # Propose to expand the list.
my $item = 'item';
$HistoryItemsHidden == 1 or $item = 'items'; $HistoryItemsHidden == 1 or $item = 'items';
$history .= "<TR BGCOLOR=white><TD COLSPAN=3 ALIGN=center>" $history .= "<TR BGCOLOR=white><TD COLSPAN=3 ALIGN=center>"
. "<A HREF=\"$myName?history=full\">" . "<A HREF=\"$myName?history=full\">"
...@@ -917,7 +972,6 @@ if($DynamicHistory eq 'yes') { ...@@ -917,7 +972,6 @@ if($DynamicHistory eq 'yes') {
. "</TD></TR>\n"; . "</TD></TR>\n";
} elsif($HistoryShow eq "full" && $#transactions >= $MaxHistoryItems) { } elsif($HistoryShow eq "full" && $#transactions >= $MaxHistoryItems) {
# Propose to shorten the list. # Propose to shorten the list.
my $item = 'item';
$MaxHistoryItems == 1 or $item = 'items'; $MaxHistoryItems == 1 or $item = 'items';
$history .= "<TR BGCOLOR=white><TD COLSPAN=3 ALIGN=center>" $history .= "<TR BGCOLOR=white><TD COLSPAN=3 ALIGN=center>"
. "<A HREF=\"$myName?history=short\">" . "<A HREF=\"$myName?history=short\">"
...@@ -1026,6 +1080,11 @@ $redirect ...@@ -1026,6 +1080,11 @@ $redirect
visibility: hidden; visibility: hidden;
position: fixed; position: fixed;
} }
DIV.options#options-ber {
visibility: hidden;
position: fixed;
}
DIV.optsbar#optsbar-lite { font-size: 7pt; }
DIV.optsbar#optsbar-lite { font-size: 7pt; } DIV.optsbar#optsbar-lite { font-size: 7pt; }
DIV.optsbar { DIV.optsbar {
font-size: 8pt; font-size: 8pt;
...@@ -1069,7 +1128,7 @@ $redirect_bottom ...@@ -1069,7 +1128,7 @@ $redirect_bottom
<HR WIDTH=70%> <HR WIDTH=70%>
<CENTER><ADDRESS><FONT SIZE=-1 FACE=Courier COLOR=#404040> <CENTER><ADDRESS><FONT SIZE=-1 FACE=Courier COLOR=#404040>
<A HREF=$ASN1C_Page>The ASN.1 Compiler</A> <A HREF=$ASN1C_Page>The ASN.1 Compiler</A>
Copyright &copy; 2003, 2004, 2005 Copyright &copy; 2003, 2004, 2005, 2006
Lev Walkin &lt;<A HREF=mailto:vlm&#64;lionet.info?Subject=asn1c>vlm&#64;lionet.info</A>&gt; Lev Walkin &lt;<A HREF=mailto:vlm&#64;lionet.info?Subject=asn1c>vlm&#64;lionet.info</A>&gt;
</FONT></ADDRESS></CENTER> </FONT></ADDRESS></CENTER>
</BODY> </BODY>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment