Skip to content

Commit

Permalink
chore: move wot relay index.html file and static directory to the ngi…
Browse files Browse the repository at this point in the history
…nx document root directory and set ownership of relay config directories to be root
  • Loading branch information
jchiarulli committed Nov 11, 2024
1 parent de898ff commit 36422ee
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pkg/manager/apt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 0 additions & 6 deletions pkg/relays/khatru29/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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}
Expand Down
6 changes: 0 additions & 6 deletions pkg/relays/khatru_pyramid/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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}
Expand Down
6 changes: 0 additions & 6 deletions pkg/relays/nostr_rs_relay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}
Expand Down
6 changes: 0 additions & 6 deletions pkg/relays/strfry/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}
Expand Down
6 changes: 0 additions & 6 deletions pkg/relays/strfry29/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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}
Expand Down
9 changes: 4 additions & 5 deletions pkg/relays/wot_relay/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
32 changes: 16 additions & 16 deletions pkg/relays/wot_relay/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion pkg/relays/wot_relay/success_messages.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit 36422ee

Please sign in to comment.