Skip to content
Snippets Groups Projects
Commit d8af3abe authored by Lars Seipel's avatar Lars Seipel
Browse files

initial import

parents
Branches
No related tags found
No related merge requests found
COPYING 0 → 100644
Copyright © 2018, Lars Seipel <lars.seipel@h-da.de>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
NOTE: Different conditions may apply to the CGI programs within the examples
directory.
FROM perl
ADD servecgi /
ADD examples/Echo.pl /
CMD ["/servecgi", "/Echo.pl"]
EXPOSE 80
Makefile 0 → 100644
# This Makefile is for building container images. For building the servecgi
# program itself use the standard go tool.
.PHONY: docker
docker: servecgi
docker build -t registry.code.fbi.h-da.de/its/servecgi/echo:latest .
.PHONY: servecgi
servecgi:
CGO_ENABLED=0 go build -tags netgo
.PHONY: clean
clean:
rm -f servecgi
# A simple HTTP server passing requests to a specified CGI program
So that Echo.pl can live on for generations of EWA students to come.
#!/usr/bin/perl -w
# Die 1. Zeile ist die Shebang-Zeile und enthält den Pfad zum Perl-Interpreter
## echo.pl
## Dieses Perl-Skript schickt Formulardaten an den Client zurück
## Bernhard Kreling, 26.4.2011
## Ralf Hahn, 17.04.2012 Anpassung auf HTML5 und Validator
# HTTP-Header für Antwort an Browser:
print "Content-type: text/html\n\n";
# HTML-Datei schreiben:
print '<!DOCTYPE html>', "\n";
print '<html lang="de">', "\n";
print "<head>\n";
print ' <meta charset="UTF-8" />', "\n";
print " <title>CGI-Formular-Echo</title>\n";
print "</head>\n";
print "<body>\n";
print " <h3>Formular-Echo</h3>\n";
print " <p>Sie haben folgende Formulardaten mit der Methode ";
# Formulardaten übernehmen abhängig von der Request-Methode:
my $ParameterString;
if ($ENV{'REQUEST_METHOD'} eq 'GET')
{
print "GET";
$ParameterString = $ENV{'QUERY_STRING'};
}
elsif($ENV{'REQUEST_METHOD'} eq 'POST')
{
print "POST";
read(STDIN, $ParameterString, $ENV{'CONTENT_LENGTH'});
# auf mmlab erscheint die Meldung "HTTP/1.1 100 Continue" - warum auch immer...
}
print " &uuml;bermittelt.</p>\n";
# Formulardaten als undekodierten String zurücksenden:
my $EscapedParameterString;
$EscapedParameterString = $ParameterString;
$EscapedParameterString =~ s/&/&amp;/g;
print " <p><strong>ParameterString:</strong><br> $EscapedParameterString </p>\n";
# Formulardaten in einzelne Parameter zerlegen mit '&' als Trenner:
my @ParameterListe = split(/&/, $ParameterString);
print " <p><strong>Einzelne Parameter:</strong><br>\n";
my $Parameter;
foreach $Parameter (@ParameterListe)
{
# Parameter in Name und Wert zerlegen mit '=' als Trenner:
my $Name;
my $Wert;
($Name, $Wert) = split(/=/, $Parameter);
# Leerstellen restaurieren ('+' ersetzen durch ' '):
$Wert =~ tr/+/ /;
# Hex-Codes %xx umwandeln in Character:
$Wert =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C" , hex($1))/eg;
# HTML-Sonderzeichen '&', '<', '>' kodieren:
$Wert =~ s/&/&amp;/;
$Wert =~ s/</&lt;/;
$Wert =~ s/>/&gt;/;
# Parameter ausgeben in HTML-Datei:
print "$Name = $Wert <br>\n";
}
# HTML-Datei abschliessen:
print " </p>\n";
print "</body>\n";
print "</html>\n";
main.go 0 → 100644
// Servecgi serves HTTP requests on the specified network address, invoking a
// CGI program for each request.
// Usage: servecgi [-l addr] cgi-prog
package main
import (
"flag"
"log"
"net/http"
"net/http/cgi"
"os"
)
var addr = flag.String("l", getEnvDefault("SERVECGI_LADDR", ":80"),
"local network `addr` to listen on")
func main() {
if flag.Parse(); flag.NArg() != 1 {
log.Fatalf("usage: %s [-l addr] path-to-cgi-executable", os.Args[0])
}
http.Handle("/", &cgi.Handler{Path: flag.Arg(0)})
log.Fatal(http.ListenAndServe(*addr, nil))
}
// GetEnvOrDefault retrieves the value associated with key from the environment
// block. If the value is the empty string, or not present at all, defValue is
// returned.
func getEnvDefault(key, defValue string) string {
if v := os.Getenv(key); v != "" {
return v
}
return defValue
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment