Skip to content

Commit aa24968

Browse files
committed
Fixes proposed after review
1 parent 51f1647 commit aa24968

File tree

3 files changed

+41
-67
lines changed

3 files changed

+41
-67
lines changed

spk/ffsync/src/service-setup.sh

+27-16
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ service_postinst ()
6060

6161

6262
if [ "${SYNOPKG_PKG_STATUS}" = "INSTALL" ]; then
63+
# Generate database password for database user
64+
DBPASS=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9!#$%^&*()_+{}<>?=' | fold -w 10 | grep -E '[a-z]' | grep -E '[A-Z]' | grep -E '[0-9]' | grep -E '[!#$%^&*()_+{}<>?=]' | head -n 1)
6365

6466
echo ${separator}
6567
echo "Set up the databases"
6668
# login as root sql user using whatever creds you set up for that
6769
# this sets up a user for sync storage and sets up the databases
6870
${MYSQL} -u root -p"${wizard_mysql_password_root}" <<EOF
69-
CREATE USER "${DBUSER}"@"localhost" IDENTIFIED BY "${wizard_password_ffsync}";
71+
CREATE USER "${DBUSER}"@"localhost" IDENTIFIED BY "${DBPASS}";
7072
CREATE DATABASE syncstorage_rs;
7173
CREATE DATABASE tokenserver_rs;
7274
GRANT ALL PRIVILEGES on syncstorage_rs.* to ${DBUSER}@localhost;
@@ -77,23 +79,23 @@ EOF
7779
echo "Run database migrations"
7880

7981
echo "Run migrations for syncstorage_rs"
80-
${DIESEL} --database-url "mysql://${DBUSER}:${wizard_password_ffsync}@${DBSERVER}/syncstorage_rs" \
82+
${DIESEL} --database-url "mysql://${DBUSER}:${DBPASS}@${DBSERVER}/syncstorage_rs" \
8183
migration --migration-dir ${SYNOPKG_PKGDEST}/syncstorage-mysql/migrations run
8284

8385
echo "Run migrations for tokenserver_rs"
84-
${DIESEL} --database-url "mysql://${DBUSER}:${wizard_password_ffsync}@${DBSERVER}/tokenserver_rs" \
86+
${DIESEL} --database-url "mysql://${DBUSER}:${DBPASS}@${DBSERVER}/tokenserver_rs" \
8587
migration --migration-dir ${SYNOPKG_PKGDEST}/tokenserver-db/migrations run
8688

8789
echo ${separator}
8890
echo "Add sync endpoint to database"
89-
${MYSQL} -u ${DBUSER} -p"${wizard_password_ffsync}" <<EOF
91+
${MYSQL} -u ${DBUSER} -p"${DBPASS}" <<EOF
9092
USE tokenserver_rs
9193
INSERT INTO services (id, service, pattern) VALUES
9294
(1, "sync-1.5", "{node}/1.5/{uid}");
9395
EOF
9496

9597
echo "Add syncserver node"
96-
${MYSQL} -u ${DBUSER} -p"${wizard_password_ffsync}" <<EOF
98+
${MYSQL} -u ${DBUSER} -p"${DBPASS}" <<EOF
9799
USE tokenserver_rs
98100
INSERT INTO nodes (id, service, node, available, current_load, capacity, downed, backoff) VALUES
99101
(1, 1, "${wizard_ffsync_public_url}", 1, 0, 4, 0, 0);
@@ -105,14 +107,11 @@ EOF
105107
MASTER_SECRET="$(cat /dev/urandom | base64 | head -c64)"
106108
METRICS_HASH_SECRET="$(cat /dev/urandom | base64 | head -c64)"
107109

