From 36422eeca73eb0a20df8e607cf819c308c1b23ec Mon Sep 17 00:00:00 2001 From: J the Code Monkey Date: Mon, 11 Nov 2024 18:56:06 -0500 Subject: [PATCH] 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 --- pkg/manager/apt.go | 2 +- pkg/relays/khatru29/service.go | 6 ----- pkg/relays/khatru_pyramid/service.go | 6 ----- pkg/relays/nostr_rs_relay/service.go | 6 ----- pkg/relays/strfry/service.go | 6 ----- pkg/relays/strfry29/service.go | 6 ----- pkg/relays/wot_relay/constants.go | 9 +++---- pkg/relays/wot_relay/service.go | 32 ++++++++++++------------ pkg/relays/wot_relay/success_messages.go | 4 ++- 9 files changed, 24 insertions(+), 53 deletions(-) diff --git a/pkg/manager/apt.go b/pkg/manager/apt.go index e24d4fe..00ff785 100644 --- a/pkg/manager/apt.go +++ b/pkg/manager/apt.go @@ -46,7 +46,7 @@ func AptInstallPackages(selectedRelayOption string) { exec.Command("apt", "update", "-qq").Run() - packages := []string{"nginx", "certbot", "python3-certbot-nginx", "ufw", "fail2ban"} + packages := []string{"ufw", "fail2ban", "nginx", "certbot", "python3-certbot-nginx"} if selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == strfry.RelayName || selectedRelayOption == wot_relay.RelayName || selectedRelayOption == strfry29.RelayName { packages = append(packages, "git") diff --git a/pkg/relays/khatru29/service.go b/pkg/relays/khatru29/service.go index 13012d2..7aea0cc 100644 --- a/pkg/relays/khatru29/service.go +++ b/pkg/relays/khatru29/service.go @@ -24,9 +24,6 @@ func SetupRelayService(domain, privKey, relayContact string) { spinner.UpdateText("Creating config directory...") directories.CreateDirectory(ConfigDirPath, 0755) - // Use chown command to set ownership of the config directory to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath) - // Check if the environment file exists and remove it if it does files.RemoveFile(EnvFilePath) @@ -41,9 +38,6 @@ func SetupRelayService(domain, privKey, relayContact string) { // Set permissions for the environment file files.SetPermissions(EnvFilePath, 0600) - // Use chown command to set ownership of the environment file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, EnvFilePath) - // Create the systemd service file spinner.UpdateText("Creating service file...") serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath} diff --git a/pkg/relays/khatru_pyramid/service.go b/pkg/relays/khatru_pyramid/service.go index 09029ae..bbd0d0f 100644 --- a/pkg/relays/khatru_pyramid/service.go +++ b/pkg/relays/khatru_pyramid/service.go @@ -24,9 +24,6 @@ func SetupRelayService(domain, pubKey, relayContact string) { spinner.UpdateText("Creating config directory...") directories.CreateDirectory(ConfigDirPath, 0755) - // Use chown command to set ownership of the config directory to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath) - // Check if the environment file exists and remove it if it does files.RemoveFile(EnvFilePath) @@ -41,9 +38,6 @@ func SetupRelayService(domain, pubKey, relayContact string) { // Set permissions for the environment file files.SetPermissions(EnvFilePath, 0644) - // Use chown command to set ownership of the environment file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, EnvFilePath) - // Create the systemd service file spinner.UpdateText("Creating service file...") serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath} diff --git a/pkg/relays/nostr_rs_relay/service.go b/pkg/relays/nostr_rs_relay/service.go index 06115e4..3b7ec8a 100644 --- a/pkg/relays/nostr_rs_relay/service.go +++ b/pkg/relays/nostr_rs_relay/service.go @@ -26,9 +26,6 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) { spinner.UpdateText("Creating config directory...") directories.CreateDirectory(ConfigDirPath, 0755) - // Use chown command to set ownership of the config directory to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath) - // Check for and remove existing config file files.RemoveFile(ConfigFilePath) @@ -56,9 +53,6 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) { // Set permissions for the config file files.SetPermissions(ConfigFilePath, 0644) - // Use chown command to set ownership of the config file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, ConfigFilePath) - // Create the systemd service file spinner.UpdateText("Creating service file...") serviceFileParams := systemd.ServiceFileParams{BinaryFilePath: BinaryFilePath} diff --git a/pkg/relays/strfry/service.go b/pkg/relays/strfry/service.go index 2033fb1..5d6c1cc 100644 --- a/pkg/relays/strfry/service.go +++ b/pkg/relays/strfry/service.go @@ -25,9 +25,6 @@ func SetupRelayService(domain, pubKey, relayContact string) { spinner.UpdateText("Creating config directory...") directories.CreateDirectory(ConfigDirPath, 0755) - // Use chown command to set ownership of the config directory to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath) - // Check for and remove existing config file files.RemoveFile(ConfigFilePath) @@ -58,9 +55,6 @@ func SetupRelayService(domain, pubKey, relayContact string) { // Set permissions for the config file files.SetPermissions(ConfigFilePath, 0644) - // Use chown command to set ownership of the config file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, ConfigFilePath) - // Create the systemd service file spinner.UpdateText("Creating service file...") serviceFileParams := systemd.ServiceFileParams{BinaryFilePath: BinaryFilePath, ConfigFilePath: ConfigFilePath} diff --git a/pkg/relays/strfry29/service.go b/pkg/relays/strfry29/service.go index 65fb357..b848481 100644 --- a/pkg/relays/strfry29/service.go +++ b/pkg/relays/strfry29/service.go @@ -26,9 +26,6 @@ func SetupRelayService(domain, pubKey, relaySecretKey, relayContact string) { spinner.UpdateText("Creating config directory...") directories.CreateDirectory(ConfigDirPath, 0755) - // Use chown command to set ownership of the config directory to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath) - // Check if the config file exists and remove it if it does files.RemoveFile(ConfigFilePath) @@ -67,9 +64,6 @@ func SetupRelayService(domain, pubKey, relaySecretKey, relayContact string) { // Set permissions for the config file files.SetPermissions(ConfigFilePath, 0644) - // Use chown command to set ownership of the config file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, ConfigFilePath) - // Create the strfry29.json file spinner.UpdateText("Creating plugin file...") pluginFileParams := plugins.PluginFileParams{Domain: domain, RelaySecretKey: relaySecretKey, ConfigFilePath: ConfigFilePath, BinaryFilePath: BinaryFilePath} diff --git a/pkg/relays/wot_relay/constants.go b/pkg/relays/wot_relay/constants.go index ee63297..e19e51b 100644 --- a/pkg/relays/wot_relay/constants.go +++ b/pkg/relays/wot_relay/constants.go @@ -9,10 +9,9 @@ const BinaryFilePath = "/usr/local/bin/wot-relay" const NginxConfigFilePath = "/etc/nginx/conf.d/wot_relay.conf" const DataDirPath = "/var/lib/wot-relay" const ConfigDirPath = "/etc/wot-relay" -const TemplatesDirPath = "/etc/wot-relay/templates" -const IndexFilePath = "/etc/wot-relay/templates/index.html" +const IndexFile = "index.html" const TmpIndexFilePath = "/tmp/wot-relay/templates/index.html" -const StaticDirPath = "/etc/wot-relay/templates/static" +const StaticDir = "static" const TmpStaticDirPath = "/tmp/wot-relay/templates/static" const ServiceName = "wot-relay" const EnvFilePath = "/etc/wot-relay/wot-relay.env" @@ -23,8 +22,8 @@ RELAY_URL="{{.WSScheme}}://{{.Domain}}" RELAY_ICON="https://pfp.nostr.build/56306a93a88d4c657d8a3dfa57b55a4ed65b709eee927b5dafaab4d5330db21f.png" RELAY_CONTACT="{{.RelayContact}}" DB_PATH="/var/lib/wot-relay/db" -INDEX_PATH="/etc/wot-relay/templates/index.html" -STATIC_PATH="/etc/wot-relay/templates/static" +INDEX_PATH="/var/www/{{.Domain}}/index.html" +STATIC_PATH="/var/www/{{.Domain}}/static" REFRESH_INTERVAL_HOURS=3 MINIMUM_FOLLOWERS=1 ARCHIVAL_SYNC="FALSE" diff --git a/pkg/relays/wot_relay/service.go b/pkg/relays/wot_relay/service.go index 4eb89f9..b46a632 100644 --- a/pkg/relays/wot_relay/service.go +++ b/pkg/relays/wot_relay/service.go @@ -2,6 +2,7 @@ package wot_relay import ( "fmt" + "github.com/nodetec/rwz/pkg/network" "github.com/nodetec/rwz/pkg/relays" "github.com/nodetec/rwz/pkg/utils/configuration" "github.com/nodetec/rwz/pkg/utils/directories" @@ -26,37 +27,39 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) { spinner.UpdateText("Creating config directory...") directories.CreateDirectory(ConfigDirPath, 0755) - // Ensure the templates directory exists and set permissions - spinner.UpdateText("Creating templates directory...") - directories.CreateDirectory(TemplatesDirPath, 0755) + // Path to the /var/www/domain directory + WWWDomainDirPath := fmt.Sprintf("%s/%s", network.WWWDirPath, domain) - // Use chown command to set ownership of the config directory and its content to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, ConfigDirPath) + // Path to the index.html file + IndexFilePath := fmt.Sprintf("%s/%s", WWWDomainDirPath, IndexFile) // Check if the index.html file exists and remove it if it does files.RemoveFile(IndexFilePath) - // Copy the index.html file to templates directory - files.CopyFile(TmpIndexFilePath, TemplatesDirPath) + // Copy the index.html file to the /var/www/domain directory + files.CopyFile(TmpIndexFilePath, WWWDomainDirPath) // Set permissions for the index.html file files.SetPermissions(IndexFilePath, 0644) - // Use chown command to set ownership of the index.html file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, IndexFilePath) + // Use chown command to set ownership of the index.html file to the www-data user + files.SetOwnerAndGroup(relays.NginxUser, relays.NginxUser, IndexFilePath) + + // Path to the static directory + StaticDirPath := fmt.Sprintf("%s/%s", WWWDomainDirPath, StaticDir) // Remove the static directory and all of its content if it exists spinner.UpdateText("Removing static directory...") directories.RemoveDirectory(StaticDirPath) - // Copy the static directory and all of its content to the templates directory - directories.CopyDirectory(TmpStaticDirPath, TemplatesDirPath) + // Copy the static directory and all of its content to the /var/www/domain directory + directories.CopyDirectory(TmpStaticDirPath, WWWDomainDirPath) // Set permissions for the static directory directories.SetPermissions(StaticDirPath, 0755) - // Use chown command to set ownership of the static directory and its content to the nostr user - directories.SetOwnerAndGroup(relays.User, relays.User, StaticDirPath) + // Use chown command to set ownership of the static directory and its content to the www-data user + directories.SetOwnerAndGroup(relays.NginxUser, relays.NginxUser, StaticDirPath) // Check if the environment file exists and remove it if it does files.RemoveFile(EnvFilePath) @@ -72,9 +75,6 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) { // Set permissions for the environment file files.SetPermissions(EnvFilePath, 0644) - // Use chown command to set ownership of the environment file to the nostr user - files.SetOwnerAndGroup(relays.User, relays.User, EnvFilePath) - // Create the systemd service file spinner.UpdateText("Creating service file...") serviceFileParams := systemd.ServiceFileParams{EnvFilePath: EnvFilePath, BinaryFilePath: BinaryFilePath} diff --git a/pkg/relays/wot_relay/success_messages.go b/pkg/relays/wot_relay/success_messages.go index 306adb8..f2e6401 100644 --- a/pkg/relays/wot_relay/success_messages.go +++ b/pkg/relays/wot_relay/success_messages.go @@ -1,10 +1,12 @@ package wot_relay import ( + "fmt" + "github.com/nodetec/rwz/pkg/network" "github.com/nodetec/rwz/pkg/utils/messages" ) func SuccessMessages(domain string, httpsEnabled bool) { - 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} + 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} messages.SuccessMessages(&successMsgParams) }