Skip to content

Commit

Permalink
Properly escape json in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
Flole998 committed Apr 25, 2024
1 parent aaccc14 commit aba5e60
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions debian/tvheadend.postinst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ HTS_USER="hts"
. /usr/share/debconf/confmodule
db_version 2.0

escape_json_string() {
LANG=C command -p awk '
BEGIN {
ORS = ""
for ( i = 1; i <= 127; i++ )
tr[ sprintf( "%c", i) ] = sprintf( "\\u%04x", i )
for ( i = 1; i < ARGC; i++ ) {
s = ARGV[i]
print "\""
while ( match( s, /[\001-\037\177"\\]/ ) ) {
print substr(s,1,RSTART-1) tr[ substr(s,RSTART,RLENGTH) ]
s = substr(s,RSTART+RLENGTH)
}
print s "\"\n"
}
}
' "$@"
}

case "$1" in
configure)
if ! getent passwd "$HTS_USER" >/dev/null; then
Expand Down Expand Up @@ -36,11 +57,15 @@ configure)
echo >>"$HTS_SUPERUSERCONF" "{"

if db_get tvheadend/admin_username; then
echo >>"$HTS_SUPERUSERCONF" "\"username\": \"$RET\","
JSONUSER=`escape_json_string $RET`
echo "\"username\": $JSONUSER,"
JSONUSER=""
fi

if db_get tvheadend/admin_password; then
echo >>"$HTS_SUPERUSERCONF" "\"password\": \"$RET\""
JSONPASS=`escape_json_string $RET`
echo "\"password\": $JSONPASS"
JSONPASS=""
fi

echo >>"$HTS_SUPERUSERCONF" "}"
Expand Down

0 comments on commit aba5e60

Please sign in to comment.