108-
# Escape vertical bars in the replacement values
109-
WIZARD_PASSWORD=$(echo "${wizard_password_ffsync}" | sed 's/|/\\|/g')
110-
111110
# Perform replacements using sed with | as the delimiter
112111
sed -e "s|{{MASTER_SECRET}}|${MASTER_SECRET}|g" \
113112
-e "s|{{TCP_PORT}}|${SERVICE_PORT}|g" \
114113
-e "s|{{SQL_USER}}|${DBUSER}|g" \
115-
-e "s|{{SQL_PASS}}|${WIZARD_PASSWORD}|g" \
114+
-e "s|{{SQL_PASS}}|${DBPASS}|g" \
116115
-e "s|{{DB_SERVER}}|${DBSERVER}|g" \
117116
-e "s|{{METRICS_HASH_SECRET}}|${METRICS_HASH_SECRET}|g" \
118117
-i "${CFG_FILE}"
@@ -126,23 +125,35 @@ validate_preuninst ()
126125
echo "Incorrect MySQL root password"
127126
exit 1
128127
fi
129-
# Check database export location
128+
# Check if database export path is specified
130129
if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ] && [ -n "${wizard_dbexport_path}" ]; then
131-
if [ -f "${wizard_dbexport_path}" ] || [ -e "${wizard_dbexport_path}/${DBUSER}.sql" ]; then
132-
echo "File ${wizard_dbexport_path}/${DBUSER}.sql already exists. Please remove or choose a different location"
130+
if [ ! -d "${wizard_dbexport_path}" ]; then
131+
# If the export path directory does not exist, create it
132+
mkdir -p "${wizard_dbexport_path}" || {
133+
# If mkdir fails, print an error message and exit
134+
echo "Error: Unable to create directory ${wizard_dbexport_path}. Check permissions."
135+
exit 1
136+
}
137+
elif [ ! -w "${wizard_dbexport_path}" ]; then
138+
# If the export path directory is not writable, print an error message and exit
139+
echo "Error: Unable to write to directory ${wizard_dbexport_path}. Check permissions."
133140
exit 1
134141
fi
142+
if [ -e "$wizard_dbexport_path/syncstorage_rs.sql" ] || [ -e "$wizard_dbexport_path/tokenserver_rs.sql" ]; then
143+
# If either syncstorage_rs.sql or tokenserver_rs.sql already exists, print an error message and exit
144+
echo "File syncstorage_rs.sql or tokenserver_rs.sql already exists in ${wizard_dbexport_path}. Please remove or choose a different location"
145+
exit 1
146+
fi
147+
# If everything is okay, perform database dumps
148+
${MYSQLDUMP} -u root -p"${wizard_mysql_password_root}" syncstorage_rs > "${wizard_dbexport_path}/syncstorage_rs.sql"
149+
${MYSQLDUMP} -u root -p"${wizard_mysql_password_root}" tokenserver_rs > "${wizard_dbexport_path}/tokenserver_rs.sql"
135150
fi
136151
}
137152

138153
service_postuninst ()
139154
{
140155
# Export and remove database
141156
if [ "${SYNOPKG_PKG_STATUS}" = "UNINSTALL" ]; then
142-
if [ -n "${wizard_dbexport_path}" ]; then
143-
mkdir -p ${wizard_dbexport_path}
144-
${MYSQLDUMP} -u root -p"${wizard_mysql_password_root}" ${DBUSER} > ${wizard_dbexport_path}/${DBUSER}.sql
145-
fi
146157
${MYSQL} -u root -p"${wizard_mysql_password_root}" -e "DROP DATABASE syncstorage_rs; DROP DATABASE tokenserver_rs; DROP USER '${DBUSER}'@'localhost';"
147158
fi
148159
}

spk/ffsync/src/wizard/install_uifile.sh

+2-37
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,6 @@ page_append ()
1616
fi
1717
}
1818

