Skip to content

Commit 36422ee

Browse files
committed
chore: move wot relay index.html file and static directory to the nginx document root directory and set ownership of relay config directories to be root
1 parent de898ff commit 36422ee

File tree

9 files changed

+24
-53
lines changed

9 files changed

+24
-53
lines changed

pkg/manager/apt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func AptInstallPackages(selectedRelayOption string) {
4646

4747
exec.Command("apt", "update", "-qq").Run()
4848

49-
packages := []string{"nginx", "certbot", "python3-certbot-nginx", "ufw", "fail2ban"}
49+
packages := []string{"ufw", "fail2ban", "nginx", "certbot", "python3-certbot-nginx"}
5050

5151
if selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == strfry.RelayName || selectedRelayOption == wot_relay.RelayName || selectedRelayOption == strfry29.RelayName {
5252
packages = append(packages, "git")

pkg/relays/khatru29/service.go

-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ func SetupRelayService(domain, privKey, relayContact string) {
2424
spinner.UpdateText("Creating config directory...")
2525
directories.CreateDirectory(ConfigDirPath, 0755)
2626

27-
// Use chown command to set ownership of the config directory to the nostr user
28-
directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath)
29-
3027
// Check if the environment file exists and remove it if it does
3128
files.RemoveFile(EnvFilePath)
3229

@@ -41,9 +38,6 @@ func SetupRelayService(domain, privKey, relayContact string) {
4138
// Set permissions for the environment file
4239
files.SetPermissions(EnvFilePath, 0600)
4340

44-
// Use chown command to set ownership of the environment file to the nostr user
45-
files.SetOwnerAndGroup(relays.User, relays.User, EnvFilePath)
46-
4741
// Create the systemd service file
4842
spinner.UpdateText("Creating service file...")
4943
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}

pkg/relays/khatru_pyramid/service.go

-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ func SetupRelayService(domain, pubKey, relayContact string) {
2424
spinner.UpdateText("Creating config directory...")
2525
directories.CreateDirectory(ConfigDirPath, 0755)
2626

27-
// Use chown command to set ownership of the config directory to the nostr user
28-
directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath)
29-
3027
// Check if the environment file exists and remove it if it does
3128
files.RemoveFile(EnvFilePath)
3229

@@ -41,9 +38,6 @@ func SetupRelayService(domain, pubKey, relayContact string) {
4138
// Set permissions for the environment file
4239
files.SetPermissions(EnvFilePath, 0644)
4340

44-
// Use chown command to set ownership of the environment file to the nostr user
45-
files.SetOwnerAndGroup(relays.User, relays.User, EnvFilePath)
46-
4741
// Create the systemd service file
4842
spinner.UpdateText("Creating service file...")
4943
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}

pkg/relays/nostr_rs_relay/service.go

-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
2626
spinner.UpdateText("Creating config directory...")
2727
directories.CreateDirectory(ConfigDirPath, 0755)
2828

29-
// Use chown command to set ownership of the config directory to the nostr user
30-
directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath)
31-
3229
// Check for and remove existing config file
3330
files.RemoveFile(ConfigFilePath)
3431

@@ -56,9 +53,6 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
5653
// Set permissions for the config file
5754
files.SetPermissions(ConfigFilePath, 0644)
5855

59-
// Use chown command to set ownership of the config file to the nostr user
60-
files.SetOwnerAndGroup(relays.User, relays.User, ConfigFilePath)
61-
6256
// Create the systemd service file
6357
spinner.UpdateText("Creating service file...")
6458
serviceFileParams := systemd.ServiceFileParams{BinaryFilePath: BinaryFilePath}

pkg/relays/strfry/service.go

-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ func SetupRelayService(domain, pubKey, relayContact string) {
2525
spinner.UpdateText("Creating config directory...")
2626
directories.CreateDirectory(ConfigDirPath, 0755)
2727

28-
// Use chown command to set ownership of the config directory to the nostr user
29-
directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath)
30-
3128
// Check for and remove existing config file
3229
files.RemoveFile(ConfigFilePath)
3330

@@ -58,9 +55,6 @@ func SetupRelayService(domain, pubKey, relayContact string) {
5855
// Set permissions for the config file
5956
files.SetPermissions(ConfigFilePath, 0644)
6057

61-
// Use chown command to set ownership of the config file to the nostr user
62-
files.SetOwnerAndGroup(relays.User, relays.User, ConfigFilePath)
63-
6458
// Create the systemd service file
6559
spinner.UpdateText("Creating service file...")
6660
serviceFileParams := systemd.ServiceFileParams{BinaryFilePath: BinaryFilePath, ConfigFilePath: ConfigFilePath}

pkg/relays/strfry29/service.go

-6
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ func SetupRelayService(domain, pubKey, relaySecretKey, relayContact string) {
2626
spinner.UpdateText("Creating config directory...")
2727
directories.CreateDirectory(ConfigDirPath, 0755)
2828

29-
// Use chown command to set ownership of the config directory to the nostr user
30-
directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath)
31-
3229
// Check if the config file exists and remove it if it does
3330
files.RemoveFile(ConfigFilePath)
3431

@@ -67,9 +64,6 @@ func SetupRelayService(domain, pubKey, relaySecretKey, relayContact string) {
6764
// Set permissions for the config file
6865
files.SetPermissions(ConfigFilePath, 0644)
6966

70-
// Use chown command to set ownership of the config file to the nostr user
71-
files.SetOwnerAndGroup(relays.User, relays.User, ConfigFilePath)
72-
7367
// Create the strfry29.json file
7468
spinner.UpdateText("Creating plugin file...")
7569
pluginFileParams := plugins.PluginFileParams{Domain: domain, RelaySecretKey: relaySecretKey, ConfigFilePath: ConfigFilePath, BinaryFilePath: BinaryFilePath}

pkg/relays/wot_relay/constants.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ const BinaryFilePath = "/usr/local/bin/wot-relay"
99
const NginxConfigFilePath = "/etc/nginx/conf.d/wot_relay.conf"
1010
const DataDirPath = "/var/lib/wot-relay"
1111
const ConfigDirPath = "/etc/wot-relay"
12-
const TemplatesDirPath = "/etc/wot-relay/templates"
13-
const IndexFilePath = "/etc/wot-relay/templates/index.html"
12+
const IndexFile = "index.html"
1413
const TmpIndexFilePath = "/tmp/wot-relay/templates/index.html"
15-
const StaticDirPath = "/etc/wot-relay/templates/static"
14+
const StaticDir = "static"
1615
const TmpStaticDirPath = "/tmp/wot-relay/templates/static"
1716
const ServiceName = "wot-relay"
1817
const EnvFilePath = "/etc/wot-relay/wot-relay.env"
@@ -23,8 +22,8 @@ RELAY_URL="{{.WSScheme}}://{{.Domain}}"
2322
RELAY_ICON="https://pfp.nostr.build/56306a93a88d4c657d8a3dfa57b55a4ed65b709eee927b5dafaab4d5330db21f.png"
2423
RELAY_CONTACT="{{.RelayContact}}"
2524
DB_PATH="/var/lib/wot-relay/db"
26-
INDEX_PATH="/etc/wot-relay/templates/index.html"
27-
STATIC_PATH="/etc/wot-relay/templates/static"
25+
INDEX_PATH="/var/www/{{.Domain}}/index.html"
26+
STATIC_PATH="/var/www/{{.Domain}}/static"
2827
REFRESH_INTERVAL_HOURS=3
2928
MINIMUM_FOLLOWERS=1
3029
ARCHIVAL_SYNC="FALSE"

pkg/relays/wot_relay/service.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package wot_relay
22

33
import (
44
"fmt"
5+
"github.com/nodetec/rwz/pkg/network"
56
"github.com/nodetec/rwz/pkg/relays"
67
"github.com/nodetec/rwz/pkg/utils/configuration"
78
"github.com/nodetec/rwz/pkg/utils/directories"
@@ -26,37 +27,39 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
2627
spinner.UpdateText("Creating config directory...")
2728
directories.CreateDirectory(ConfigDirPath, 0755)
2829

29-
// Ensure the templates directory exists and set permissions
30-
spinner.UpdateText("Creating templates directory...")
31-
directories.CreateDirectory(TemplatesDirPath, 0755)
30+
// Path to the /var/www/domain directory
31+
WWWDomainDirPath := fmt.Sprintf("%s/%s", network.WWWDirPath, domain)
3232

33-
// Use chown command to set ownership of the config directory and its content to the nostr user
34-
directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath)
33+
// Path to the index.html file
34+
IndexFilePath := fmt.Sprintf("%s/%s", WWWDomainDirPath, IndexFile)
3535

3636
// Check if the index.html file exists and remove it if it does
3737
files.RemoveFile(IndexFilePath)
3838

39-
// Copy the index.html file to templates directory
40-
files.CopyFile(TmpIndexFilePath, TemplatesDirPath)
39+
// Copy the index.html file to the /var/www/domain directory
40+
files.CopyFile(TmpIndexFilePath, WWWDomainDirPath)
4141

4242
// Set permissions for the index.html file
4343
files.SetPermissions(IndexFilePath, 0644)
4444

45-
// Use chown command to set ownership of the index.html file to the nostr user
46-
files.SetOwnerAndGroup(relays.User, relays.User, IndexFilePath)
45+
// Use chown command to set ownership of the index.html file to the www-data user
46+
files.SetOwnerAndGroup(relays.NginxUser, relays.NginxUser, IndexFilePath)
47+
48+
// Path to the static directory
49+
StaticDirPath := fmt.Sprintf("%s/%s", WWWDomainDirPath, StaticDir)
4750

4851
// Remove the static directory and all of its content if it exists
4952
spinner.UpdateText("Removing static directory...")
5053
directories.RemoveDirectory(StaticDirPath)
5154

52-
// Copy the static directory and all of its content to the templates directory
53-
directories.CopyDirectory(TmpStaticDirPath, TemplatesDirPath)
55+
// Copy the static directory and all of its content to the /var/www/domain directory
56+
directories.CopyDirectory(TmpStaticDirPath, WWWDomainDirPath)
5457

5558
// Set permissions for the static directory
5659
directories.SetPermissions(StaticDirPath, 0755)
5760

58-
// Use chown command to set ownership of the static directory and its content to the nostr user
59-
directories.SetOwnerAndGroup(relays.User, relays.User, StaticDirPath)
61+
// Use chown command to set ownership of the static directory and its content to the www-data user
62+
directories.SetOwnerAndGroup(relays.NginxUser, relays.NginxUser, StaticDirPath)
6063

6164
// Check if the environment file exists and remove it if it does
6265
files.RemoveFile(EnvFilePath)
@@ -72,9 +75,6 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
7275
// Set permissions for the environment file
7376
files.SetPermissions(EnvFilePath, 0644)
7477

75-
// Use chown command to set ownership of the environment file to the nostr user
76-
files.SetOwnerAndGroup(relays.User, relays.User, EnvFilePath)
77-
7878
// Create the systemd service file
7979
spinner.UpdateText("Creating service file...")
8080
serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath}
+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package wot_relay
22

33
import (
4+
"fmt"
5+
"github.com/nodetec/rwz/pkg/network"
46
"github.com/nodetec/rwz/pkg/utils/messages"
57
)
68

79
func SuccessMessages(domain string, httpsEnabled bool) {
8-
successMsgParams := messages.SuccessMsgParams{Domain: domain, HTTPSEnabled: httpsEnabled, DataDirPath: DataDirPath, IndexFilePath: IndexFilePath, StaticDirPath: StaticDirPath, NginxConfigFilePath: NginxConfigFilePath, BinaryFilePath: BinaryFilePath, EnvFilePath: EnvFilePath, ServiceFilePath: ServiceFilePath, ServiceName: ServiceName, RelayName: RelayName, GitHubLink: GithubLink}
10+
successMsgParams := messages.SuccessMsgParams{Domain: domain, HTTPSEnabled: httpsEnabled, DataDirPath: DataDirPath, IndexFilePath: fmt.Sprintf("%s/%s/%s", network.WWWDirPath, domain, IndexFile), StaticDirPath: fmt.Sprintf("%s/%s/%s", network.WWWDirPath, domain, StaticDir), NginxConfigFilePath: NginxConfigFilePath, BinaryFilePath: BinaryFilePath, EnvFilePath: EnvFilePath, ServiceFilePath: ServiceFilePath, ServiceName: ServiceName, RelayName: RelayName, GitHubLink: GithubLink}
911
messages.SuccessMessages(&successMsgParams)
1012
}

0 commit comments

Comments
 (0)