Check-in [e4bc46f550]
Not logged in

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

Overview
Comment:Hotfix: Enable database sanitization.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:e4bc46f5503e4b972edae2984f6006fd14bc0958
User & Date: tux 2014-09-15 10:14:20
Context
2014-09-15
10:38
Merge fixes from develop. Leaf check-in: e1204b6194 user: tux tags: trunk, v0.4
10:15
Merge hotfix back to develop. check-in: 6bbe724313 user: tux tags: develop
10:14
Hotfix: Enable database sanitization. check-in: e4bc46f550 user: tux tags: trunk
2014-09-14
20:05
Merge changes from develop. check-in: 2072520a1c user: tux tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to index.cgi.

18
19
20
21
22
23
24




25
26
27
28
29
30
31
...
107
108
109
110
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
141
142
143
144
145
146
147
148

149
150
151
152

153
154
155
156

157

158
159
160
161
162
163
164
#script_url="https://chiselapp.com/user/mastersrp/repository/mltv-db"
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





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

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

................................................................................
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)"
			phone="$(POST phone)"
			email="$(POST email)"
			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)"
			desc="$(POST desc)"
			p="$(POST p)"
			producer="$(POST producer)"
			editor="$(POST editor)"
			category=$(POST category)
			music="$(POST music)"
			created="$(POST created)"
			exp_done="$(POST exp_done)"
			exp_length="$(POST exp_length)"
			real_length="$(POST real_length)"
			release="$(POST release)"
			participants="$(POST participants)"
			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







>
>
>
>







 







>

|
|
|










>

|
|




|
|
|
|
|
|
|







>




>




>

>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
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
141
142
143
144
145
146
147
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="https://chiselapp.com/user/mastersrp/repository/mltv-db"
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

................................................................................
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)
			music="$(POST music | sanitize)"
			created="$(POST created | sanitize)"
			exp_done="$(POST exp_done | sanitize)"
			exp_length="$(POST exp_length | sanitize)"
			real_length="$(POST real_length | sanitize)"
			release="$(POST release | sanitize)"
			participants="$(POST participants | sanitize)"
			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