File: pcal.cgi

package info (click to toggle)
pcal 4.7-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 688 kB
  • ctags: 949
  • sloc: ansic: 6,800; csh: 245; makefile: 136; sh: 57
file content (113 lines) | stat: -rwxr-xr-x 3,625 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh
#
# Bourne shell script to decode QUERY_STRING (as set up by pcal.html or
# pcalw.html) and run 'pcal' with selected options; must be installed
# with execute permission for all
#
# expects QUERY_STRING to contain one or more of the following variables:
#
#	datefile	"-e" (empty calendar) or null (use default file)
#	dflag		optional "-D<sym>" flag to be passed to pcal (<sym>
#				should not contain any special characters)
#	dstyle		default day style ("-[bgGO]" or null)
#	font		font name (can be null)
#	hstyle		holiday style ("-[bgGO]" or null)
#	jdates		Julian dates ("-[jJ]" or null)
#	lang		language ("-a<lang>" or null)
#	mode		landscape/portrait mode ("-[lp]" or null)
#	month		starting month (1-12; use current month if null)
#	nmonths		number of months (1-99; use 1 if null)
#	smcal		small calendar position ("-[kKS]" or null)
#	wflag		"-w" or null ("-w" overrides 'month' and 'nmonths')
#	wstyle		weekend (Sat/Sun) style ("-[bgGO]" or null)
#	year		two- or four-digit year; use current year if null
#

# N.B.: edit these to point to the location of the pcal executable and
# common calendar file on your system (note that the user can't use his/her
# own calendar file since most servers will execute pcal.cgi as 'nobody')

pcal=/yourpath/pcal
file=/yourpath/calendar

# set DEBUG=1 to echo debugging output as HTML text
DEBUG=0

datefile=; dflag=; dstyle=; font=; hstyle=; jdates=; lang=;	# defaults
mode=; month=; moons=; nmonths=; smcal=; wflag=; wstyle=; year=;

# convert QUERY_STRING from HTML-supplied "var1=val1&var2=val2..." to /bin/sh
# "var1=val1;var2=val2..." commands; 'eval' result to set local variables
# (note that 'eval' is vulnerable to attacks from clever hackers who could
# sneak other shell commands into the request string; you may want to replace
# this with any of several more robust parsing scripts publicly available)

set -f						# disable file name expansion
eval `echo $QUERY_STRING | sed -e 's/&/;/g'`

# fill in default values as needed

if [ "$month" = "" ] ; then
  month=`date +%m`		# use current month
fi

case "$year" in
  [1-9][0-9][0-9][0-9])		# valid 4-digit year
    ;;
  [0-9][0-9])			# valid 2-digit year (pcal supplies century)
    ;;
  *)				# null or invalid - use current year
    year=`date +%y`
    ;;
esac

case "$nmonths" in
  [0-9][0-9])			# valid 2-digit number
    ;;
  [0-9])			# valid 1-digit number
    ;;
  *)				# null or invalid - print single month
    nmonths=1
    ;;
esac

# additional tweaks as required by certain flags

if [ "$wflag" = "-w" ] ; then	# whole-year mode: override month and nmonths
  month=; nmonths=;
fi

if [ "$datefile" = "" ] ; then	# use path to calendar file
  datefile="-f $file"
fi

if [ "$dstyle" != "" ] ; then	# append 'all' to -[bgGO] flag (default)
  dstyle=$dstyle"all"
fi

if [ "$hstyle" != "" ] ; then	# append 'hol' to -[bgGO] flag (holidays)
  hstyle=$hstyle"hol"
fi

if [ "$wstyle" != "" ] ; then	# append 'sat-sun' to -[bgGO] flag (weekends)
  wstyle=$wstyle"sat-sun"
fi

# write header describing content as PostScript; run pcal (sending output
# to stdout)

if [ $DEBUG -eq 0 ] ; then
  echo "Content-type: application/PostScript"
  echo ""
  $pcal $mode $dflag -d$font -t$font $wstyle $dstyle $hstyle $moons \
	$jdates $datefile $lang $smcal $wflag $month $year $nmonths
else
  echo "Content-type: text/html"	# write debugging output as HTML
  echo ""
  echo "<title>pcal debugging information</title>"
  echo "<p>QUERY_STRING = "$QUERY_STRING"</p>"
  echo $pcal $mode $dflag -d$font -t$font $wstyle $dstyle $hstyle $moons \
	$jdates $datefile $lang $smcal $wflag $month $year $nmonths
fi

exit 0