Check-in [e1204b6194]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Merge fixes from develop.
Timelines: family | ancestors | trunk | v0.4
Files: files | file ages | folders
SHA1:e1204b61944a5c7489b0404b30dda7d5886542fa
User & Date: tux 2014-09-15 10:38:44
Context
2014-09-15
10:38
Merge fixes from develop. Leaf check-in: e1204b6194 user: tux tags: trunk, v0.4
10:38
index.cgi: Add sanitization function to functions. index.cgi: Add comments. Leaf check-in: c74a7b455a user: tux tags: develop
10:14
Hotfix: Enable database sanitization. check-in: e4bc46f550 user: tux tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to index.cgi.

19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34



35
36
37
38
39
40
41
...
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
...
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
...
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
script_url="http://${HTTP_HOST%:*}:8082"
script_lastid=$(sqlite3 .repo.fossil "SELECT MAX(rid) FROM blob;")
script_rev=$(sqlite3 .repo.fossil "SELECT uuid FROM blob WHERE rid == $script_lastid;")

STYLE="default"
DEBUG=yes

sanitize() {
	sed -e 's|\&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|"|\&quot;|g'
}

# ====
# Functions
# ====

[ ! -f "$db" ] && cat schema | sqlite3 $db




html_tmpl() {
	tmpl="$1"
	if [[ -f "${styles}/${STYLE}/${tmpl}.cgi" ]]; then
		. ${styles}/${STYLE}/${tmpl}.cgi
	fi
}
................................................................................
case " $(POST) " in
	*\ save\ *)
		if [ "$(POST save)" == "category" ]; then
			# We're just creating a new category, let's get it over with quick
			category="$(POST category)"
			sql="INSERT INTO categories VALUES( NULL, \"$category\");"
			redir="Location: ${script}?category"
			exit 0
		elif [ "$(POST save)" == "member" ]; then
			name="$(POST name | sanitize)"
			phone="$(POST phone | sanitize)"
			email="$(POST email | sanitize)"
			memid="$(POST memid)"
			if [ "$memid" == "NULL" ]; then
				# We're adding a new member
................................................................................
				sql="INSERT INTO members VALUES( NULL, \"$name\", \"$phone\", \"$email\");"
				redir="Location: ${script}?member"
			else
				# We're updating an existing member
				sql="UPDATE members SET name=\"$name\", phone=\"$phone\", email=\"$email\" WHERE id == $memid"
				redir="Location: ${script}?member&id=$memid"
			fi
			exit 0
		elif [ "$(POST save)" == "project" ]; then
			title="$(POST title | sanitize)"
			desc="$(POST desc | sanitize)"
			p="$(POST p)"
			producer="$(POST producer)"
			editor="$(POST editor)"
			category=$(POST category)
................................................................................
			if [ -z "$p" ]; then
				# We're creating a new project
				[ -z "$p" ] && p=NULL
				sql="INSERT INTO projects VALUES ( $p, \"$title\", \"$desc\", $producer, $editor, $category, \"$music\", \"$created\", \"$exp_done\", \"$exp_length\", \"$real_length\", \"$release\", \"$participants\" );"
				realp=$(sqlite3 $db "SELECT MAX(id) FROM projects")
				realp=$(($realp + 1 ))
				redir="Location: ${script}?view&p=$realp"
				exit 0
			elif [ -z "$(sqlite3 $db 'SELECT id FROM projects WHERE id == '$p)" ]; then
				# We're creating a new project with id $p
				sql="INSERT INTO projects VALUES ( $p, \"$title\", \"$desc\", $producer, $editor, $category, \"$music\", \"$created\", \"$exp_done\", \"$exp_length\", \"$real_length\", \"$release\", \"$participants\" );"
				redir="Location: ${script}?view&p=$p"
				exit 0
			else
				# We're updating an existing project
				sql="UPDATE projects SET title = \"$title\", desc = \"$desc\", producer = $producer, editor = $editor, category = $category, music = \"$music\", created = \"$created\", expected_done = \"$exp_done\", expected_length = \"$exp_length\", real_length = \"$real_length\", release = \"$release\", participants = \"$participants\" WHERE id == $p;"
				redir="Location: ${script}?view&p=$p"
				exit 0
			fi
			exit 0
		else
			header "Location: $HTTP_REFERER"
			exit 0
		fi
		sqlite3 $db "$sql"
		local err=$?
		if [ "$err" == "0" ]; then







