improve 2004/hibachi

Instead of hiding the source code in an opaque compressed
tarball, we copy a src tree into a build tree.

Improved Makefile, .gitignore and README.md as well.
This commit is contained in:
Landon Curt Noll committed 2023-03-21 20:56:17 -07:00
1 parent f31bfe0bc8
commit 82376d4fc4
43 files changed
+18287 -400

No files matched your search

+1 -1
View File
@@ -1 +1 @@
hibachi
build
+270 -300
View File
@@ -1,362 +1,332 @@
#!/bin/make
#!/usr/bin/env make
#
# 2004 makefile
# IOCCC 2004 winning entry - hibachi
################################################################################
#
# Copyright (C) 2004, Landon Curt Noll, Simon Cooper, Peter Seebach
# and Leonid A. Broukhis. All Rights Reserved. Permission for personal,
# educational or non-profit use is granted provided this copyright and
# notice are included in its entirety and remains unaltered. All other
# uses must receive prior permission from the contest judges.
# Regarding individual entries:
#
# IOCCC winning entry code may not work on your system. Even with standards,
# conditions and build environments change, especially when it comes to more
# extreme code such you might find in an IOCCC winner. Moreover, what was
# allowed and liked in one IOCCC contest may no longer be liked/allowed in
# later IOCCC years.
#
# Corrections on winning author and fixing typos in remarks are VERY WELCOME.
#
# GitHub pull requests are welcome:
#
# If you have a patch that might make running an entry work in modern Unix-like
# environments, please create a GitHub pull request for the IOCCC judges to
# consider.
#
# Suggestions and corrections regarding Makefiles, winning author information,
# fixing typos in remarks, and code patches are welcome via opening a GitHub
# issue or better yet, by creating a GitHub pull request for the IOCCC judges
# to consider. To form a GitHub issue or GitHub pull, please visit:
#
# https://github.com/ioccc-src/winner
#
################################################################################
# This work by Landon Curt Noll and Leonid A. Broukhis is licensed under:
#
# Creative Commons Attribution-ShareAlike 3.0 Unported License.
#
# See: http://creativecommons.org/licenses/by-sa/3.0/
# tool locations
#############################
# shell used by this Makefile
#############################
#
SHELL= /bin/sh
CP= cp
CPP= cpp
GUNZIP= gunzip
LD= ld
MAKE= make
RM= rm
SED= sed
TAR= tar
TRUE= true
SHELL= bash
# Special flags for the gavin entry
#######################
# common tool locations
#######################
#
# FYI: Older versions of GCC have a bug in -O2 optimization, hence -O1
#
GAVIN_OPT= -O1
GAVIN_FLAGS=\
'-DY(m)=*((int*)(m))'\
'-DE(f,a,b,c)=((G((*)))(f))(a,b,c)'\
'-DM=for(D=0;D<786432;D++)'\
'-DZ=int i=0,j=0,h,n,p=393728,s=26739,C,D'\
'-DV=0x90200'\
'-DK=0'\
'-DR=while((C=E(V-8,100,0,0))&3&&(D=E(V-8,96,0,0))|3){'\
'-DL(c,d)=E(V+8,100,c,0);R}E(V+8,96,d,0);R}'
include ../../var.mk
# Set X11_LIBDIR to the directory where the X11 library resides
#
X11_LIBDIR= /usr/X11R6/lib
#X11_LIBDIR= /usr/X11R6/lib
#X11_LIBDIR= /usr/X11/lib
X11_LIBDIR= /opt/X11/lib
#CINCLUDE= -I ${HOMEBREW_PREFIX}/include/SDL2
# Set X11_INCLUDEDIR to the directory where the X11 include files reside
#
#X11_INCDIR= /usr/X11R6/include
#X11_INCDIR= /usr/X11/include
X11_INCDIR= /opt/X11/include
# optimization
# Common C compiler warnings to silence
#
#CSILENCE=
CSILENCE= -Wno-pointer-sign -Wno-unused-parameter
# Common C compiler warning flags
#
#CWARN= ${CSILENCE}
#CWARN= -Wall ${CSILENCE}
#CWARN= -Wall -Wextra ${CSILENCE}
CWARN= -Wall -Wextra -pedantic ${CSILENCE}
# Compiler standard
#
#CSTD=
#CSTD= -ansi
CSTD= -std=gnu99
# Compiler bit architecture
#
# Some entries require 32-bitness:
# ARCH= -m32
#
# Some entries require 64-bitness:
# ARCH= -m64
#
# By default we assume nothing:
#
ARCH=
# Defines that are needed to compile
#
CDEFINE=
#CDEFINE= -DIOCCC
# Include files that are needed to compile
#
CINCLUDE=
#CINCLUDE= -include stdlib.h
#CINCLUDE= -include stdio.h
#CINCLUDE= -include stdlib.h -include stdio.h
#CINCLUDE= -I ${X11_INCDIR} -I ${X11_INCDIR}/X11
#CINCLUDE= `${SDL2_CONFIG} --cflags`
# Optimization
#
# Most compiles will safely use -O2. Some can use only -O1 or -O.
# A few compilers have broken optimizers and thus you may
# not want anything.
# A few compilers have broken optimizers or this entry make break
# under those buggy optimizers and thus you may not want anything.
# Reasonable compilers will allow for -O3.
#
#OPT=
#OPT= -O
#OPT= -O1
OPT= -O2
#OPT= -O2
OPT= -O3
# Default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}
# flags for ANSI compiles
# Libraries needed to build
#
# NOTE: Some ANSI compilers make use of -Xa to turn on ANSI mode,
# others such as gcc may want -ansi, others (Compaq Tru64 Unix)
# want -std1, and others may want nothing at all.
# Adjust the CFLAGS line as needed.
#
# NOTE: Some compilers cannot optimize, or optimize some entries
# incorrectly. You might want to turn on -O to see if your
# compiler can handle them.
#
#
#CFLAGS= -Xa ${OPT}
#CFLAGS= -std1 $(OPT)
CFLAGS= -ansi ${OPT}
LIBS=
#LIBS= -lm
#LIBS= -L ${X11_LIBDIR} -lX11
#LIBS= `${SDL2_CONFIG} --libs`
# ANSI compiler
#
# Set CC to the name of your ANSI compiler.
#
# Some entries seem to need gcc. If you have gcc, set
# both CC and MAY_NEED_GCC to gcc.
#
# If you do not have gcc, set CC to the name of your ANSI compiler, and
# set MAY_NEED_GCC to either ${CC} (and hope for the best) or to just :
# to disable such programs.
# C compiler to use
#
CC= cc
MAY_NEED_GCC= gcc
#CC=clang
#CC=gcc
# 2004 winners
# Compiler add-ons or replacements for clang only
#
WINNERS= anonymous arachnid burley gavare gavin hibachi hoyle jdalbec \
kopczynski newbern omoikane schnitzi sds vik1 vik2
CLEAN= anonymous_clean arachnid_clean burley_clean gavare_clean gavin_clean \
hibachi_clean hoyle_clean jdalbec_clean kopczynski_clean \
newbern_clean omoikane_clean schnitzi_clean sds_clean vik1_clean \
vik2_clean
CLOBBER= anonymous_clobber arachnid_clobber burley_clobber gavare_clobber \
gavin_clobber hibachi_clobber hoyle_clobber jdalbec_clobber \
kopczynski_clobber newbern_clobber omoikane_clobber schnitzi_clobber \
sds_clobber vik1_clobber vik2_clobber
ALT_NAMES= hoyle.orig kopczynski.orig
DATA_FILES= arachnid_files gavin_files hibachi_files kopczynski_files \
newbern_files omoikane_files schnitzi_files
# default build
ifeq ($(CC),clang)
#
all: ${WINNERS}
# Best use of "Precious" Lines
#CSILENCE+=
#
anonymous: anonymous.c
${CC} anonymous.c -o anonymous
anonymous_clean:
${RM} -f anonymous.o
anonymous_clobber: anonymous_clean
${RM} -f anonymous
# Best use of Vision
CWARN+= -Weverything
#
arachnid: arachnid.c
${CC} -o arachnid -DL=LINES -DS=COLS \
-DW=mvwaddch\(w,v,u,acs_map\[l\[m\[u arachnid.c -lncurses
endif
arachnid_clean:
${RM} -f arachnid.o
arachnid_clobber: arachnid_clean
${RM} -f arachnid
arachnid_files: arachnid.info
# Best Calculated Risk
# Specific add-ons or replacements for gcc only
#
burley: burley.c
${CC} -ansi burley.c -o burley
burley_clean:
${RM} -f burley.o
burley_clobber: burley_clean
${RM} -f burley
# Best Use of Light and Spheres
ifeq ($(CC),gcc)
#
gavare: gavare.c
${CC} -O3 gavare.c -o gavare
gavare_clean:
${RM} -f gavare.o
gavare_clobber: gavare_clean
${RM} -f gavare
# Best of Show
#CSILENCE+=
#
gavin: gavin.c
${CC} ${GAVIN_OPT} -o gavin ${GAVIN_FLAGS} gavin.c
${RM} -f kernel
./gavin > kernel
${CC} ${GAVIN_OPT} -c ${GAVIN_FLAGS} -DB=_start '-Dputchar(a)=' gavin.c
${RM} -f sh
${LD} -s -o sh gavin.o
${RM} -f vi
${CP} sh vi
${RM} -f fs.tar
${TAR} -cvf fs.tar sh vi gavin.c gavin.hint prim
gavin_clean:
${RM} -f sh vi kernel gavin.o
gavin_clobber: gavin_clean
${RM} -f gavin fs.tar
gavin_files: boot.b lilo.conf prim gavin_install.txt
# Best Abuse of the Guidelines
#CWARN+=
#
hibachi: hibachi.tar.gz
${RM} -f hibachi.tar
${GUNZIP} < hibachi.tar.gz > hibachi.tar
${TAR} -xvf hibachi.tar
${RM} -f hibachi.tar
(cd hibachi && ${SHELL} ./configure)
([ -f hibachi/makefile ] && cd hibachi && $(MAKE) -f makefile || true)
hibachi_clean:
${RM} -f hibachi/hibachi.o hibachi.tar
hibachi_clobber: hibachi_clean
${RM} -rf hibachi
hibachi_files: hibachi.tar.gz
endif
# Most Functional Output
##############################
# Special flags for this entry
##############################
#
hoyle: hoyle.c
${CC} hoyle.c -o hoyle -lm
hoyle.orig: hoyle.orig.c
${CC} hoyle.orig.c -o hoyle.orig -lm
hoyle_clean:
${RM} -f hoyle.o hoyle.orig.o
hoyle_clobber: hoyle_clean
${RM} -f hoyle hoyle.orig
# Best Abuse of the Periodic Table
ENTRY= hibachi
PROG= ${ENTRY}
#
jdalbec: jdalbec.c
@${RM} -f jdalbec2.c
-${CC} -E jdalbec.c > jdalbec2.c
@${RM} -f jdalbec3.c
${SED} -e 's/ (/(/g' < jdalbec2.c > jdalbec3.c
${CC} -ansi jdalbec3.c -o jdalbec
jdalbec_clean:
${RM} -f jdalbec2.c jdalbec3.c jdalbec.o
jdalbec_clobber: jdalbec_clean
${RM} -f jdalbec
# Best one-liner
OBJ= ${PROG}.o
DATA=
TARGET= build/${PROG}
#
kopczynski: kopczynski.c
${CC} -Dif=while kopczynski.c -o kopczynski
kopczynski.orig: kopczynski.orig.c
${CC} -Dif=while kopczynski.orig.c -o kopczynski.orig
kopczynski_clean:
${RM} -f kopczynski.o kopczynski.orig.o
kopczynski_clobber: kopczynski_clean
${RM} -f kopczynski kopczynski.orig
kopczynski_files: kopczynski-10 kopczynski-11 kopczynski-8a kopczynski-8b \
kopczynski-8c kopczynski-9
ALT_OBJ=
ALT_TARGET=
# Best Font Engine
#################
# build the entry
#################
#
newbern: newbern.c
${CC} newbern.c -o newbern
all: data ${TARGET}
@${TRUE}
newbern_clean:
${RM} -f newbern.o
.PHONY: all alt data everything clean clobber install \
love haste waste maker easter_egg sandwich \
supernova deep_magic magic charon pluto
newbern_clobber: newbern_clean
${RM} -f newbern
build/${PROG}: src
${RM} -rf build
${CP} -v -r src build
cd build; CFLAGS="${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${OPT}" \
LDFLAGS="${LIBS}" \
CC="${CC}" \
${SHELL} ./configure
cd build; ${MAKE}
newbern_files: newbern.dat
# Best Utility
# alternative executable
#
omoikane: omoikane.c
${CC} -O omoikane.c -o omoikane
alt: data ${ALT_TARGET}
@${TRUE}
omoikane_clean:
${RM} -f omoikane.o
omoikane_clobber: omoikane_clean
${RM} -f omoikane
omoikane_files: omoikane.info
# Best Non-Use of Curses
# data files
#
schnitzi: schnitzi.c
${CC} schnitzi.c -o schnitzi
data: ${DATA}
@${TRUE}
schnitzi_clean:
${RM} -f schnitzi.o
schnitzi_clobber: schnitzi_clean
${RM} -f schnitzi
schnitzi_files: schnitzi.inp0 schnitzi.inp1
# Best Abuse of Indentation
# both all and alt
#
sds: sds.c
${CC} -o sds sds.c
sds_clean:
${RM} -f sds_encoder.c sds_encoder.o sds.o
sds_clobber: sds_clean
${RM} -f sds sds_encoder
# Best X11 Game
#
vik1: vik1.c
${CC} -ansi -O2 -o vik1 vik1.c -L${X11_LIBDIR} -lX11
vik1_clean:
${RM} -f vik1.o
vik1_clobber: vik1_clean
${RM} -f vik1
# Best Abuse of CPP
#
vik2: vik2.c
@${RM} -f vik2_1.c
${CC} -E '-DSTOP=_5' '-DFNAME="vik2_1.c"' vik2.c > vik2_1.c
@${RM} -f vik2_2.c
${CC} -E vik2_1.c > vik2_2.c
${CC} -O vik2_2.c -o vik2
vik2_clean:
${RM} -f vik2_1.c vik2_2.c vik2.o
vik2_clobber: vik2_clean
${RM} -f vik2
everything: all alt
###############
# utility rules
###############
#
everything: ${WINNERS} ${ALT_NAMES} ${DATA_FILES}
clean:
${RM} -f ${OBJ} ${ALT_OBJ}
@-if [ -f indent.c ]; then \
echo ${RM} -f indent.c; \
${RM} -f indent.c; \
fi
clobber: clean
${RM} -f ${TARGET} ${ALT_TARGET}
${RM} -rf build
@-if [ -e sandwich ]; then \
${RM} -f sandwich; \
echo 'ate sandwich'; \
fi
install:
@echo "Dr. Spock says that is not logical!"
@${TRUE}
# you may be able to misunderstand the source by reading indent.c
#
indent.c: ${PROG}.c
@if which "${GINDENT}" >/dev/null 2>&1; then \
echo ${RM} -f $@; \
${RM} -f $@; \
echo "${GINDENT} < $< > $@"; \
${GINDENT} < $< > $@; \
elif which "${INDENT}" >/dev/null 2>&1; then \
echo ${RM} -f $@; \
${RM} -f $@; \
echo "${INDENT} < $< > $@"; \
${INDENT} < $< > $@; \
else \
echo "no intent tool found, ident $< yourself, sorry"; \
echo "exit 1"; \
exit 1; \
fi
##################
# 133t hacker rulz
##################
#
love:
@echo 'not war?'
@${TRUE}
haste:
$(MAKE) waste
waste:
@echo 'waste'
clean: ${CLEAN}
${RM} -f a.out core
clobber: ${CLOBBER}
${RM} -f ${WINNERS}
${RM} -f ${ALT_NAMES}
nuke: clobber
@${TRUE}
install: all
${CAT} ${WINNERS} ${ALT_NAMES} > /dev/null
waste:
@echo 'haste'
@${TRUE}
maker:
@echo 'Participate in a maker faire'
@${TRUE}
easter_egg:
@echo "you expected to often misunderstand this $${RANDOM} magic"
@echo "chongo '<was here>' /\\oo/\\"
@echo "Eggy"
sandwich: easter_egg
@if [ `id -u` -eq 0 ]; then \
echo 'Okay.'; \
echo "$${RANDOM}`date +%s`$${RANDOM}" > $@; \
else \
echo 'What? Make it yourself.'; \
exit 1; \
fi
# Understand the history of the Homebrew Computer Club
# as well as the West Coast Computer Faire and
# you might be confused different. :-)
#
supernova: sandwich
@-if [ -r .code_anal ]; then \
${RM} -f .code_anal_v6; \
else \
echo "planet deniers, like some members of the IAU, are so cute when they try to defend their logic"; \
fi
@echo "A $@ helps ${MAKE} the elements that help form planets"
@${TRUE}
deep_magic: supernova
@-if [ -r .code_anal ]; then \
ccode_analysis --deep_magic 7889066cdbdf09b0408021754586e895be641cc9be29e7eafd3ca65359541f17 \
--FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
else \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
sleep 2; \
echo "Wrong! Do it again!"; \
fi
@${TRUE}
magic: deep_magic
@-if [ -r .code_anal ]; then \
ccode_analysis --level 20003 --mode 5717175 --FNV1a_hash_512_bit -v2 "${PROG}" "${PROG}.c"; \
else \
echo "If you don't eat yer meat, you can't have any pudding!"; \
echo "How can you have any pudding if you don't eat yer meat?!"; \
fi
@${TRUE}
# The IOCCC resident astronomer states
#
charon: magic
@echo "$@ is a dwarf planet"
@echo "dwarf is a type of planet"
@echo "therefore IAU, $@ is a planet"
pluto: charon
${MAKE} charon
@echo "$@ is a dwarf planet"
@echo "dwarf is a type of planet"
@echo "therefore, $@ is a planet"
@echo "having lots of planets is good feature because supernovae can help ${MAKE} a lot of them"
+109 -99
View File
@@ -1,4 +1,4 @@
Best Abuse of the Guidelines:
# Best Abuse of the Guidelines:
Anthony Howe
Snert
@@ -8,162 +8,172 @@ Best Abuse of the Guidelines:
http://www.snert.com/
# To build:
Judges' Comments:
```sh
make
```
To build (simple: Cygwin, FreeBSD, Linux, Mac OS X):
### To run:
tar -zxf hibachi.tgz
cd hibachi
./configure
make
```sh
./hibachi-start.sh
```
Try:
### Try:
cd hibachi
./hibachi-start.sh
```sh
./hibachi-start.sh
```
Then use your web browser to visit http://localhost:8008/
Then use your web browser to visit http://localhost:8008/
This entry violates the guidelines in so many ways! We are not
exactly sure how many org's will be upset with this entry, but we
are considering starting an IOCCC standards body just to reign in
the likes Mr Howe.
## Judges' comments:
This entry also has the dubious honour of being the only one to have
been submitted with its own ./configure script.
This entry violates the guidelines in so many ways! We are not
exactly sure how many org's will be upset with this entry, but we
are considering starting an IOCCC standards body just to reign in
the likes Mr Howe.
This entry also has the dubious honour of being the only one to have
been submitted with its own ./configure script.
Selected Author's Comments:
## Author's comments:
README.TXT Feb 2004
==========
### README.TXT (Feb 2004)
Hibachi is a simple, small, and (probably) very secure web server.
Hibachi is a simple, small, and (probably) very secure web server.
There is a `hibachi.tgz' file that unpacks several support
files and a sub-directory tree containing the documentation and
examples. It can be viewed by:
There is a `hibachi.tgz' file that unpacks several support
files and a sub-directory tree containing the documentation and
examples. It can be viewed by:
tar -zxf hibachi.tgz
lynx hibachi/localhost/index.html
tar -zxf hibachi.tgz
lynx hibachi/localhost/index.html
Or once Hibachi is running, use a web browser, preferably one that
supports images and JavaScript, to view the documentation and try
some of the CGI examples:
Or once Hibachi is running, use a web browser, preferably one that
supports images and JavaScript, to view the documentation and try
some of the CGI examples:
http://localhost:8008/
http://localhost:8008/
### Building
Building
--------
To build just the executable:
To build just the executable:
For Cygwin, FreeBSD, Linux (newer), Mac OS X:
# Cygwin, FreeBSD, Linux (newer), Mac OS X
gcc -o hibachi hibachi.c
```sh
gcc -o hibachi hibachi.c
```
# Linux (older)
gcc -DSHUT_WR=1 -o hibachi hibachi.c
For Linux (older):
# SunOS
gcc -o hibachi hibachi.c -lnsl -lsocket
```sh
gcc -DSHUT_WR=1 -o hibachi hibachi.c
``
Since some systems place socket and network functions into other
libraries, a GNU autoconf ./configure script has been provided to
figure out the necessary link libraries, to verify all the
necessary headers and functions are present, and setup the #!
paths for the CGI examples. In which case the preferred build
commands are:
For SunOS:
./configure [--enable-port=number]
make
```sh
gcc -o hibachi hibachi.c -lnsl -lsocket
```
To start the server on the default port (8008):
Since some systems place socket and network functions into other
libraries, a GNU autoconf ./configure script has been provided to
figure out the necessary link libraries, to verify all the
necessary headers and functions are present, and setup the #!
paths for the CGI examples. In which case the preferred build
commands are:
./hibachi-start.sh &
```
./configure [--enable-port=number]
make
```
To test the server:
To start the server on the default port (8008):
lynx http://localhost:8008/
```sh
./hibachi-start.sh &
```
To stop the server:
To test the server:
kill %1
```sh
lynx http://localhost:8008/
```
To stop the server:
Features
--------
```sh
kill %1
```
o Supports virtual hosts.
### Features
o Supports all MIME types.
* Supports virtual hosts.
o Supports Common Gateway Interface (CGI) scripts and programs.
* Supports all MIME types.
o Supports multiple index.* file types:
* Supports Common Gateway Interface (CGI) scripts and programs.
index.htm, index.html, index.php, index.pl,
index.sh, index.rb, index.py
* Supports multiple index.* file types:
o Supports subset of RFC 2616 HTTP/1.1 methods:
index.htm, index.html, index.php, index.pl,
index.sh, index.rb, index.py
GET, HEAD, and POST
* Supports subset of RFC 2616 HTTP/1.1 methods:
o Simple & straight forward configuration using environment variables.
GET, HEAD, and POST
o Portability across Unix-like environments, such as:
* Simple & straight forward configuration using environment variables.
Cygwin, FreeBSD, Linux, SunOS.
* Portability across Unix-like environments, such as:
o Known to work with Lynx, Mozilla, Opera, and Internet Explorer
web browsers.
Cygwin, FreeBSD, Linux, SunOS.
o Is a dedicated process-forking server that does not use inetd.
* Known to work with Lynx, Mozilla, Opera, and Internet Explorer
web browsers.
o Is secure against relative path file snooping.
* Is a dedicated process-forking server that does not use inetd.
o Is secure against directory searches.
* Is secure against relative path file snooping.
o CGI script execution managed through Unix file permissions.
* Is secure against directory searches.
o ~155 lines of source,
1940 bytes long by IOCCC 2004 rules,
~6KB compiled & stripped for FreeBSD.
* CGI script execution managed through Unix file permissions.
o Superior & smaller than micro_httpd from http://www.acme.com/
* ~155 lines of source,
1940 bytes long by IOCCC 2004 rules,
~6KB compiled & stripped for FreeBSD.
o And has a really cool tongue-in-cheek animated logo too.
* Superior & smaller than micro_httpd from http://www.acme.com/
* And has a really cool tongue-in-cheek animated logo too.
Comments
--------
### Comments
o This code is properly indented using the One True Brace style.
* This code is properly indented using the One True Brace style.
o HTTP/1.0 200 OK == HTTP/1.1 200 OK CRLF Connection: close ?
* HTTP/1.0 200 OK == HTTP/1.1 200 OK CRLF Connection: close ?
o getenv() == putenv() ?
* getenv() == putenv() ?
o Hibachi can serve www.ioccc.org.
* Hibachi can serve www.ioccc.org.
o Commented spoiler available.
* Commented spoiler available.
### Known Issues
Known Issues
------------
* The "links" text browser does not support RFC 2616 section 7.2.1
paragraph 3 sentence 2, and so fails to display responses from
hibachi.
o The "links" text browser does not support RFC 2616 section 7.2.1
paragraph 3 sentence 2, and so fails to display responses from
hibachi.
### Suggested IOCCC Categories
Suggested IOCCC Categories
--------------------------
Best Utility
Best Support
Most Portable Package
Most Likely to Cook Apache
Best Interpretation of RFC 2616
Winner of The Far Too Much Free Time Award
Best Utility
Best Support
Most Portable Package
Most Likely to Cook Apache
Best Interpretation of RFC 2616
Winner of The Far Too Much Free Time Award
Binary file not shown.
Vendored Executable
+4874
View File
File diff suppressed because it is too large. Load diff
+210
View File
@@ -0,0 +1,210 @@
#######################################################################
# Thus it begins...
#######################################################################
AC_INIT(hibachi, 1.0, [Anthony Howe <achowe@snert.com>])
dnl The autoconf version I learned to deal with.
AC_PREREQ(2.57)
dnl Yes I wrote this mess.
AC_COPYRIGHT([Public Domain 2004 by Anthony Howe.])
AC_SUBST(package_copyright, ['Public Domain 2004 by Anthony Howe.'])
AC_SUBST(package_major, [[`echo $PACKAGE_VERSION | sed -e 's/^\([0-9]*\)\.\([0-9]*\)/\1/'`]])
AC_SUBST(package_minor, [[`echo $PACKAGE_VERSION | sed -e 's/^\([0-9]*\)\.\([0-9]*\)/\2/'`]])
AC_SUBST(package_author, $PACKAGE_BUGREPORT)
AC_DEFINE_UNQUOTED(_NAME, ["$PACKAGE_NAME"])
AC_DEFINE_UNQUOTED(_MAJOR, $package_major)
AC_DEFINE_UNQUOTED(_MINOR, $package_minor)
AC_DEFINE_UNQUOTED(_AUTHOR, ["$package_author"])
AC_DEFINE_UNQUOTED(_VERSION, ["$PACKAGE_NAME/$PACKAGE_VERSION"])
AC_DEFINE_UNQUOTED(_COPYRIGHT, ["$package_copyright"])
OS=`uname -s`
#######################################################################
# Setup paths
#######################################################################
# The total perspective vortex "You are here..."
AC_CONFIG_SRCDIR($PACKAGE_NAME.c)
dnl AC_SUBST(srcdir)
dnl AC_SUBST(top_srcdir)
dnl AC_SUBST(abs_srcdir)
dnl AC_SUBST(abs_top_srcdir)
dnl
dnl AC_SUBST(builddir)
dnl AC_SUBST(top_builddir)
dnl AC_SUBST(abs_builddir)
dnl AC_SUBST(abs_top_builddir)
# If localstatedir still has its original value, then use our prefered default.
if test "$localstatedir" = '${prefix}/var'; then
if test "$OS" = 'Linux'; then
localstatedir='/var/lib'
elif test "$OS" = 'FreeBSD'; then
localstatedir='/var/state'
elif test "$OS" = 'SunOS'; then
localstatedir='/var/opt'
else
localstatedir='/var'
fi
fi
AC_PATH_TOOL(perl_exe, perl, [/usr/local/bin/perl])
AC_SUBST(perl_exe)
AC_PATH_TOOL(ruby_exe, ruby, [/usr/local/bin/ruby])
AC_SUBST(ruby_exe)
if test -z "$php_exe"; then
AC_PATH_TOOL(php_exe, php.cgi)
fi
if test -z "$php_exe"; then
AC_PATH_TOOL(php_exe, php-cgi)
fi
if test -z "$php_exe"; then
# Note this might be either the CLI or CGI version.
AC_PATH_TOOL(php_exe, php, [/usr/local/bin/php])
if test -e $php_exe; then
AC_MSG_CHECKING([if $php_exe is the CGI binary])
if $php_exe -v | grep -q '(cli)'; then
AC_MSG_RESULT(no)
dnl unset ac_cv_path_ac_pt_php_exe
dnl unset ac_cv_path_php_exe
dnl unset php_exe
else
AC_MSG_RESULT(yes)
fi
fi
fi
AC_SUBST(php_exe)
#######################################################################
# Auxliary files to be modified later
#######################################################################
AC_CONFIG_FILES(makefile)
AC_CONFIG_FILES(hibachi-start.sh, [find . -name '*.sh' -exec chmod 755 \{\} \;])
if test ! -d localhost; then
if test -e supplement.tar; then
tar -xf supplement.tar
elif test -e supplement.tar.gz; then
tar -zxf supplement.tar.gz
fi
fi
if test -d localhost; then
AC_CONFIG_FILES(localhost/test/perl/yahoo-ticker.pl, [chmod 755 localhost/test/perl/yahoo-ticker.pl])
AC_CONFIG_FILES(localhost/test/php/index_php, [mv localhost/test/php/index_php localhost/test/php/index.php; chmod 755 localhost/test/php/index.php])
AC_CONFIG_FILES(localhost/test/php/sendform.php, [chmod 755 localhost/test/php/sendform.php])
AC_CONFIG_FILES(localhost/test/php/info.php, [chmod 755 localhost/test/php/info.php])
AC_CONFIG_FILES(localhost/test/ruby/index_rb, [mv localhost/test/ruby/index_rb localhost/test/ruby/index.rb; chmod 755 localhost/test/ruby/index.rb])
fi
#######################################################################
# Configuration options
#######################################################################
AC_ARG_ENABLE(port,
[AC_HELP_STRING([--enable-port=number],[specifiy the server port number, default is 8008])],
[], [enable_port=8008]
)
AC_SUBST(enable_port)
#######################################################################
# Setup compiler predefines and exceptions.
#######################################################################
# Tradional cc options. These are different for Borland C.
AC_SUBST(CC_E, '-o')
AC_SUBST(CC_E_NAME, '-o $@')
AC_SUBST(CC_O, '-o')
AC_SUBST(CC_O_NAME, '-o $*$O')
AC_PROG_CC
AC_PROG_LN_S
dnl AC_PROG_MAKE_SET
dnl AC_CHECK_TOOL(RANLIB, ranlib, true)
#######################################################################
# Check for libraries.
#######################################################################
AC_SEARCH_LIBS(socket, [socket nsl],[AC_DEFINE_UNQUOTED([AS_TR_CPP([HAVE_SOCKET])])])
AC_SEARCH_LIBS(inet_ntoa, [socket nsl resolv],[AC_DEFINE_UNQUOTED([AS_TR_CPP([HAVE_INET_NTOA])])])
#######################################################################
# Check for headers.
#######################################################################
# Need these ANSI C headers.
AC_CHECK_HEADERS(
[stdio.h stdlib.h string.h],
[], [AC_MSG_FAILURE([Missing required ANSI C header.], 1)]
)
# Need these I/O headers.
AC_CHECK_HEADERS(
[arpa/inet.h dirent.h fcntl.h netinet/in.h sys/socket.h sys/stat.h sys/wait.h unistd.h],
[], [AC_MSG_FAILURE([Missing required I/O header.], 1)]
)
dnl ###################################################################
dnl This should be in aclocal.m4 instead, but I couldn't be
dnl bothered with an aclocal.m4 file for just one macro.
dnl ###################################################################
dnl
dnl APR_CHECK_DEFINE(symbol, header_file)
dnl
AC_DEFUN(APR_CHECK_DEFINE,[
AC_CACHE_CHECK([for $1],ac_cv_define_$1,[
AC_RUN_IFELSE([AC_LANG_PROGRAM([
AC_INCLUDES_DEFAULT()
#include <$2>
], [[
#ifdef $1
exit(0);
#else
exit(1);
#endif
]])], [ac_cv_define_$1=yes],[ac_cv_define_$1=no])
])
])
APR_CHECK_DEFINE(SHUT_WR, sys/socket.h)
if test $ac_cv_define_SHUT_WR = 'no'; then
CFLAGS="$CFLAGS -DSHUT_WR=1"
fi
#######################################################################
# Check for functions.
#######################################################################
AC_CHECK_FUNCS(
[ accept bind close closedir dup2 fork getenv inet_ntoa listen open opendir putenv read readdir recv send shutdown snprintf socket sscanf stat strcspn strncat strncmp strstr strtol system tolower waitpid],
[], [AC_MSG_FAILURE([Missing required function.], 1)]
)
#######################################################################
# Generate output.
#######################################################################
AC_OUTPUT()
echo
echo $PACKAGE_NAME/$package_major.$package_minor
#echo $package_copyright
echo
AC_MSG_RESULT([ prefix..................: $prefix])
AC_MSG_RESULT([ datadir.................: $datadir])
AC_MSG_RESULT([ CFLAGS..................: $CFLAGS])
AC_MSG_RESULT([ LDFLAGS.................: $LDFLAGS])
AC_MSG_RESULT([ LIBS....................: $LIBS])
echo
+182
View File
@@ -0,0 +1,182 @@
#!/usr/bin/env bash
#
# hibachi-start.sh
#
# Limited implementation of RFC 2616 and CGI/1.1.
#
# Public Domain 2002, 2004 by Anthony Howe. All rights released.
#
# usage:
#
# hibachi-start.sh &
#
#######################################################################
# Do NOT modify the following section if you are security conscious.
#######################################################################
#
# Reset internal field separator to space, tab, newline.
# Not 100% effective if the environment we inherited has
# already played silly buggers with IFS like "IFS='S'".
#
# Use #!/usr/bin/env -i /bin/sh on shells that support
# option passing and #! lines longer than 32 bytes to
# guarantee a clean environment.
#
IFS='
'
SED=$(which sed)
#
# Get a clean environment to work with. This works for all
# Bourne like shells under Linux and Cygwin environments.
#
unset $(env | $SED -e 's/^\([^=]*\).*/\1/')
#
# Path of safe executables.
#
export PATH='/usr/local/bin:/usr/bin:/bin'
#
# Disable any environment file.
#
unset ENV
#
# Disable cd shortcuts.
#
unset CDPATH
#######################################################################
# Minimum required for serving static files.
#######################################################################
prefix=/usr/local
exec_prefix=${prefix}
datadir=${prefix}/share
sysconfdir=${prefix}/etc
sharedstatedir=${prefix}/com
localstatedir=/var
sbindir=${exec_prefix}/sbin
bindir=${exec_prefix}/bin
#
# The port to be used by the Hibachi web server.
#
# This is NOT normally a server parameter, but information about the
# client connection, but since Hibachi only listens on one port, we
# assume to know what the incoming port is and listen on that. Also
# for the purpose of demonstration, we can't bind to a privileged
# port.
#
export SERVER_PORT=8008
#
# The root of the Hibachi document tree. Virtual hosts
# are implemented as subdirectories from this location.
#
# For example, to setup virtual hosts by name or IP:
#
# /usr/local/share/hibachi/
# localhost/
# index.html
# ...
# 127.0.0.1 -> localhost/
#
# www.ioccc.org/
# index.html
# ...
# 64.81.251.233 -> www.ioccc.org/
#
#export DOCUMENT_ROOT=${datadir}/hibachi
export DOCUMENT_ROOT=$(pwd)
#
# The executable.
#
#hibachi=${sbindir}/hibachi
hibachi=`dirname $0`/hibachi
#######################################################################
# Required for most CGI scripts.
#######################################################################
#
# Your host name or IP address. Ideally this should be the server-name
# used in self-referencing URLs.
#
export SERVER_NAME=127.0.0.1
#
# My web server name and version
#
export SERVER_SOFTWARE='hibachi/1.0'
#
# Predefined environment space for the request method.
#
export REQUEST_METHOD='1234'
#
# Predefined environment space for remote address of a request.
#
export REMOTE_ADDR='123.123.123.123'
#
# Predefined environment space for upload Content-Length.
#
export CONTENT_LENGTH='123456789.123456789.'
#
# Predefined environment space for upload Content-Type.
# Look at the Apache mime.types file, there are some long ones.
#
export CONTENT_TYPE='123456789.123456789.123456789.123456789.123456789.123456789.'
#
# Predefined environment space for cookies. A single cookie can actually
# be a maximum of 4096 bytes in size, but here we only handle shorter ones.
#
export HTTP_COOKIE='123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.'
#
# Predefined environment space for the absolute path of the script
# to be processed. Required by PHP/CGI in order to find the script.
# This variable is not part of the CGI/1.1 Specification.
#
export SCRIPT_FILENAME='123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.'
#
# Hibachi does support the entire CGI/1.1 specification.
#
export GATEWAY_INTERFACE='CGI/0.0'
#
# We cannot support the following common CGI environment variables
# as specified in the draft 3 of a proposed Internet Standard
# due to space limitations, but since the draft has expired and
# on hold, there is a lot of lee way:
#
# AUTH_TYPE (MUST) HTTP_ACCEPT (MAY)
# HTTP_REFERER (MAY) PATH_INFO (MUST)
# PATH_TRANSLATED (SHOULD) REMOTE_HOST (SHOULD)
# REMOTE_IDENT (MAY) REMOTE_USER (SHOULD)
# SCRIPT_NAME (MUST) SERVER_PROTOCOL (MUST)
#
#######################################################################
# Nothing to configure below this point.
#######################################################################
#
# Start the web server.
#
exec ${hibachi}
#######################################################################
# Beyond here be dragons...
#######################################################################
+188
View File
@@ -0,0 +1,188 @@
#!/usr/bin/env bash
#
# hibachi-start.sh
#
# Limited implementation of RFC 2616 and CGI/1.1.
#
# Public Domain 2002, 2004 by Anthony Howe. All rights released.
#
# usage:
#
# hibachi-start.sh &
#
#######################################################################
# Do NOT modify the following section if you are security conscious.
#######################################################################
#
# Reset internal field separator to space, tab, newline.
# Not 100% effective if the environment we inherited has
# already played silly buggers with IFS like "IFS='S'".
#
# Use #!/usr/bin/env -i /bin/sh on shells that support
# option passing and #! lines longer than 32 bytes to
# guarantee a clean environment.
#
IFS='
'
SED=$(which sed)
#
# Get a clean environment to work with. This works for all
# Bourne like shells under most Unix like environments.
#
# Cleaning out the environment on Cygwin prevents hibachi from
# starting and would appear there is some Windows/Cygwin specific
# information maintained and required here.
#
if ! expr `uname` : 'CYGWIN.*' >/dev/null; then
unset $(env | $SED -e '/!::/d' -e 's/^\([^=]*\).*/\1/')
fi
#
# Path of safe executables.
#
export PATH='/usr/local/bin:/usr/bin:/bin'
#
# Disable any environment file.
#
unset ENV
#
# Disable cd shortcuts.
#
unset CDPATH
#######################################################################
# Minimum required for serving static files.
#######################################################################
prefix=@prefix@
exec_prefix=@exec_prefix@
datadir=@datadir@
sysconfdir=@sysconfdir@
sharedstatedir=@sharedstatedir@
localstatedir=@localstatedir@
sbindir=@sbindir@
bindir=@bindir@
#
# The port to be used by the Hibachi web server.
#
# This is NOT normally a server parameter, but information about the
# client connection, but since Hibachi only listens on one port, we
# assume to know what the incoming port is and listen on that. Also
# for the purpose of demonstration, we can't bind to a privileged
# port.
#
export SERVER_PORT=@enable_port@
#
# The root of the Hibachi document tree. Virtual hosts
# are implemented as subdirectories from this location.
#
# For example, to setup virtual hosts by name or IP:
#
# /usr/local/share/hibachi/
# localhost/
# index.html
# ...
# 127.0.0.1 -> localhost/
#
# www.ioccc.org/
# index.html
# ...
# 64.81.251.233 -> www.ioccc.org/
#
#export DOCUMENT_ROOT=${datadir}/hibachi
export DOCUMENT_ROOT=$(pwd)
#
# The executable.
#
#hibachi=${sbindir}/@PACKAGE_NAME@
hibachi=`dirname $0`/@PACKAGE_NAME@
#######################################################################
# Required for most CGI scripts.
#######################################################################
#
# Your host name or IP address. Ideally this should be the server-name
# used in self-referencing URLs.
#
export SERVER_NAME=127.0.0.1
#
# My web server name and version
#
export SERVER_SOFTWARE='@PACKAGE_NAME@/@PACKAGE_VERSION@'
#
# Predefined environment space for the request method.
#
export REQUEST_METHOD='1234'
#
# Predefined environment space for remote address of a request.
#
export REMOTE_ADDR='123.123.123.123'
#
# Predefined environment space for upload Content-Length.
#
export CONTENT_LENGTH='123456789.123456789.'
#
# Predefined environment space for upload Content-Type.
# Look at the Apache mime.types file, there are some long ones.
#
export CONTENT_TYPE='123456789.123456789.123456789.123456789.123456789.123456789.'
#
# Predefined environment space for cookies. A single cookie can actually
# be a maximum of 4096 bytes in size, but here we only handle shorter ones.
#
export HTTP_COOKIE='123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.'
#
# Predefined environment space for the absolute path of the script
# to be processed. Required by PHP/CGI in order to find the script.
# This variable is not part of the CGI/1.1 Specification.
#
export SCRIPT_FILENAME='123456789.123456789.123456789.123456789.123456789.123456789.123456789.123456789.'
#
# Hibachi does support the entire CGI/1.1 specification.
#
export GATEWAY_INTERFACE='CGI/0.0'
#
# We cannot support the following common CGI environment variables
# as specified in the draft 3 of a proposed Internet Standard
# due to space limitations, but since the draft has expired and
# on hold, there is a lot of lee way:
#
# AUTH_TYPE (MUST) HTTP_ACCEPT (MAY)
# HTTP_REFERER (MAY) PATH_INFO (MUST)
# PATH_TRANSLATED (SHOULD) REMOTE_HOST (SHOULD)
# REMOTE_IDENT (MAY) REMOTE_USER (SHOULD)
# SCRIPT_NAME (MUST) SERVER_PROTOCOL (MUST)
#
#######################################################################
# Nothing to configure below this point.
#######################################################################
#
# Start the web server.
#
exec ${hibachi}
#######################################################################
# Beyond here be dragons...
#######################################################################
+155
View File
@@ -0,0 +1,155 @@
#define B break;
#define Q if(
#define R return
#define V getenv(
#define T "DOCUMENT_ROOT"
#define S snprintf(
#define C strcspn(u,
#include <fcntl.h>
#include <dirent.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <ctype.h>
#define Z 8192
char r[Z], q[Z], l[Z], w[Z], *o, *m = "404 Not Found", *e = "500 Error";
void
X(int t, char *u, long j)
{
j = S
q, Z,
"HTTP/1.0 %s\r\nContent-Length: %ld\r\n\r\n%s",
u, j ? j : C ""), j ? "" : u
);
send(t, q, j, 0);
}
void
A(char *i, char *j)
{
char *u;
Q (u = strstr(o, i + 5)))
sscanf(u + C ":") + 1, j, V i));
}
int
main(int c, char **p)
{
int f, t, i;
struct stat g;
struct sockaddr_in a;
char *v, *u;
Q (v = V "SERVER_PORT")) == 0) {
R 4;
}
i = (int) strtol(v, 0, 10);
a.sin_addr.s_addr = htonl(INADDR_ANY);
a.sin_port = htons((unsigned short) i);
a.sin_family = AF_INET;
Q (f = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
R 5;
}
Q bind(f, (void *) &a, sizeof a)) {
R 6;
}
Q listen(f, 10)) {
R 7;
}
for ( ; ; close(t)) {
for ( ; waitpid(0, 0, WNOHANG) > 0; )
;
i = sizeof a;
Q (t = accept(f, (void *) &a, &i)) < 0)
continue;
Q fork())
continue;
for (f = i = 0; f < 2 && i < Z; i++) {
Q recv(t, r + i, 1, 0) <= 0)
R 1;
Q r[i] == '\n')
f++;
Q r[i] == ':')
f = 0;
Q f)
r[i] = r[i] == '-' ? '_' : toupper(r[i]);
}
Q Z <= i)
B
r[i] = 0;
Q *r != 'G' && *r != 'H' && r[2] != 'S') {
X(t, "501 Unsupported", 0);
B
}
*l = 0;
Q (v = strstr(r, "HOST:")))
sscanf(v+5, " %255[^:\r\n]", l);
S w, Z, T "=%s/%s", V T), l);
putenv(w);
u = r + 4 + (*r != 'G');
Q *u != '/' || strstr(u, "../")) {
X(t, m, 0);
B
}
u[i = C " ")] = 0;
o = u + i + 1;
i = C "?");
Q u[i]) {
S q, Z, "QUERY_STRING=%s", u+i+1);
putenv(q);
u[i] = 0;
}
S l, Z, "SCRIPT_FILENAME=%s%s", w+14, u);
v = l+16;
Q stat(v, &g) < 0) {
X(t, m, 0);
B
}
Q S_ISDIR(g.st_mode)) {
struct dirent *d;
DIR *D = opendir(v);
for ( ; (d = readdir(D)); ) {
Q !strncmp(d->d_name, "index.", 6)) {
strncat(v, d->d_name, Z-16);
stat(v, &g);
B
}
}
closedir(D);
Q d == 0) {
X(t, m, 0);
B
}
}
Q *r != 'H') {
Q g.st_mode & 0111) {
putenv(l);
sscanf(r, "%4s", V "REQUEST_METHOD"));
sscanf(inet_ntoa(a.sin_addr), "%15s", V "REMOTE_ADDR"));
A("HTTP_COOKIE", "%*[ \t]%80[^\r\n]");
A("CONTENT_LENGTH", "%20s");
A("CONTENT_TYPE", "%60s");
dup2(t, 0);
dup2(t, 1);
Q system(v))
X(t, e, 0);
B
}
Q (f = open(v, O_RDONLY)) < 0) {
X(t, e, 0);
B
}
}
X(t, "200 OK", g.st_size);
Q *r != 'H') {
for ( ; 0 < (i = read(f, r, Z)); )
send(t, r, i, 0);
}
B
}
shutdown(t, SHUT_WR);
R 0;
}
@@ -0,0 +1,16 @@
CHANGES
-------
The major number changes for such things as code rewrites, changes in
syntax, and/or dramatic changes in functionality. The minor number
changes for corrections, enhancements, etc. made to the code. There
is no set schedule for releases.
--TODO--
--1.0--
Initial release. Submission to the IOCCC 2004.
@@ -0,0 +1,63 @@
CHANGES
-------
The major number changes for such things as code rewrites, changes in
syntax, and/or dramatic changes in functionality. The minor number
changes for corrections, enhancements, etc. made to the code. There
is no set schedule for releases.
--TODO--
+ Figure out why Links browser doesn't work.
--1.0--
Initial release. Submission to the IOCCC 2004.
--0.8--
+ Add support for SCRIPT_FILENAME for PHP/CGI.
+ Restructured directories.
+ Added autoconf configure.in script and friends.
--0.7--
! Replaced print() macro by expansion in status(). Only used in one
place. This also fixes a macro expansion bug in status().
! status() now correctly passes the size of the status response
headers to send().
! Fixed transform.sed which incorrectly transform Host: header string
into h:.
+ Experimented with configure.in and makefile.in. Not really necessary
and the macros tests required in the source exceed the size limit.
--0.6--
! Renamed error() to status(). Set content-length to that of the
response message or static file.
+ Added more details comments with citiations of relavent paragraphs
from RFC 2616 and the CGI/1.1 specification.
! Enlarged header parsing buffer from 4KB to 8KB.
! Changed parsing of request CRLF to allow for just LF.
+ Fold case of request headers to lower case, because of problem with
Lynx not specifying headers as they appear in RFC 2616.
--0.5--
+ First attempt static file web server, with virtual host support.
+ Added support for CGI/1.1 specification, in particular "nph" CGIs
with a selected set of necessary environment variables.
Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 909 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

+432
View File
@@ -0,0 +1,432 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Snert . Com - Software - Hibachi
</title>
<meta name="keywords" content="hibachi IOCCC International Obfuscated C Code Contest HTTP web server RFC 2616 Apache Unix Linux Cygwin Windows">
<meta name="description" content="A small and simple web server with CGI support. It is a limited implementation of RFC 2616. Works for unix boxen, Cygwin, and Windows.">
<script language="JavaScript" type="text/javascript" src="./mailto.js"></script>
<link rel="stylesheet" type="text/css" href="./style.css">
</head>
<body class="normal" background="Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<!-- MARGINS -->
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td rowspan="2">
<img alt="" src="Img/mrpixel.gif" width="130" height="1">
<!--
</td><td>
<img alt="Snert . Com" src="Img/sun.gif" width="105" height="103">
-->
</td><td align="center" style="padding-left: 30px; text-align: center;">
<img alt="HIBACHI/1.0 Web Server" src="Img/hibachi-256-oc-nc-300x150.gif" width="300" height="150" border="0">
<!-- <span class="title hibachi">HIBACHI/1.0</span> -->
<!--
<br>
<span class="plain">from</span>&nbsp;&nbsp;
<span class="snert">Snert</span>
-->
</td>
</tr><tr>
<td colspan="2" style="padding: 0 50 0 0;">
<!-- PAGE BODY -->
<br>
<blockquote class="normal big" style="font-weight: bold; margin: 30px 50px 30px 50px;">
[hih-BAH-chee]
<br>
<br>
Japanese for "fire bowl", a hibachi is just that - a small
(generally cast-iron) container made for holding fuel
(usually charcoal). A grill that sits on top of the bowl
is used to cook various foods. Hibachis come in square,
oblong and round models. Because of their compact size,
they're completely portable.
<p class="small">-
<a href="http://eat.epicurious.com/dictionary/food/index.ssf?DEF_ID=2150">
epicurious.com food dictionary</a>
</p>
</blockquote>
<a name="Description"></a>
<h2>Description</h2>
<p>
<span class="hibachi">HIBACHI</span> is a simple, small, and secure web server with virtual
host and CGI support. It is a limited implementation of <a href="reference/rfc2616.html">RFC 2616</a>
and the <a href="http://www.w3.org/CGI/">CGI/1.1 Specification</a>.
<span class="hibachi">HIBACHI</span> was written as an entry for the
<a href="http://www.ioccc.org/">International Obfuscated C Code Contest</a> and works
for any Unix variant including the <a href="http://sources.redhat.com/cygwin/">Cygwin</a>
environment for Windows.
</p>
<p>
<span class="hibachi">HIBACHI</span> supports dynamic web content through the use of the
<a href="http://www.w3.org/CGI/">Common Gateway Interface (CGI)</a> specification.
Just about any scripting or programming language can be used, such as a POSIX shell,
<a href="http://www.perl.com/">Perl</a>,
<a href="http://www.php.net/">PHP</a>,
<a href="http://www.python.org/">Python</a>, and/or
<a href="http://www.ruby-lang.org/">Ruby</a>.
Existing CGI scripts can be used with little or no modification.
Hibachi executes all CGI scripts as though they were "nph" prefixed, which is to say that it is
the script's responsibility to send the HTTP status line and necessary headers direct to the client.
</p>
<p>
Virtual host support is implemented as subdirectories of the <span class="hibachi">HIBACHI</span>
document tree, where the directory name is the domain name publish in a URL. For example to setup
a virtual host by name or IP for http://www.ioccc.org/, assuming the <span class="hibachi">HIBACHI</span>
document tree is rooted at /usr/local/share/hibachi, then:
</p>
<blockquote><pre>
/usr/local/share/hibachi/
www.ioccc.org/
index.html
...
64.81.251.233 -> www.ioccc.org/
</pre></blockquote>
<p>
<span class="hibachi">HIBACHI</span> is ideal
for special floppy-Linux distributions, like
<a href="http://leka.muumilaakso.org/">Leka</a>, which can be used for rescue, firewall,
demo, or dedicated servers. In theory, with some modifications,
<span class="hibachi">HIBACHI</span> and a script interpreter, like <a href="http://www.php.net/">PHP</a>, could also be
bundled with CDROMS that require a means of presenting dynamic web pages.
</p>
<a name="Features"></a>
<h2>Features</h2>
<ul>
<li>Supports virtual hosts.</li>
<li>Supports all MIME types.</li>
<li>Supports Common Gateway Interface (<a href="http://www.w3.org/CGI/">CGI</a>) scripts and programs.</li>
<li>Supports multiple index.* file types, ie. index.html, index.php, index.pl</li>
<li>Supports subset of <a href="reference/rfc2616.html">RFC 2616</a> HTTP/1.1 methods GET, HEAD, and POST.</li>
<li>Simple &amp; straight forward configuration using environment variables.</li>
<li>Portability across Unix-like environments, ie. <a href="http://sources.redhat.com/cygwin/">Cygwin</a>, <a href="http://www.freebsd.org/">FreeBSD</a>, Linux, SunOS.</li>
<li>Known to work with <a href="http://lynx.isc.org/lynx-2.8.3/index.html">Lynx</a>, <a href="http://www.mozilla.org/">Mozilla</a>, <a href="http://www.opera.com/">Opera</a>, and Internet Explorer web browsers.</li>
<li>Is a dedicated process-forking server that does not use inetd.</li>
<li>Is secure against relative path file snooping.</li>
<li>Is secure against directory searches.</li>
<li>~155 lines of source, 1940 bytes long by <a href="http://www.ioccc.org/">IOCCC</a> 2004 rules, ~6KB compiled &amp; stripped on FreeBSD.</li>
<li>Superior &amp; smaller than <a href="http://www.acme.com/software/micro_httpd/">micro_httpd</a> from <a href="http://www.acme.com/">ACME</a>.</li>
<li>And has a really cool animated logo too.</li>
</ul>
<!--
<a href="http://www.borland.com/products/downloads/download_cbuilder.html">Borland C++ 5.5</a> free command-line compiler and debugger
-->
<a name="Installation"></a>
<h2>Installation</h2>
<ol>
<li><p>
Download:
</p>
<blockquote>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="normal hline" style="padding: 0 30 5 0;"><a href="http://hibachi.snert.org:8008/hibachi-1.0.tar.gz">Hibachi-1.0 Obfuscated</a></td>
<td class="normal hline" style="padding: 0 30 5 0;"><a href="http://hibachi.snert.org:8008/hibachi.md5">md5sum</a></td>
<td class="normal hline" style="padding: 0 0 5 0;"><a href="http://hibachi.snert.org:8008/CHANGES-OBFUSCATED.TXT">Change Log</a></td>
</tr>
<tr>
<td style="padding: 5 30 0 0;"><a href="http://hibachi.snert.org:8008/hibachi-spoiler-1.0.tar.gz">Hibachi-1.0 Spoiler</a></td>
<td style="padding: 5 30 0 0;"><a href="http://hibachi.snert.org:8008/hibachi-spoiler.md5">md5sum</a></td>
<td style="padding: 5 0 0 0;"><a href="http://hibachi.snert.org:8008/CHANGES-SPOILER.TXT">Change Log</a></td>
</tr>
</table>
</blockquote>
</li>
<li>
<p>
Unpack and build the executable:
</p>
<blockquote><tt>
tar -zxf hibachi-1.0.tgz<br>
cd hibachi-1.0<br>
./configure<br>
make
</tt></blockquote>
</li>
</ol>
<a name="Usage"></a>
<h2>Usage</h2>
<p>
First read and configure the file <code>hibachi-start.sh</code>. In most cases the
defaults settings should be fine for testing. Start the server in
the background, and perform the initial test (assuming that SERVER_PORT was
not altered in <code>hibachi-start.sh</code>):
</p>
<blockquote><pre>
./hibachi-start.sh &amp;
lynx http://localhost:8008/
</pre></blockquote>
<p>
To stop the server:
</p>
<blockquote><pre>
kill %1
</pre></blockquote>
<p>
To access this documentation and examples from the Internet, create symbolic links for the
host name and/or IP pointing to the &laquo;localhost&raquo; directory. For example, replace the IP and host
name addresses below with that of the machine running
<span class="hibachi">HIBACHI</span>:
</p>
<blockquote><pre>
ln -s localhost 64.81.251.233
ln -s localhost www.ioccc.org
</pre></blockquote>
<p>
<span class="hibachi">HIBACHI</span> can server multiple
web sites from the same machine simply by creating content directories with the same
name as the URL domain names within the document root tree. Domain and/or IP aliases are simply symbolic links
to content directories. There is never any need to restart <span class="hibachi">HIBACHI</span>
when web sites are published or aliases added.
Assuming the server is running and that port 8008 is not blocked by any firewall,
you should be able to access the server from the Internet using an IP or host name URL similar to:</p>
</p>
<blockquote><pre>
http://64.81.251.233:8008/
http://www.ioccc.org:8008/
</pre></blockquote>
<p>
Port 8008 (http-alt) was chosen as the default port for demonstration purposes,
since its an alternative HTTP port that does not require special privileges and
is rarely in use.
Of course, <span class="hibachi">HIBACHI</span> could be run as a standard
web server on port 80, but this would require that it be installed by
the system administrator, contrary to IOCCC rules.
</p>
<a name="Test"></a>
<h2>CGI Examples</h2>
<p>
The following tests and examples are available to demonstrate various
aspects of the CGI support:
</p>
<dl>
<dt><a href="test/shell/test0.sh">POSIX Shell Example</a></dt>
<dd>
These CGI scripts perform some basic tests on the handling of GET and POST requests,
cookies, and the passing of environment variables to CGI scripts. These CGI scripts
assume that <span class="path">/bin/sh</span> is a POSIX compliant shell and the
standard set of POSIX utilities are available. Should work for all Unix variants
and <a href="http://sources.redhat.com/cygwin/">Cygwin</a>.
</dd>
<dt><a href="test/perl/">Perl Example</a></dt>
<dd>
<a href="http://www.perl.com/"><img alt="Powered by Perl" src="Img/rectangle_power_perl.gif" width="88" height="31" border="0" hspace="20" align="right"></a>
This example queries the Yahoo web site for a stock quote to insert into a web page.
<u><i>This example requires a browser with JavaScript support </i></u> and
should work for all Unix variants and <a href="http://sources.redhat.com/cygwin/">Cygwin</a>, when Perl is installed.
</dd>
<dt><a href="test/php/">PHP Example</a></dt>
<dd>
<a href="http://www.php.net/"><img alt="Powered by PHP" src="Img/php-small-trans-light.gif" width="88" height="31" border="0" hspace="20" align="right"></a>
This PHP example generates a calendar complete with ISO 8601:2000 week numbers.
<!--
This example shows how PHP might be used to format the result of a web form into
something human readable suitable for sending by email.
-->
<p>
The Windows PHP CGI binary distribution from the
<a href="http://www.php.net/">PHP</a> web site does not work within the <a href="http://sources.redhat.com/cygwin/">Cygwin</a>
environment. Instead, download the source distribution and build the PHP CGI and CLI versions from scratch
from within Cygwin. <!-- The CLI is desired, since it behaves more like an nph-CGI. -->
The following commands were used to build:
<blockquote><pre>
# Without this link, the configure script has problems with Cygwin.
ln -s /bin/gcc /bin/cc
CFLAGS=-O ./configure \
--with-config-file-path=/usr/local/etc:/etc \<!--
--enable-calendar \
--enable-shared \
--disable-cgi \
--enable-cli \ -->
--enable-discard-path \
--disable-xml \
--without-pear \
--enable-sockets \
--enable-bcmath \
--enable-ftp \
--enable-dba \
--with-inifile
make
make install
# Install both the CGI and CLI (though the CLI is not used here).
mv /usr/local/bin/php /usr/local/bin/php.cgi.exe
make install-cli
mv /usr/local/bin/php /usr/local/bin/php.exe
cp php.ini-recommended /etc/php.ini
</pre>
</blockquote>
<p>
The php.ini file should specify "output_buffering = 4096" so that PHP scripts have a chance to
modify the response status and headers before the body is sent. Also set "cgi.rfc2616_headers = 1".
Click here to display the <a href="test/php/info.php">PHP Info</a> configuration.
</p>
</dd>
<!--
-->
<dt><a href="test/ruby/">Ruby Example</a></dt>
<dd>
This example validates and/or generates Luhn check-digits.
Should work for all Unix variants and <a href="http://sources.redhat.com/cygwin/">Cygwin</a>,
when Ruby is installed.
</dd>
</dl>
<a name="Portability"></a>
<h2>Portability</h2>
<blockquote>
<table border="0" cellspacing="4" cellpadding="0">
<tr valign="middle">
<td align="right">
<a href="http://www.freebsd.org/"><img alt="FreeBSD" src="Img/freebsd.gif" width="94" height="39" border="0" hspace="20" border="0"></a>
</td>
<td rowspan="4">&nbsp;&nbsp;&nbsp;</td>
<td>
4.8
</td>
</tr>
<tr valign="middle">
<td align="right">
<img alt="Linux" src="Img/logosml.256.png" width="92" height="39" border="0" hspace="20">
</td>
<td>
Cobalt Qube 1, RedHat Linux 5.1, gcc 2.7.2
</td>
</tr>
<tr valign="middle">
<td bgcolor="#594FBF" align="right">
<a href="http://www.sun.com/"><img src="Img/sun_logo.gif" width="94" height="39" border="0" alt="Sun Microsystems Logo" vspace="0" hspace="20"></a>
</td>
<td>
5.8
</td>
</tr>
<tr valign="middle">
<td align="right">
<!-- <span class="large" style="position: relative; top: -8px">+</span> --><a href="http://sources.redhat.com/cygwin/"><img alt="Cygwin Unix Emulation" src="Img/cygwin-icon.gif" width="28" height="28" border="0" hspace="20" vspace="8" align="right"></a>
<img alt="Microsoft Windows" src="Img/win.gif" width="40" height="40" border="0" style="padding: 3px 6px 0 0;" align="right">
</td>
<td>
Windows 2000 SP4, Windows XP Pro SP1
<br>with <a href="http://sources.redhat.com/cygwin/">Cygwin</a>, gcc 2.95.3-5
</td>
</tr>
</table>
</blockquote>
<a name="License"></a>
<h2>License</h2>
<p>
In accordance with the
<a href="http://www.ioccc.org/">International Obfuscated C Code Contest</a>
this is an original work and placed in the public domain.
</p>
<!--
<p>
In all cases a monetary donation and/or <a href="http://www.amazon.com/">Amazon</a>
wishlist gifts to the author are welcomed, but not required, for the continued
encouragment, moral support, and ego pumping needed to work in foriegn non-english
speaking lands.
</p>
-->
<a name="Disclaimer"></a>
<h2>Disclaimer</h2>
<p>
THIS SOFTWARE IS PROVIDE "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO WAY SHALL THE
AUTHOR OR LICENSEE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
</p>
<a name="Support"></a>
<h2>Support</h2>
<p>
Free support is limited, based on the author's availability, though
enhancements requests and problem reports are welcome (see logo above).
</p>
&nbsp;&nbsp;&nbsp;&nbsp;
<div align="center">
<a href="http://hibachi.snert.org:8008/">
<img alt="Powered by Hibachi" src="Img/powered-by-hibachi-150x75.png" width="150" height="75" border="1" style="color: #000000"></a>
</div>
<!-- copyright -->
<div align="center" class="copyright">
<nobr>Public Domain 2004 by
<a href="javascript:achowe()">
Anthony C Howe</a>.</nobr>
</div>
<!--end copyright-->
<br/>
<!-- END PAGE BODY -->
</td>
</tr>
</table>
<!-- END MARGINS -->
</body>
</html>
File diff suppressed because it is too large. Load diff
+110
View File
@@ -0,0 +1,110 @@
body {
padding: 0px 60px 0px 10px;
}
.normal, p, ul {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 12pt;
color: #000000;
text-align: justify;
}
.title {
/* font-family: serif; */
font-weight: bold;
font-size: 24pt;
color: #3099ff;
}
.hibachi {
color: #b50000;
font-style: italic;
}
.small {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 8pt;
color: #000000;
}
.copyright {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 9pt;
color: #000000;
}
.big, h3 {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 12pt;
color: #000000;
}
.large, h2 {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-weight: normal;
font-size: 16pt;
color: #000000;
}
.huge, h1 {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 26pt;
}
.project {
text-decoration: none;
font-weight: bold;
# color: #3099ff;
}
.plain {
font-family: serif;
font-size: 14pt;
color: #000000;
}
.snert {
font-family: serif;
font-weight: bold;
font-size: 16pt;
color: #000000;
z-index: 10;
}
.serif {
font-family: serif;
}
a {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-weight: bold;
text-decoration: none;
}
a:link {
/* color: #0000ff; */
color: #aa0000;
}
a:hover {
/* color: #000080; */
color: #dd0000;
text-decoration: underline;
}
a:visited {
/* color: #000080; */
color: #800000;
}
.syntax {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-weight: normal;
font-size: 11pt;
color:#000080;
}
.param {
color:#0000cc;
font-style: italic;
font-weight: normal
}
dd {
margin: 0 20px 20px 30px;
}
.path {
font-family: monospace;
font-weight: bold;
font-size: 10pt;
}
.hline {
border-collapse: collapse;
border-bottom: 1px solid;
border-color: #000000;
}
@@ -0,0 +1,66 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - Stock Price Example in Perl
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
<script language="JavaScript" type="text/javascript" src="yahoo-ticker.pl?DIR.V"></script>
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<h2>Stock Price Fetch Example in Perl</h2>
<p>
(This example requires JavaScript.)
</p>
<table border="0" style="margin: 30 20 30 0;">
<tr>
<td rowspan="7">
&nbsp;&nbsp;&nbsp;&nbsp;
</td>
<th style="text-align: right;">Exchange : </th><td>CDNX</td>
</tr><tr>
<th style="text-align: right;">Symbol : </th><td>DIR</td>
</tr><tr>
<th style="text-align: right;">Share Price : </th>
<td>
<script language="JavaScript" type="text/javascript">
document.write(ticker['price']);
</script>
&nbsp;
</td>
</tr>
<tr>
<th style="text-align: right;">Volume : </th>
<td>
<script language="JavaScript" type="text/javascript">
document.write(ticker['volume']);
</script>
</td>
</tr><tr>
<th style="text-align: right;">Last Trade : </th>
<td>
<script language="JavaScript" type="text/javascript">
document.write(ticker['last']);
</script>
</td>
</tr>
</table>
<hr/>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
+77
View File
@@ -0,0 +1,77 @@
#!/usr/bin/perl
#
# yahoo-ticker.pl
#
# Copyright 1998 by Anthony Howe. All rights reserved.
#
# Usage: yahoo-ticker.pl?<symbol>
#
##########################################################################
# Nothing to be configured below this point.
##########################################################################
use Socket;
# WORK-AROUND 1.
# BAH! Some Perl implementations (for Windows) are not created equal.
# Force I/O flushes after each read/write operation.
$| = 1;
#########################################################################
# Open connection to URL.
#########################################################################
my ($symbol) = $ENV{'QUERY_STRING'} =~ /\??(.*)/;
# Figure out who we have to call.
#($host, $port, $path) = ($url =~ m!http://([^:/]+)(?:\:(\d*))?(/.*)!);
$host = "finance.yahoo.com";
$port = 80 unless defined $port;
$path = "/q?s=$symbol";
# Get a socket...
unless (socket(HTTP, PF_INET, SOCK_STREAM, getprotobyname('tcp'))) {
print("[CGI failed ($!)]\n");
exit(0);
}
# ...set socket to be line buffered...
select( (select(HTTP), $| = 1)[0] );
# .. make the connection.
unless (connect(HTTP, sockaddr_in($port, inet_aton("$host")))) {
print("[CGI failed ($!)]\n");
exit(0);
}
print HTTP "GET $path HTTP/1.0\nHost: $host\n\n";
while (<HTTP>) {
# Last trade price line.
if (m!>Last Trade:<!) {
($price) = (m!Last Trade:</td><td class="yfnc_tabledata1"><big><b>(\d+\.\d+)</b></big></td>!);
}
if (m!>Trade Time:<!) {
($last) = (m!Trade Time:</td><td class="yfnc_tabledata1">([^<]+)</td>!);
}
if (m!>Volume:<!) {
($volume) = (m!Volume:</td><td class="yfnc_tabledata1">([^<]+)</td>!);
}
}
close(HTTP);
print "HTTP/1.0 200 OK\n";
print "Content-Type: text/javascript\n\n";
print "var ticker = new Array();\n";
print "ticker['price'] = $price;\n";
print "ticker['volume'] = \"$volume\";\n";
print "ticker['last'] = \"$last\";\n";
exit 0;
@@ -0,0 +1,77 @@
#!@perl_exe@
#
# yahoo-ticker.pl
#
# Copyright 1998 by Anthony Howe. All rights reserved.
#
# Usage: yahoo-ticker.pl?<symbol>
#
##########################################################################
# Nothing to be configured below this point.
##########################################################################
use Socket;
# WORK-AROUND 1.
# BAH! Some Perl implementations (for Windows) are not created equal.
# Force I/O flushes after each read/write operation.
$| = 1;
#########################################################################
# Open connection to URL.
#########################################################################
my ($symbol) = $ENV{'QUERY_STRING'} =~ /\??(.*)/;
# Figure out who we have to call.
#($host, $port, $path) = ($url =~ m!http://([^:/]+)(?:\:(\d*))?(/.*)!);
$host = "finance.yahoo.com";
$port = 80 unless defined $port;
$path = "/q?s=$symbol";
# Get a socket...
unless (socket(HTTP, PF_INET, SOCK_STREAM, getprotobyname('tcp'))) {
print("[CGI failed ($!)]\n");
exit(0);
}
# ...set socket to be line buffered...
select( (select(HTTP), $| = 1)[0] );
# .. make the connection.
unless (connect(HTTP, sockaddr_in($port, inet_aton("$host")))) {
print("[CGI failed ($!)]\n");
exit(0);
}
print HTTP "GET $path HTTP/1.0\nHost: $host\n\n";
while (<HTTP>) {
# Last trade price line.
if (m!>Last Trade:<!) {
($price) = (m!Last Trade:</td><td class="yfnc_tabledata1"><big><b>(\d+\.\d+)</b></big></td>!);
}
if (m!>Trade Time:<!) {
($last) = (m!Trade Time:</td><td class="yfnc_tabledata1">([^<]+)</td>!);
}
if (m!>Volume:<!) {
($volume) = (m!Volume:</td><td class="yfnc_tabledata1">([^<]+)</td>!);
}
}
close(HTTP);
print "HTTP/1.0 200 OK\n";
print "Content-Type: text/javascript\n\n";
print "var ticker = new Array();\n";
print "ticker['price'] = $price;\n";
print "ticker['volume'] = \"$volume\";\n";
print "ticker['last'] = \"$last\";\n";
exit 0;
@@ -0,0 +1,557 @@
<?
class Date
{
var $date;
var $time;
//
// Create a new date object set to the time now.
//
function Date()
{
$this->setTime(time());
}
function isLeapYear(/* year */)
{
if (func_num_args() == 1)
$year = func_get_arg(0);
else
$year = $this->date['year'];
if ($year % 4000 == 0)
return false;
if ($year % 400 == 0)
return true;
if ($year % 100 == 0)
return false;
if ($year % 4 == 0)
return true;
return false;
}
//
// Return the number of seconds since system epoch.
//
function getTime()
{
return $this->time;
}
//
// Set the date / time in seconds for the object.
//
function setTime($t)
{
$this->time = $t;
$this->date = getdate($t);
}
function getHour()
{
return $this->date['hour'];
}
function getMinute()
{
return $this->date['minutes'];
}
function getSecond()
{
return $this->date['seconds'];
}
function getMonth()
{
return $this->date['mon'];
}
function getYear()
{
return $this->date['year'];
}
function getDayOfWeek()
{
return $this->date['wday'];
}
function getDayOfMonth()
{
return $this->date['mday'];
}
function getDayOfYear()
{
return $this->date['yday'];
}
function getDaysInMonth(/* year, month */)
{
if (func_num_args() == 2) {
$year = func_get_arg(0);
$month = func_get_arg(1);
} else {
$year = $this->date['year'];
$month = $this->date['mon'];
}
$endOfMonth = Array(
31,
28 + Date::isLeapYear($year),
31,
30,
31,
30,
31,
31,
30,
31,
30,
31
);
return $endOfMonth[$month-1];
}
function getPreviousMonth()
{
if ($this->date['mon'] <= 1)
return 12;
return $this->date['mon']-1;
}
function getNextMonth()
{
if (12 <= $this->date['mon'])
return 1;
return $this->date['mon']+1;
}
function getFirstWeekDayOfMonth(/* year, month */)
{
if (func_num_args() == 2) {
$y = func_get_arg(0);
$m = func_get_arg(1);
} else {
$y = $this->date['year'];
$m = $this->date['mon'];
}
// Day of the week 0..6 (Sunday..Saturday).
$weekDay = strftime("%w", mktime(0, 0, 0, $m, 1, $y));
// Day of the week 1..7 (Monday..Sunday).
return $weekDay == 0 ? 7 : $weekDay;
}
function getNumberOfWeeks(/* year */)
{
if (func_num_args() == 1)
$year = func_get_arg(0);
else
$year = $this->date['year'];
/* An ISO calendar year y is long (contains 53 weeks) if:
*
* p(y) modulo 7 = 4
*
* or if:
*
* p(y-1) modulo 7 = 3
*
* with:
*
* p(y) = y + floor(y/4) - floor(y/100) + floor(y/400)
*
* http://www.phys.uu.nl/~vgent/calendar/isocalendar.htm
*/
if (($year + floor($year/4) - floor($year/100) + floor($year/400)) % 7 == 4)
return 53;
if ((--$year + floor($year/4) - floor($year/100) + floor($year/400)) % 7 == 3)
return 53;
return 52;
}
/*
* Return ISO 8601:2000(E) week number. This is a work around for
* Windows, which does not support a working strftime %V format.
*/
function getWeekNumber(/* year, month, day */)
{
if (func_num_args() == 3) {
$year = func_get_arg(0);
$month = func_get_arg(1);
$day = func_get_arg(2);
} else {
$year = $this->date['year'];
$month = $this->date['mon'];
$day = $this->date['mday'];
}
/* The week number of the current year as a decimal number, range
* 00 to 53, starting with the first Monday as the first day of
* week 01.
*/
$week = strftime("%W", mktime(0, 0, 0, $month, $day, $year));
/* Week days numbered 0 (Sunday) to 6 (Saturday). */
$firstWeekDayThisYear = strftime("%w", mktime(0, 0, 0, 1, 1, $year));
$firstWeekDayNextYear = strftime("%w", mktime(0, 0, 0, 1, 1, $year+1));
/* The first ISO calendar week of a year is the one that includes the
* first Thursday of that year. In other words, the first week of the
* ISO calendar year is the earliest week that contains at least four
* days of the month of January.
*/
if (1 < $firstWeekDayThisYear && $firstWeekDayThisYear < 5) {
/* The first Thursday of the current ISO year was in week zero. */
$week++;
}
if ($week == 53 && 1 < $firstWeekDayNextYear && $firstWeekDayNextYear < 5) {
/* The first Thursday of the following ISO year is this week. */
$week = 1;
}
if ($week == 0) {
/* Number of weeks last year. */
$week = Date::getNumberOfWeeks($year-1);
}
return $week+0;
}
//
// Return the number seconds as of zero hour today.
//
function getDate()
{
return mktime(0, 0, 0, $this->date['mon'], $this->date['mday'], $this->date['year']);
}
//
// Set date as of zero hour that day.
//
function setDate($year, $month, $day)
{
$this->setDateTime($year, $month, $day, 0, 0, 0);
}
//
// Return the date / time array.
//
function getDateTime()
{
return $this->date;
}
//
// Set the date / time for the object.
//
function setDateTime($year, $month, $day, $hour, $minute, $second)
{
$time = mktime($hour, $minute, $second, $month, $day, $year, 0);
$this->setTime($time);
}
//
// Adjust the date / time of the object.
//
function addDateTime($year, $month, $day, $hour, $minute, $second)
{
$t = mktime(
$this->date['hour'] + $hour,
$this->date['minutes'] + $minute,
$this->date['seconds'] + $second,
$this->date['mon'] + $month,
$this->date['mday'] + $day,
$this->date['year'] + $year
);
$this->setTime($t);
}
//
// Return the date / time as an ISO date string.
//
function getDateISO()
{
return strftime("%Y-%m-%d %H:%M:%S", $this->time);
}
//
// Set the date / time of the object using an ISO date string.
//
function setDateISO($str)
{
if (!ereg('([0-9]+)-([0-9]+)-([0-9]+)', $str, $ymd))
$ymd = array('','0','0','0');
if (!ereg('([0-9]+):([0-9]+):([0-9]+)\+([0-9]+)', $str, $hms))
$hms = array('','0','0','0');
// Assume local time, ignore timezone.
$this->setDateTime(
intval($ymd[1]),
intval($ymd[2]),
intval($ymd[3]),
intval($hms[1]),
intval($hms[2]),
intval($hms[3])
);
}
function setDateMySQL($str)
{
$n = sscanf($str, "%4d%2d%2d%2d%2d%2d", $y, $m, $d, $H, $M, $S);
$this->setDateTime($y, $m, $d, $H, $M, $S);
}
//
// Relational operations between Date vs time or Date vs Date.
//
function eq($t)
{
if (is_object($t)) $t = $t->getTime();
return $this->time == $t;
}
function ne($t)
{
if (is_object($t)) $t = $t->getTime();
return $this->time != $t;
}
function lt($t)
{
if (is_object($t)) $t = $t->getTime();
return $this->time < $t;
}
function le($t)
{
if (is_object($t)) $t = $t->getTime();
return $this->time <= $t;
}
function gt($t)
{
if (is_object($t)) $t = $t->getTime();
return $this->time > $t;
}
function ge($t)
{
if (is_object($t)) $t = $t->getTime();
return $this->time >= $t;
}
/*
* $obj->getSmallCalendar()
* Date::getSmallCalendar($year, $month)
*/
function getSmallCalendar(/* [$year, $month] */)
{
if (func_num_args() == 2) {
$year = func_get_arg(0);
$month = func_get_arg(1);
} else {
$year = $this->date['year'];
$month = $this->date['mon'];
}
$name = date('F', mktime(0,0,0,$month,1,$year));
$weekNumber = Date::getWeekNumber($year, $month, 1);
$daysInMonth = Date::getDaysInMonth($year, $month);
$weekDay = Date::getFirstWeekDayOfMonth($year, $month) - 1;
$thisDate = getdate(time());
$thisDay = mktime(0, 0, 0, $thisDate['mon'], $thisDate['mday'], $thisDate['year']);
$thisWeek = Date::getWeekNumber($thisDate['year'], $thisDate['mon'], $thisDate['mday']);
if ($year != $thisDate['year']) {
$thisWeek = 0;
}
$rc = <<<EOT
<table class="smCalendarTable">
<tr>
<td class="smCalendarCell smCalendarMonthTitle" colspan="8" align="center">{$name} &nbsp; {$year}</td>
</tr>
<tr>
<td class="smCalendarCell smCalendarDayTitle">&nbsp;</td>
<td class="smCalendarCell smCalendarDayTitle">Mo</td>
<td class="smCalendarCell smCalendarDayTitle">Tu</td>
<td class="smCalendarCell smCalendarDayTitle">We</td>
<td class="smCalendarCell smCalendarDayTitle">Th</td>
<td class="smCalendarCell smCalendarDayTitle">Fr</td>
<td class="smCalendarCell smCalendarDayTitle">Sa</td>
<td class="smCalendarCell smCalendarDayTitle">Su</td>
</tr>
<tr>
<td class="smCalendarCell smCalendarWeekNumber" valign='top'>{$weekNumber}</td>
EOT;
if ($weekNumber == $thisWeek) {
$style = "smCalendarThisWeek";
$thisDayStyle = "smCalendarThisWeek smCalendarThisDay";
} else {
$style = $thisDayStyle = "smCalendarDay";
}
for ($i = 0; $i < $weekDay; $i++) {
$rc .= sprintf(
"\t<td class='smCalendarCell %s%s'>&nbsp;</td>\n",
$i == $thisDate['wday'] ? $thisDayStyle : $style,
$i < 5 ? "" : " smCalendarWeekend"
);
}
for ($i = 1; $i <= $daysInMonth; $i++, $weekDay = ($weekDay + 1) % 7) {
if (1 < $i && $weekDay == 0) {
$weekNumber = Date::getWeekNumber($year, $month, $i);
$week = $weekNumber < 10 ? "&nbsp;&nbsp;{$weekNumber}" : $weekNumber;
$rc .= "</tr>\n<tr>\n\t<td class='smCalendarCell smCalendarWeekNumber' valign='top'>{$week}</td>\n";
if ($weekNumber == $thisWeek) {
$style = "smCalendarThisWeek";
$thisDayStyle = "smCalendarThisWeek smCalendarThisDay";
} else {
$style = $thisDayStyle = "smCalendarDay";
}
}
$key = sprintf("%04d-02d-02d", $year, $month, $i);
$rc .= sprintf(
"\t<td class='smCalendarCell %s%s' valign='top'><span class='smCalendarNumber'>%d</span></td>\n",
$i == $thisDate['mday'] ? $thisDayStyle : $style,
$weekDay < 5 ? "" : " smCalendarWeekend", $i
);
}
for ( ; $weekDay != 0; $weekDay = ($weekDay + 1) % 7) {
$rc .= sprintf(
"\t<td class='smCalendarCell %s'>&nbsp;</td>\n",
$weekDay < 5 ? "smCalendarDay" : "smCalendarWeekend"
);
}
$rc .= "</tr>\n</table>\n";
return $rc;
}
/*
* $obj->getLargeCalendar($notes)
* Date::getLargeCalendar($notes, $year, $month)
*/
function getLargeCalendar(/* $notes [, $year, $month] */)
{
switch (func_num_args()) {
case 3:
$notes = func_get_arg(0);
$year = func_get_arg(1);
$month = func_get_arg(2);
break;
case 1:
$notes = func_get_arg(0);
$year = $this->date['year'];
$month = $this->date['mon'];
break;
default:
return '';
}
$name = date('F', mktime(0,0,0,$month,1,$year));
$weekNumber = Date::getWeekNumber($year, $month, 1);
$daysInMonth = Date::getDaysInMonth($year, $month);
$weekDay = Date::getFirstWeekDayOfMonth($year, $month) - 1;
$thisDate = getdate(time());
$thisDay = mktime(0, 0, 0, $thisDate['mon'], $thisDate['mday'], $thisDate['year']);
$thisWeek = Date::getWeekNumber($thisDate['year'], $thisDate['mon'], $thisDate['mday']);
if ($year != $thisDate['year']) {
$thisWeek = 0;
}
$rc = <<<EOT
<table class="lgCalendarTable">
<tr>
<td class="lgCalendarCell lgCalendarMonthTitle" colspan="8" align="center">{$name} &nbsp; {$year}</td>
</tr>
<tr>
<td class="lgCalendarCell lgCalendarDayTitle" width="2%">W</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">Mo</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">Tu</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">We</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">Th</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">Fr</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">Sa</td>
<td class="lgCalendarCell lgCalendarDayTitle" width="14%">Su</td>
</tr>
<tr>
<td class="lgCalendarCell lgCalendarWeekNumber" valign='top' style='padding-left: 0; padding-right: 1;'><img align='left' width='1' height='80' src='pixel.gif'>{$weekNumber}</td>
EOT;
if ($weekNumber == $thisWeek) {
$style = "lgCalendarThisWeek";
$thisDayStyle = "lgCalendarThisWeek lgCalendarThisDay";
} else {
$style = $thisDayStyle = "lgCalendarDay";
}
for ($i = 0; $i < $weekDay; $i++) {
$rc .= sprintf(
"\t<td class='lgCalendarCell %s%s'>&nbsp;</td>\n",
$i == $thisDate['wday'] ? $thisDayStyle : $style,
$i < 5 ? "" : " lgCalendarWeekend"
);
}
for ($i = 1; $i <= $daysInMonth; $i++, $weekDay = ($weekDay + 1) % 7) {
if (1 < $i && $weekDay == 0) {
$weekNumber = Date::getWeekNumber($year, $month, $i);
$week = $weekNumber < 10 ? "&nbsp;&nbsp;{$weekNumber}" : $weekNumber;
$rc .= "</tr>\n<tr>\n\t<td class='lgCalendarCell lgCalendarWeekNumber' valign='top' style='padding-left: 0; padding-right: 1;'><img align='left' width='1' height='80' src='pixel.gif'>{$week}</td>\n";
if ($weekNumber == $thisWeek) {
$style = "lgCalendarThisWeek";
$thisDayStyle = "lgCalendarThisWeek lgCalendarThisDay";
} else {
$style = $thisDayStyle = "lgCalendarDay";
}
}
$key = sprintf("%04d-%02d-%02d", $year, $month, $i);
$rc .= sprintf(
"\t<td class='lgCalendarCell %s%s' valign='top' style='text-align: left;'><span class='lgCalendarNumber'>%d&nbsp;&nbsp;</span>%s</td>\n",
$i == $thisDate['mday'] ? $thisDayStyle : $style,
$weekDay < 5 ? "" : " lgCalendarWeekend",
$i, isset($notes[$key]) ? $notes[$key] : ''
);
}
for ( ; $weekDay != 0; $weekDay = ($weekDay + 1) % 7) {
$rc .= sprintf(
"\t<td class='lgCalendarCell %s'>&nbsp;</td>\n",
$weekDay < 5 ? "lgCalendarDay" : "lgCalendarWeekend"
);
}
$rc .= "</tr>\n</table>\n";
return $rc;
}
}
?>
+106
View File
@@ -0,0 +1,106 @@
#!/usr/bin/php
<?
header("HTTP/1.0 299 OK");
header("Content-Type: text/html");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - A Calendar Generator in PHP
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
<style>
<!--
.smCalendarTable {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 9pt;
border-spacing: 0;
border-width: 1;
border-style: groove;
}
.smCalendarCell {
padding: 3;
text-align: right;
}
.smCalendarMonthTitle {
color: #ff0000;
text-align: center;
border-collapse: collapse;
border-color: #000000;
border-width: 2 0 0 0;
border-style: solid;
}
.smCalendarDayTitle {
color: #0000cc;
text-align: center;
border-collapse: collapse;
border-color: #000000;
border-width: 1 0 1 0;
border-style: solid;
}
.smCalendarWeekNumber {
color: #cc00cc;
font-weight: bold;
background-color: #eeeeee;
}
.smCalendarDay {
color: #0000cc;
}
.smCalendarWeekend {
color: #0000cc;
background-color: #cae4ff;
}
.smCalendarThisWeek {
color: #0000cc;
background-color: #ffcccc;
}
.smCalendarThisDay {
padding: 1;
border-color: #ff0000;
border-width: 2;
border-style: solid;
}
-->
</style>
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<div align="center">
<table border="0" cellspacing="0" cellpadding="5">
<h2>A Calendar Generator in PHP</h2>
<?
include('Date.php');
$date = new Date();
for ($i = 0; $i < 12; $i++) {
if ($i % 4 == 0)
print("<tr valign='top'>\n");
print("<td>");
print Date::getSmallCalendar($date->getYear(), $i+1);
print("</td>\n");
if ($i % 4 == 3)
print("</tr>\n");
}
?>
</table>
</div>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
@@ -0,0 +1,106 @@
#!@php_exe@
<?
header("HTTP/1.0 299 OK");
header("Content-Type: text/html");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - A Calendar Generator in PHP
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
<style>
<!--
.smCalendarTable {
font-family: Arial, Verdana, Helvetica, sans-serif;
font-size: 9pt;
border-spacing: 0;
border-width: 1;
border-style: groove;
}
.smCalendarCell {
padding: 3;
text-align: right;
}
.smCalendarMonthTitle {
color: #ff0000;
text-align: center;
border-collapse: collapse;
border-color: #000000;
border-width: 2 0 0 0;
border-style: solid;
}
.smCalendarDayTitle {
color: #0000cc;
text-align: center;
border-collapse: collapse;
border-color: #000000;
border-width: 1 0 1 0;
border-style: solid;
}
.smCalendarWeekNumber {
color: #cc00cc;
font-weight: bold;
background-color: #eeeeee;
}
.smCalendarDay {
color: #0000cc;
}
.smCalendarWeekend {
color: #0000cc;
background-color: #cae4ff;
}
.smCalendarThisWeek {
color: #0000cc;
background-color: #ffcccc;
}
.smCalendarThisDay {
padding: 1;
border-color: #ff0000;
border-width: 2;
border-style: solid;
}
-->
</style>
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<div align="center">
<table border="0" cellspacing="0" cellpadding="5">
<h2>A Calendar Generator in PHP</h2>
<?
include('Date.php');
$date = new Date();
for ($i = 0; $i < 12; $i++) {
if ($i % 4 == 0)
print("<tr valign='top'>\n");
print("<td>");
print Date::getSmallCalendar($date->getYear(), $i+1);
print("</td>\n");
if ($i % 4 == 3)
print("</tr>\n");
}
?>
</table>
</div>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
+15
View File
@@ -0,0 +1,15 @@
#!/usr/bin/php
<?
// Bug #27026: header('HTTP/1.0 200 OK') never sent when explicitly
// requested.
//
// Send a 2xx status code not defined by RFC 2616. A 200 value would
// be the correct value, but PHP/CGI refuses to send it when explicitly
// set.
//
// This works for Opera 7, Mozilla 1.6, and IE 6.0 SP1.
//
header("HTTP/1.0 299 OK");
phpinfo();
?>
@@ -0,0 +1,15 @@
#!@php_exe@
<?
// Bug #27026: header('HTTP/1.0 200 OK') never sent when explicitly
// requested.
//
// Send a 2xx status code not defined by RFC 2616. A 200 value would
// be the correct value, but PHP/CGI refuses to send it when explicitly
// set.
//
// This works for Opera 7, Mozilla 1.6, and IE 6.0 SP1.
//
header("HTTP/1.0 299 OK");
phpinfo();
?>
@@ -0,0 +1,70 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - Form Processing Example in PHP
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<h2>Form Processing Example in PHP</h2>
<p>This example takes the output of a form POST and reformats it from
its encoded format into human readable output suitable for sending
by email.
</p>
<form method="POST" action="sendform.php">
<table border="0" cellspacing="2" cellpadding="0">
<tr valign="top">
<td align="right" style="text-align: right;">
Who am I?
</td>
<td>
<input name="who" value="Snert" size="24">
</td>
</tr>
<tr valign="top">
<td align="right" style="text-align: right;">
What am I?
</td>
<td>
<input name="what" value="A sick puppy" size="24">
</td>
</tr>
<tr valign="top">
<td align="right" style="text-align: right;">
Where am I?
</td>
<td>
<textarea rows="4" cols="20" name="where" wrap="hard">I live in the south of France now.</textarea>
</td>
</tr>
<tr valign="top">
<td>
&nbsp;
</td>
<td>
<input type="submit" value="SEND">
</td>
</tr>
</table>
</form>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
+81
View File
@@ -0,0 +1,81 @@
#!/usr/bin/php
<?
header("HTTP/1.0 299 OK");
header("Content-Type: text/html");
///////////////////////////////////////////////////////////////////////
// CHANGE THE VALUES BELOW HERE
///////////////////////////////////////////////////////////////////////
$SEND_TO = 'achowe@snert.com';
$SUBJECT = 'From the web form...';
///////////////////////////////////////////////////////////////////////
// CHANGE THE VALUES ABOVE HERE
///////////////////////////////////////////////////////////////////////
$maxWidth = 0;
foreach ($_GET as $name => $value) {
if ($maxWidth < strlen($name))
$maxWidth = strlen($name);
}
foreach ($_POST as $name => $value) {
if ($maxWidth < strlen($name))
$maxWidth = strlen($name);
}
$body = '';
$fmt = "%{$maxWidth}s: %s\n";
foreach ($_GET as $name => $value) {
$body .= sprintf($fmt, $name, $value);
}
foreach ($_POST as $name => $value) {
$body .= sprintf($fmt, $name, $value);
}
//mail($SEND_TO, $SUBJECT, $body);
///////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - Form Processing Example in PHP
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<h2>Form Processing Example in PHP</h2>
<p>Formatted output of web form as would be seen in an email message (without decorations).
This example does not send any actual email, though it could with some minor changes.
</p>
<pre>
<?= $body; ?>
</pre>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
@@ -0,0 +1,81 @@
#!@php_exe@
<?
header("HTTP/1.0 299 OK");
header("Content-Type: text/html");
///////////////////////////////////////////////////////////////////////
// CHANGE THE VALUES BELOW HERE
///////////////////////////////////////////////////////////////////////
$SEND_TO = 'achowe@snert.com';
$SUBJECT = 'From the web form...';
///////////////////////////////////////////////////////////////////////
// CHANGE THE VALUES ABOVE HERE
///////////////////////////////////////////////////////////////////////
$maxWidth = 0;
foreach ($_GET as $name => $value) {
if ($maxWidth < strlen($name))
$maxWidth = strlen($name);
}
foreach ($_POST as $name => $value) {
if ($maxWidth < strlen($name))
$maxWidth = strlen($name);
}
$body = '';
$fmt = "%{$maxWidth}s: %s\n";
foreach ($_GET as $name => $value) {
$body .= sprintf($fmt, $name, $value);
}
foreach ($_POST as $name => $value) {
$body .= sprintf($fmt, $name, $value);
}
//mail($SEND_TO, $SUBJECT, $body);
///////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - Form Processing Example in PHP
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<h2>Form Processing Example in PHP</h2>
<p>Formatted output of web form as would be seen in an email message (without decorations).
This example does not send any actual email, though it could with some minor changes.
</p>
<pre>
<?= $body; ?>
</pre>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
@@ -0,0 +1,150 @@
#
# LUHN.rb
#
# Copyright 2000, 2004 by Anthony Howe. All rights reserved.
#
class LUHN
def LUHN.base(str, radix)
if radix < 2 then
return nil
end
num = 0
str.downcase!
str.each_byte do |byte|
i = "0123456789abcdefghijklmnopqrstuvwxyz".index(byte)
if i.nil? || radix <= i then
return nil
end
num = num * radix + i
end
return num
end
#
# Internal routine that computes the LUHN sum.
#
# The LUHN Algorithm ("mod 10 Double-Add-Double"):
#
# 1. Position from right 8 7 6 5 4 3 2 1
# ------------------------------
# Number string 4 8 9 5 1 3 1 3
# x2 even positions 2 1 2 1 2 1 2 1
# ------------------------------
# Add odd positions & 8 +8 +1+8 +5 +2 +3 +2 +3
# add digits of doubled
# positions
#
# Sum 40
#
# Number is valid if sum is a multiple of 10.
#
#
# 2. Alpha-numeric ISIN U S 3 8 3 8 8 3 1 0 5 1
# (ISO 6166) -----------------------------------------
# base 36 digits 30 28 3 8 3 8 8 3 1 0 5 1
# -----------------------------------------
# consider digit string 3 0 2 8 3 8 3 8 8 3 1 0 5 1
# & x2 even digits from 2 1 2 1 2 1 2 1 2 1 2 1 2 1
# -----------------------------------------
# 6 0 4 8 6 8 6 8 16 3 2 0 10 1
# -----------------------------------------
# sum the digits of 6 +0 +4 +8 +6 +8 +6 +8+1+6+3 +2 +0+1+0+1
#
# Sum 60
#
# Number is valid if sum is a multiple of 10.
#
def LUHN.sum(str)
if ! str.instance_of?(String) || str.length < 1 then
return nil
end
total = 0
even = false
str = str.reverse.downcase
# Working right to left...
str.each_byte do |byte|
# Convert base36 digit to a base10 value.
digit36 = base(byte.chr, 36)
if digit36.nil? then
return nil
end
# For each base10 digit of a base36 digit...
begin
digit10 = digit36 % 10
if even then
# Multiply even digits by 2.
digit10 <<= 1
# Sum digits of product.
if 10 <= digit10 then
digit10 -= 9
end
end
# Add digits of product to total.
total += digit10
# Next digit.
digit36 = (digit36 / 10).floor
# Toggle from digit to digit.
even = !even
end while 0 < digit36
end
return total
end
#
# Return true if the string of digits is valid.
# Assumes LUHN check digit is right most digit.
#
def LUHN.valid?(str)
if ! str.instance_of?(String) || str.length < 2 then
return false
end
total = sum(str)
return total.nil? ? false : (total % 10) == 0
end
#
# Return the LUHN check digit (mod 10) for the
# given string of digits; otherwise nil on error.
#
def LUHN.generate(str)
if ! str.instance_of?(String) || str.length < 1 then
return nil
end
total = sum(str + '0')
return total.nil? ? nil : (10 - (total % 10)) % 10
end
end
if $DEBUG && $0 == 'LUHN.rb' then
def generate(str, expect)
digit = LUHN.generate(str)
puts(str + "-" + digit.to_s + ' ' + (digit == expect).to_s)
end
def validate(str)
puts(str + ' ' + LUHN.valid?(str).to_s)
end
generate('1', 8)
generate('12', 5)
generate('123', 0)
generate('A', 9)
generate('AB', 6)
validate('AB6')
end
+80
View File
@@ -0,0 +1,80 @@
#!/usr/bin/ruby
require 'cgi'
require ENV['DOCUMENT_ROOT'] + '/test/ruby/LUHN'
if ENV['QUERY_STRING'].nil? then
answer = ''
numebr = ''
else
query = CGI.parse(ENV['QUERY_STRING'])
number = query['number'].to_s
case query['action'].to_s
when 'Validate'
is_valid = LUHN.valid?(number)
answer = number
when 'Generate'
digit = LUHN.generate(number)
answer = "#{number}" + digit.to_s
is_valid = ! digit.nil?
end
end
puts <<"EOT"
HTTP/1.0 200 OK
Content-Type: text/html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - Playing with LUHN checksums in Ruby
</title>
</head>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="500">
<tr>
<td>
<h2>Playing with LUHN checksums in Ruby<br/>"mod 10 Double-Add-Double"</h2>
<p>Enter an alpha-numeric string like a credit card number or International Securities Identification Number (ISO 6166).
Click validate to test if the entered string is correct. Click generate to append the check digit to the string.
</p>
<form name="luhn" method="GET" action="index.rb">
<textarea name="number" wrap="virtual" rows="2" cols="30">#{answer}</textarea>
<br/><b>#{ is_valid ? "Is valid." : "Is NOT valid." }</b>
<br/>
<br/>
<input type="submit" name="action" value="Validate">
&nbsp;&nbsp;
<input type="submit" name="action" value="Generate">
&nbsp;&nbsp;
<input type="button" value="Clear" onclick="this.form.number.value = ''">
</form>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
EOT
exit(0)
@@ -0,0 +1,80 @@
#!@ruby_exe@
require 'cgi'
require ENV['DOCUMENT_ROOT'] + '/test/ruby/LUHN'
if ENV['QUERY_STRING'].nil? then
answer = ''
numebr = ''
else
query = CGI.parse(ENV['QUERY_STRING'])
number = query['number'].to_s
case query['action'].to_s
when 'Validate'
is_valid = LUHN.valid?(number)
answer = number
when 'Generate'
digit = LUHN.generate(number)
answer = "#{number}" + digit.to_s
is_valid = ! digit.nil?
end
end
puts <<"EOT"
HTTP/1.0 200 OK
Content-Type: text/html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi - Playing with LUHN checksums in Ruby
</title>
</head>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td>
<table border="0" cellpadding="0" cellspacing="0" width="500">
<tr>
<td>
<h2>Playing with LUHN checksums in Ruby<br/>"mod 10 Double-Add-Double"</h2>
<p>Enter an alpha-numeric string like a credit card number or International Securities Identification Number (ISO 6166).
Click validate to test if the entered string is correct. Click generate to append the check digit to the string.
</p>
<form name="luhn" method="GET" action="index.rb">
<textarea name="number" wrap="virtual" rows="2" cols="30">#{answer}</textarea>
<br/><b>#{ is_valid ? "Is valid." : "Is NOT valid." }</b>
<br/>
<br/>
<input type="submit" name="action" value="Validate">
&nbsp;&nbsp;
<input type="submit" name="action" value="Generate">
&nbsp;&nbsp;
<input type="button" value="Clear" onclick="this.form.number.value = ''">
</form>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
EOT
exit(0)
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
cat <<'EOT'
<table border="1" cellspacing="0" cellpadding="0">
<caption><h3>Environment Variables</h3></caption>
EOT
env | sed -e 's/^\(.[^\=]*\)=\(.*\)$/<tr><td class="normal">\1<\/td><td class="normal">\2\&nbsp;<\/td><\/tr>/'
echo "</table>"
if [ "$REQUEST_METHOD" = "POST" -a X"$CONTENT_LENGTH" != X ]; then
STUFF=`dd bs=1 count=$CONTENT_LENGTH 2>/dev/null`
COUNT=`printf $STUFF | wc -c`
cat <<EOT
<table border="1" cellspacing="0" cellpadding="0">
<caption><h3>Standard Input</h3></caption>
<tr><td class="normal"><pre>Length: $COUNT</pre></td></tr>
<tr><td class="normal"><pre>$STUFF</pre></td></tr>
</table>
EOT
if [ $CONTENT_LENGTH -eq $COUNT ]; then
echo "[ OK ] CONTENT_LENGTH = bytes read"
else
echo "[ BAD ] CONTENT_LENGTH != bytes read"
fi
fi
+108
View File
@@ -0,0 +1,108 @@
#!/bin/sh
cat <<'-EOT-'
HTTP/1.0 200 OK
Content-Type: text/html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi/1.0 Shell Test 0 - Display Enviroment
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td class="normal">
<div align="center">
<h3>Results from Simple GET request</h3>
<table border="0" cellspacing="0" cellpadding="0">
<caption><h3>Assertions</h3></caption>
-EOT-
if [ X"$PATH" = X'/usr/local/bin:/usr/bin:/bin' ]; then
echo "<tr><td>[ OK ] PATH</td></tr>"
else
echo "<tr><td>[ BAD ] PATH</td></tr>"
fi
if [ X"$ENV" = X ]; then
echo "<tr><td>[ OK ] ENV</td></tr>"
else
echo "<tr><td>[ BAD ] ENV</td></tr>"
fi
if [ X"$CDPATH" = X ]; then
echo "<tr><td>[ OK ] CDPATH</td></tr>"
else
echo "<tr><td>[ BAD ] CDPATH</td></tr>"
fi
if [ X"$REQUEST_METHOD" = X'GET' ]; then
echo "<tr><td>[ OK ] REQUEST_METHOD</td></tr>"
else
echo "<tr><td>[ BAD ] REQUEST_METHOD</td></tr>"
fi
if [ X"$DOCUMENT_ROOT" != X ]; then
echo "<tr><td>[ OK ] DOCUMENT_ROOT</td></tr>"
else
echo "<tr><td>[ BAD ] DOCUMENT_ROOT</td></tr>"
fi
# Test for existance only, since the location changes.
if [ X"$SCRIPT_FILENAME" = X ]; then
echo "<tr><td>[ BAD ] SCRIPT_FILENAME</td></tr>"
else
echo "<tr><td>[ OK ] SCRIPT_FILENAME</td></tr>"
fi
# Test for existance only, since the default value might change.
if [ X"$SERVER_PORT" = X ]; then
echo "<tr><td>[ BAD ] SERVER_PORT</td></tr>"
else
echo "<tr><td>[ OK ] SERVER_PORT</td></tr>"
fi
if [ X"$SERVER_SOFTWARE" = X'hibachi/1.0' ]; then
echo "<tr><td>[ OK ] SERVER_SOFTWARE</td></tr>"
else
echo "<tr><td>[ BAD ] SERVER_SOFTWARE</td></tr>"
fi
if [ X"$GATEWAY_INTERFACE" = X'CGI/0.0' ]; then
echo "<tr><td>[ OK ] GATEWAY_INTERFACE</td></tr>"
else
echo "<tr><td>[ BAD ] GATEWAY_INTERFACE</td></tr>"
fi
echo "</table>"
. "$DOCUMENT_ROOT/test/shell/dump.sh"
cat <<'-EOT-'
<br>
<form method="GET" action="test1.sh">
<b>Next Test: <input type="submit" name="example" value="GET REQUEST WITH QUERY-STRING">
<input type="hidden" name="garibaldi" value="peek-a-boo"></b>
</form>
</div>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
-EOT-
exit 0
+84
View File
@@ -0,0 +1,84 @@
#!/bin/sh
cat <<'-EOT-'
HTTP/1.0 200 OK
Content-Type: text/html
Set-Cookie: cookie1=test1.sh; path=/
Set-Cookie: cookie2=test1.sh; path=/
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi/1.0 Shell Test 1
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td class="normal">
<div align="center">
<h2>Results of Form GET request</h2>
<table border="0" cellspacing="0" cellpadding="0">
<caption><h3>Assertions</h3></caption>
-EOT-
if [ X"$PATH" = X'/usr/local/bin:/usr/bin:/bin' ]; then
echo "<tr><td>[ OK ] PATH</td></tr>"
else
echo "<tr><td>[ BAD ] PATH</td></tr>"
fi
if [ X"$ENV" = X ]; then
echo "<tr><td>[ OK ] ENV</td></tr>"
else
echo "<tr><td>[ BAD ] ENV</td></tr>"
fi
if [ X"$CDPATH" = X ]; then
echo "<tr><td>[ OK ] CDPATH</td></tr>"
else
echo "<tr><td>[ BAD ] CDPATH</td></tr>"
fi
if [ X"$REQUEST_METHOD" = X'GET' ]; then
echo "<tr><td>[ OK ] REQUEST_METHOD</td></tr>"
else
echo "<tr><td>[ BAD ] REQUEST_METHOD</td></tr>"
fi
if [ X"$QUERY_STRING" = X'example=GET+REQUEST+WITH+QUERY-STRING&garibaldi=peek-a-boo' ]; then
echo "<tr><td>[ OK ] QUERY_STRING</td></tr>"
else
echo "<tr><td>[ BAD ] QUERY_STRING</td></tr>"
fi
echo "</table>"
. "$DOCUMENT_ROOT/test/shell/dump.sh"
cat <<'-EOT-'
<br>
<form method="POST" action="test2.sh">
<b>Next Test:</b> <input type="submit" name="example" value="POST REQUEST WITH COOKIES">
<input type="hidden" name="hibachi" value="is not Apache">
<input type="hidden" name="garibaldi" value="peek-a-boo">
</form>
</div>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
-EOT-
exit 0
+83
View File
@@ -0,0 +1,83 @@
#!/bin/sh
cat <<'-EOT-'
HTTP/1.0 200 OK
Content-Type: text/html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>
Hibachi/1.0 Shell Test 2
</title>
<link rel="stylesheet" type="text/css" href="../../style.css">
</head>
<body background="../../Img/hot-coal-edge-110-indent.png" style="margins: 0 0 0 0; padding: 0 0 0 0;">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130">
<img alt="" src="../../Img/mrpixel.gif" width="130" height="1">
</td>
<td class="normal">
<div align="center">
<h2>Results of Form POST request</h2>
<table border="0" cellspacing="0" cellpadding="0">
<caption><h3>Assertions</h3></caption>
-EOT-
if [ X"$PATH" = X'/usr/local/bin:/usr/bin:/bin' ]; then
echo "<tr><td>[ OK ] PATH</td></tr>"
else
echo "<tr><td>[ BAD ] PATH</td></tr>"
fi
if [ X"$ENV" = X ]; then
echo "<tr><td>[ OK ] ENV</td></tr>"
else
echo "<tr><td>[ BAD ] ENV</td></tr>"
fi
if [ X"$CDPATH" = X ]; then
echo "<tr><td>[ OK ] CDPATH</td></tr>"
else
echo "<tr><td>[ BAD ] CDPATH</td></tr>"
fi
if [ X"$REQUEST_METHOD" = X'POST' ]; then
echo "<tr><td>[ OK ] REQUEST_METHOD</td></tr>"
else
echo "<tr><td>[ BAD ] REQUEST_METHOD</td></tr>"
fi
if [ X"$QUERY_STRING" = X ]; then
echo "<tr><td>[ OK ] QUERY_STRING</td></tr>"
else
echo "<tr><td>[ BAD ] QUERY_STRING</td></tr>"
fi
if [ X"$HTTP_COOKIE" = X'cookie1=test1.sh; cookie2=test1.sh' -o X"$HTTP_COOKIE" = X'cookie2=test1.sh; cookie1=test1.sh' ]; then
echo "<tr><td>[ OK ] HTTP_COOKIE</td></tr>"
else
echo "<tr><td>[ BAD ] HTTP_COOKIE</td></tr>"
fi
echo "</table>"
. "$DOCUMENT_ROOT/test/shell/dump.sh"
cat <<'-EOT-'
</div>
<hr>
<a href="../../#Test">Return to HIBACHI</a>
</td>
</tr>
</table>
</body>
</html>
-EOT-
exit 0
+57
View File
@@ -0,0 +1,57 @@
#
# @package_copyright@
#
# @configure_input@
#
.POSIX :
########################################################################
### Pick one that best suits your system.
########################################################################
prefix = @prefix@
exec_prefix = @exec_prefix@
PACKAGE = @PACKAGE_NAME@
VERSION = @PACKAGE_VERSION@
TARNAME = @PACKAGE_TARNAME@
TARDIR = ../
SRCDIR = ./
CC = @CC@
CC_E = @CC_E@
CC_O = @CC_O@
CFLAGS = @CFLAGS@
LDFLAGS = @LDFLAGS@
LIBS = @LIBS@
########################################################################
### No further configuration beyond this point.
########################################################################
.SUFFIXES :
O = .@OBJEXT@
E = @EXEEXT@
.SUFFIXES : .c $O
all: build
build : @PACKAGE_NAME@$E
clean :
-rm -f *.o *.obj *.i *.map *.tds *.TR2 *.ilc *.ild *.ilf *.ils *.log
-rm @PACKAGE_NAME@$E
distclean: clean
-rm -rf autom4te.cache config.status config.log
-rm -f @PACKAGE_NAME@-start.sh makefile
-rm -f localhost/test/perl/yahoo-ticker.pl
-rm -f localhost/test/php/index.php
-rm -f localhost/test/php/info.php
-rm -f localhost/test/php/sendform.php
-rm -f localhost/test/ruby/index.rb
@PACKAGE_NAME@$E: @PACKAGE_NAME@.c
$(CC) $(CFLAGS) $(LDFLAGS) $(CC_E) @PACKAGE_NAME@$E @PACKAGE_NAME@.c $(LIBS)