19-
getRootPasswordValidator()
20-
{
21-
validator=$(/bin/cat<<EOF
22-
{
23-
var password = arguments[0];
24-
return -1 !== password.search("(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{10,})") && ! password.includes("root");
25-
}
26-
EOF
27-
)
28-
echo "$validator" | quote_json
29-
}
30-
31-
getUserPasswordValidator()
32-
{
33-
validator=$(/bin/cat<<EOF
34-
{
35-
var password = arguments[0];
36-
return -1 !== password.search("(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{10,})") && ! password.includes("ffsync");
37-
}
38-
EOF
39-
)
40-
echo "$validator" | quote_json
41-
}
42-
4319
PAGE_FFSYNC_SETUP=$(/bin/cat<<EOF
4420
{
4521
"step_title": "Firefox Sync Server 1.5 database configuration",
@@ -50,20 +26,8 @@ PAGE_FFSYNC_SETUP=$(/bin/cat<<EOF
5026
"subitems": [{
5127
"key": "wizard_mysql_password_root",
5228
"desc": "Root password",
53-
"invalidText": "Password does not meet the current strength rules. The minimum password length is 10 characters and must include mixed case, numeric characters, and special characters; it must also exclude common passwords or using username as password.",
54-
"validator": {
55-
"fn": "$(getRootPasswordValidator)"
56-
}
57-
}]
58-
}, {
59-
"type": "password",
60-
"desc": "A 'ffsync' user and database will be created. Please enter a password for the 'ffsync' user.",
61-
"subitems": [{
62-
"key": "wizard_password_ffsync",
63-
"desc": "ffsync password",
64-
"invalidText": "Password does not meet the current strength rules. The minimum password length is 10 characters and must include mixed case, numeric characters, and special characters; it must also exclude common passwords or using username as password.",
6529
"validator": {
66-
"fn": "$(getUserPasswordValidator)"
30+
"allowBlank": false
6731
}
6832
}]
6933
}]
@@ -75,6 +39,7 @@ PAGE_FFSYNC_SETUP=$(/bin/cat<<EOF
7539
"subitems": [{
7640
"key": "wizard_ffsync_public_url",
7741
"desc": "Public URL",
42+
"emptyText": "http://hostname.domain:8132",
7843
"validator": {
7944
"allowBlank": false
8045
}

spk/ffsync/src/wizard/uninstall_uifile.sh

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/bin/bash
22

3+
# for backwards compatability
4+
if [ $SYNOPKG_DSM_VERSION_MAJOR -lt 7 ]; then
5+
if [ -z ${SYNOPKG_PKGDEST_VOL} ]; then
6+
SYNOPKG_PKGDEST_VOL="/volume1"
7+
fi
8+
if [ -z ${SYNOPKG_PKGNAME} ]; then
9+
SYNOPKG_PKGNAME="ffsync"
10+
fi
11+
fi
12+
313
quote_json ()
414
{
515
sed -e 's|\\|\\\\|g' -e 's|\"|\\\"|g'
@@ -16,18 +26,6 @@ page_append ()
1626
fi
1727
}
1828

19-
getPasswordValidator()
20-
{
21-
validator=$(/bin/cat<<EOF
22-
{
23-
var password = arguments[0];
24-
return -1 !== password.search("(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[^A-Za-z0-9])(?=.{10,})") && ! password.includes("root");
25-
}
26-
EOF
27-
)
28-
echo "$validator" | quote_json
29-
}
30-
3129
PAGE_FFSYNC_REMOVE=$(/bin/cat<<EOF
3230
{
3331
"step_title": "Remove Firefox Sync Server 1.5 database",
@@ -40,9 +38,8 @@ PAGE_FFSYNC_REMOVE=$(/bin/cat<<EOF
4038
"subitems": [{
4139
"key": "wizard_mysql_password_root",
4240
"desc": "Root password",
43-
"invalidText": "Password does not meet the current strength rules. The minimum password length is 10 characters and must include mixed case, numeric characters, and special characters; it must also exclude common passwords or using username as password.",
4441
"validator": {
45-
"fn": "$(getPasswordValidator)"
42+
"allowBlank": false
4643
}
4744
}]
4845
}, {
@@ -51,6 +48,7 @@ PAGE_FFSYNC_REMOVE=$(/bin/cat<<EOF
5148
"subitems": [{
5249
"key": "wizard_dbexport_path",
5350
"desc": "Database export location",
51+
"emptyText": "${SYNOPKG_PKGDEST_VOL}/${SYNOPKG_PKGNAME}/backup",
5452
"validator": {
5553
"allowBlank": true,
5654
"regex": {

0 commit comments

Comments
 (0)