|
|
<





|
>
>
>







 







<







 







<







 







<




<




<

<







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
...
113
114
115
116
117
118
119

120
121
122
123
124
125
126
...
127
128
129
130
131
132
133

134
135
136
137
138
139
140
...
148
149
150
151
152
153
154

155
156
157
158

159
160
161
162

163

164
165
166
167
168
169
170
script_url="http://${HTTP_HOST%:*}:8082"
script_lastid=$(sqlite3 .repo.fossil "SELECT MAX(rid) FROM blob;")
script_rev=$(sqlite3 .repo.fossil "SELECT uuid FROM blob WHERE rid == $script_lastid;")

STYLE="default"
DEBUG=yes

# Ensure database exists.
[ ! -f "$db" ] && cat schema | sqlite3 $db


# ====
# Functions
# ====

# Ensure that problematic inserts doesn't exist.
sanitize() {
	sed -e 's|\&|\&amp;|g; s|<|\&lt;|g; s|>|\&gt;|g; s|\"|\&quot;|g'
}

html_tmpl() {
	tmpl="$1"
	if [[ -f "${styles}/${STYLE}/${tmpl}.cgi" ]]; then
		. ${styles}/${STYLE}/${tmpl}.cgi
	fi
}
................................................................................
case " $(POST) " in
	*\ save\ *)
		if [ "$(POST save)" == "category" ]; then
			# We're just creating a new category, let's get it over with quick
			category="$(POST category)"
			sql="INSERT INTO categories VALUES( NULL, \"$category\");"
			redir="Location: ${script}?category"

		elif [ "$(POST save)" == "member" ]; then
			name="$(POST name | sanitize)"
			phone="$(POST phone | sanitize)"
			email="$(POST email | sanitize)"
			memid="$(POST memid)"
			if [ "$memid" == "NULL" ]; then
				# We're adding a new member
................................................................................
				sql="INSERT INTO members VALUES( NULL, \"$name\", \"$phone\", \"$email\");"
				redir="Location: ${script}?member"
			else
				# We're updating an existing member
				sql="UPDATE members SET name=\"$name\", phone=\"$phone\", email=\"$email\" WHERE id == $memid"
				redir="Location: ${script}?member&id=$memid"
			fi

		elif [ "$(POST save)" == "project" ]; then
			title="$(POST title | sanitize)"
			desc="$(POST desc | sanitize)"
			p="$(POST p)"
			producer="$(POST producer)"
			editor="$(POST editor)"
			category=$(POST category)
................................................................................
			if [ -z "$p" ]; then
				# We're creating a new project
				[ -z "$p" ] && p=NULL
				sql="INSERT INTO projects VALUES ( $p, \"$title\", \"$desc\", $producer, $editor, $category, \"$music\", \"$created\", \"$exp_done\", \"$exp_length\", \"$real_length\", \"$release\", \"$participants\" );"
				realp=$(sqlite3 $db "SELECT MAX(id) FROM projects")
				realp=$(($realp + 1 ))
				redir="Location: ${script}?view&p=$realp"

			elif [ -z "$(sqlite3 $db 'SELECT id FROM projects WHERE id == '$p)" ]; then
				# We're creating a new project with id $p
				sql="INSERT INTO projects VALUES ( $p, \"$title\", \"$desc\", $producer, $editor, $category, \"$music\", \"$created\", \"$exp_done\", \"$exp_length\", \"$real_length\", \"$release\", \"$participants\" );"
				redir="Location: ${script}?view&p=$p"

			else
				# We're updating an existing project
				sql="UPDATE projects SET title = \"$title\", desc = \"$desc\", producer = $producer, editor = $editor, category = $category, music = \"$music\", created = \"$created\", expected_done = \"$exp_done\", expected_length = \"$exp_length\", real_length = \"$real_length\", release = \"$release\", participants = \"$participants\" WHERE id == $p;"
				redir="Location: ${script}?view&p=$p"

			fi

		else
			header "Location: $HTTP_REFERER"
			exit 0
		fi
		sqlite3 $db "$sql"
		local err=$?
		if [ "$err" == "0" ]; then