Skip to content

Commit de898ff

Browse files
committed
feat: add pubkey input and configure real ip header for strfry and strfry29 and update nostr-rs-relay, strfry, wot relay, and strfry29 database path
1 parent 2e223bf commit de898ff

File tree

8 files changed

+31
-13
lines changed

8 files changed

+31
-13
lines changed

cmd/install.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ var installCmd = &cobra.Command{
5454

5555
var privKey string
5656
var pubKey string
57-
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == wot_relay.RelayName {
57+
if selectedRelayOption == khatru_pyramid.RelayName || selectedRelayOption == nostr_rs_relay.RelayName || selectedRelayOption == strfry.RelayName || selectedRelayOption == wot_relay.RelayName || selectedRelayOption == strfry29.RelayName {
5858
pterm.Println()
5959
pubKey, _ = pterm.DefaultInteractiveTextInput.Show("Public key (hex not npub)")
60-
} else if selectedRelayOption == khatru29.RelayName || selectedRelayOption == strfry29.RelayName {
60+
}
61+
62+
if selectedRelayOption == khatru29.RelayName || selectedRelayOption == strfry29.RelayName {
6163
pterm.Println()
6264
privKeyInput := pterm.DefaultInteractiveTextInput.WithMask("*")
6365
privKey, _ = privKeyInput.Show("Private key (hex not nsec)")
@@ -160,7 +162,7 @@ var installCmd = &cobra.Command{
160162
strfry.InstallRelayBinary()
161163

162164
// Step 10: Set up the relay service
163-
strfry.SetupRelayService(relayDomain, relayContact)
165+
strfry.SetupRelayService(relayDomain, pubKey, relayContact)
164166

165167
// Step 11: Show success messages
166168
strfry.SuccessMessages(relayDomain, httpsEnabled)
@@ -217,7 +219,7 @@ var installCmd = &cobra.Command{
217219
strfry29.InstallRelayBinary()
218220

219221
// Step 10: Set up the relay service
220-
strfry29.SetupRelayService(relayDomain, privKey, relayContact)
222+
strfry29.SetupRelayService(relayDomain, pubKey, privKey, relayContact)
221223

222224
// Step 11: Show success messages
223225
strfry29.SuccessMessages(relayDomain, httpsEnabled)

pkg/relays/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ package relays
22

33
const BinaryDestDir = "/usr/local/bin"
44
const TmpDirPath = "/tmp"
5+
const DBDir = "db"
56
const User = "nostr"
67
const NginxUser = "www-data"

pkg/relays/khatru29/constants.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ const DataDirPath = "/var/lib/khatru29"
88
const ConfigDirPath = "/etc/khatru29"
99
const ServiceName = "khatru29"
1010
const EnvFilePath = "/etc/khatru29/khatru29.env"
11-
const EnvFileTemplate = `PORT="5577"
12-
DOMAIN="{{.Domain}}"
11+
const EnvFileTemplate = `DOMAIN="{{.Domain}}"
12+
PORT="5577"
1313
RELAY_NAME="Khatru29"
1414
RELAY_PRIVKEY="{{.PrivKey}}"
1515
RELAY_DESCRIPTION="Khatru29 Relay"

pkg/relays/nostr_rs_relay/nginx_https.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ server {
3737
proxy_set_header Host $host;
3838
proxy_set_header X-Real-IP $remote_addr;
3939
proxy_set_header X-Forwarded-For $remote_addr;
40+
proxy_set_header X-Forwarded-Proto $scheme;
4041
# First attempt to serve request as file, then
4142
# as directory, then fall back to displaying 404.
4243
try_files $uri $uri/ =404;

pkg/relays/nostr_rs_relay/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
1717
// Ensure the data directory exists and set permissions
1818
spinner.UpdateText("Creating data directory...")
1919
directories.CreateDirectory(DataDirPath, 0755)
20-
directories.CreateDirectory(fmt.Sprintf("%s/db", DataDirPath), 0755)
20+
directories.CreateDirectory(fmt.Sprintf("%s/%s", DataDirPath, relays.DBDir), 0755)
2121

2222
// Use chown command to set ownership of the data directory to the nostr user
2323
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
@@ -45,7 +45,7 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
4545
files.InPlaceEdit(fmt.Sprintf(`s|#contact = ".*"|contact = "%s"|`, relayContact), TmpConfigFilePath)
4646

4747
// Construct the sed command to change the data directory
48-
files.InPlaceEdit(fmt.Sprintf(`s|#data_directory = ".*"|data_directory = "%s"|`, DataDirPath), TmpConfigFilePath)
48+
files.InPlaceEdit(fmt.Sprintf(`s|#data_directory = ".*"|data_directory = "%s/%s"|`, DataDirPath, relays.DBDir), TmpConfigFilePath)
4949

5050
// Construct the sed command to change the remote ip header
5151
files.InPlaceEdit(fmt.Sprintf(`s|#remote_ip_header = "x-forwarded-for"|remote_ip_header = "x-forwarded-for"|`), TmpConfigFilePath)

pkg/relays/strfry/service.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
)
1111

1212
// Function to set up the relay service
13-
func SetupRelayService(domain, relayContact string) {
13+
func SetupRelayService(domain, pubKey, relayContact string) {
1414
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay service...")
1515

1616
// Ensure the data directory exists and set permissions
1717
spinner.UpdateText("Creating data directory...")
1818
directories.CreateDirectory(DataDirPath, 0755)
19+
directories.CreateDirectory(fmt.Sprintf("%s/%s", DataDirPath, relays.DBDir), 0755)
1920

2021
// Use chown command to set ownership of the data directory to the nostr user
2122
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
@@ -34,14 +35,20 @@ func SetupRelayService(domain, relayContact string) {
3435
files.RemoveFile(ServiceFilePath)
3536

3637
// Construct the sed command to change the db path
37-
files.InPlaceEdit(fmt.Sprintf(`s|db = ".*"|db = "%s"|`, DataDirPath), TmpConfigFilePath)
38+
files.InPlaceEdit(fmt.Sprintf(`s|db = ".*"|db = "%s/%s"|`, DataDirPath, relays.DBDir), TmpConfigFilePath)
3839

3940
// Construct the sed command to change the nofiles limit
4041
// TODO
4142
// Determine system hard limit
4243
// Determine preferred nofiles value
4344
files.InPlaceEdit(`s|nofiles = .*|nofiles = 0|`, TmpConfigFilePath)
4445

46+
// Construct the sed command to change the realIpHeader
47+
files.InPlaceEdit(`s|realIpHeader = .*|realIpHeader = "x-forwarded-for"|`, TmpConfigFilePath)
48+
49+
// Construct the sed command to change the pubkey
50+
files.InPlaceEdit(fmt.Sprintf(`s|pubkey = .*|pubkey = "%s"|`, pubKey), TmpConfigFilePath)
51+
4552
// Construct the sed command to change the contact
4653
files.InPlaceEdit(fmt.Sprintf(`s|contact = ".*"|contact = "%s"|`, relayContact), TmpConfigFilePath)
4754

pkg/relays/strfry29/service.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ import (
1111
)
1212

1313
// Function to set up the relay service
14-
func SetupRelayService(domain, relaySecretKey, relayContact string) {
14+
func SetupRelayService(domain, pubKey, relaySecretKey, relayContact string) {
1515
spinner, _ := pterm.DefaultSpinner.Start("Configuring relay service...")
1616

1717
// Ensure the data directory exists and set permissions
1818
spinner.UpdateText("Creating data directory...")
1919
directories.CreateDirectory(DataDirPath, 0755)
20+
directories.CreateDirectory(fmt.Sprintf("%s/%s", DataDirPath, relays.DBDir), 0755)
2021

2122
// Use chown command to set ownership of the data directory to the nostr user
2223
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)
@@ -38,16 +39,22 @@ func SetupRelayService(domain, relaySecretKey, relayContact string) {
3839
files.RemoveFile(ServiceFilePath)
3940

4041
// Construct the sed command to change the db path
41-
files.InPlaceEdit(fmt.Sprintf(`s|db = ".*"|db = "%s"|`, DataDirPath), TmpConfigFilePath)
42+
files.InPlaceEdit(fmt.Sprintf(`s|db = ".*"|db = "%s/%s"|`, DataDirPath, relays.DBDir), TmpConfigFilePath)
4243

4344
// TODO
4445
// Determine system hard limit
4546
// Determine preferred nofiles value
4647
// Construct the sed command to change the nofiles limit
4748

49+
// Construct the sed command to change the realIpHeader
50+
files.InPlaceEdit(`s|realIpHeader = .*|realIpHeader = "x-forwarded-for"|`, TmpConfigFilePath)
51+
4852
// Construct the sed command to change the info description
4953
files.InPlaceEdit(fmt.Sprintf(`s|description = ".*"|description = "%s"|`, ConfigFileInfoDescription), TmpConfigFilePath)
5054

55+
// Construct the sed command to change the pubkey
56+
files.InPlaceEdit(fmt.Sprintf(`s|pubkey = .*|pubkey = "%s"|`, pubKey), TmpConfigFilePath)
57+
5158
// Construct the sed command to change the contact
5259
files.InPlaceEdit(fmt.Sprintf(`s|contact = ".*"|contact = "%s"|`, relayContact), TmpConfigFilePath)
5360

pkg/relays/wot_relay/service.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func SetupRelayService(domain, pubKey, relayContact string, httpsEnabled bool) {
1717
// Ensure the data directory exists and set permissions
1818
spinner.UpdateText("Creating data directory...")
1919
directories.CreateDirectory(DataDirPath, 0755)
20-
directories.CreateDirectory(fmt.Sprintf("%s/db", DataDirPath), 0755)
20+
directories.CreateDirectory(fmt.Sprintf("%s/%s", DataDirPath, relays.DBDir), 0755)
2121

2222
// Use chown command to set ownership of the data directory and its content to the nostr user
2323
directories.SetOwnerAndGroup(relays.User, relays.User, DataDirPath)

0 commit comments

Comments
 (0)