Skip to content

Commit

Permalink
Merge pull request #60 from Impa10r/v1.5.3
Browse files Browse the repository at this point in the history
v1.5.3
  • Loading branch information
Impa10r authored Jun 18, 2024
2 parents f7cde54 + f79a808 commit 766d7d0
Show file tree
Hide file tree
Showing 29 changed files with 3,735 additions and 2,518 deletions.
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DEBUG=1
NETWORK="testnet"
NETWORK="testnet"
NO_HTTPS="true"
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"program": "${workspaceFolder}/cmd/psweb/",
"showLog": false,
"envFile": "${workspaceFolder}/.env",
// "args": ["-datadir", "/home/vlad/.peerswap2"]
"args": ["-datadir", "/home/vlad/.peerswap2"]
}
]
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Versions

## 1.5.3

- Add automatic channel fees management
- Randomize serial number of CA to let install in Ubuntu/Firefox
- Increase Web UI password cookie expiry to 7 days
- Add NO_HTTPS env variable for Umbrel update

## 1.5.2

- Add navigation menu
Expand Down
6 changes: 5 additions & 1 deletion cmd/psweb/config/cln.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ func GetPeerswapCLNSetting(section, searchVariable string) string {
// Search section
if sectionIndex := strings.Index(fileContent, "["+section+"]"); sectionIndex > -1 {
lines := strings.Split(string(fileContent[sectionIndex:]), "\n")
for _, line := range lines {
for i, line := range lines {
if i > 0 && strings.HasPrefix(line, "[") {
// end of section reached
break
}
if parts := strings.Split(line, "="); len(parts) > 1 {
if parts[0] == searchVariable {
// Remove double quotes
Expand Down
3 changes: 1 addition & 2 deletions cmd/psweb/config/lnd.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ func SavePS() {
//key, default, new value, env key
t += setPeerswapdVariable("host", "localhost:42069", Config.RpcHost, "")
t += setPeerswapdVariable("rpchost", "", "", "") // will keep the same if set
// remove resthost
// t += setPeerswapdVariable("resthost", "localhost:42070", "", "")
t += setPeerswapdVariable("resthost", "localhost:42070", "", "")
t += setPeerswapdVariable("lnd.host", "localhost:10009", "", "LND_HOST")
t += setPeerswapdVariable("lnd.tlscertpath", filepath.Join(Config.LightningDir, "tls.cert"), "", "")
t += setPeerswapdVariable("lnd.macaroonpath", filepath.Join(Config.LightningDir, "data", "chain", "bitcoin", Config.Chain, "admin.macaroon"), "", "LND_MACAROONPATH")
Expand Down
16 changes: 11 additions & 5 deletions cmd/psweb/config/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"software.sslmate.com/src/go-pkcs12"
)

// generates Certificate Autonrity CA.crt
// generates Root Certificate Autority CA.crt
func GenerateCA() error {
crtPath := filepath.Join(Config.DataDir, "CA.crt")
keyPath := filepath.Join(Config.DataDir, "CA.key")
Expand All @@ -42,7 +42,7 @@ func GenerateCA() error {
// Create a certificate signing request (CSR)
csrTemplate := x509.CertificateRequest{
Subject: pkix.Name{
Organization: []string{"PeerSwap Web UI"},
Organization: []string{"PeerSwap Web UI Local Root CA"},
},
SignatureAlgorithm: x509.SHA256WithRSA,
}
Expand All @@ -60,9 +60,15 @@ func GenerateCA() error {
return err
}

// Generate a random serial number
serialNumber, err := rand.Int(rand.Reader, new(big.Int).Lsh(big.NewInt(1), 128))
if err != nil {
return err
}

// Create a certificate based on the CSR
certTemplate := x509.Certificate{
SerialNumber: big.NewInt(1),
SerialNumber: serialNumber,
Subject: certFromCSR.Subject,
NotBefore: time.Now(),
NotAfter: time.Now().AddDate(10, 0, 0), // Valid for 10 years
Expand Down Expand Up @@ -258,12 +264,12 @@ func GenerateClientCertificate(password string) error {
return err
}

log.Println("Generated new client.crt and client.key")
log.Println("Generated new client.p12")

return nil
}

const charset = "abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789"
const charset = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"

// GeneratePassword generates a random password of a given length
func GeneratePassword(length int) (string, error) {
Expand Down
55 changes: 55 additions & 0 deletions cmd/psweb/db/bolt.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package db

import (
"encoding/json"
"fmt"
"log"
"path"
"peerswap-web/cmd/psweb/config"

"go.etcd.io/bbolt"
)

// Save saves any object to the Bolt database
func Save(bucketName string, key string, value interface{}) error {
// Open the Bolt database
db, err := bbolt.Open(path.Join(config.Config.DataDir, "psweb.db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()

return db.Update(func(tx *bbolt.Tx) error {
b, err := tx.CreateBucketIfNotExists([]byte(bucketName))
if err != nil {
return err
}
data, err := json.Marshal(value)
if err != nil {
return err
}
return b.Put([]byte(key), data)
})
}

// Load loads any object from the Bolt database
func Load(bucketName string, key string, result interface{}) error {
// Open the Bolt database
db, err := bbolt.Open(path.Join(config.Config.DataDir, "psweb.db"), 0600, nil)
if err != nil {
log.Fatal(err)
}
defer db.Close()

return db.View(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(bucketName))
if b == nil {
return fmt.Errorf("bucket %s not found", bucketName)
}
data := b.Get([]byte(key))
if data == nil {
return fmt.Errorf("key %s not found in bucket %s", key, bucketName)
}
return json.Unmarshal(data, result)
})
}
Loading

0 comments on commit 766d7d0

Please sign in to comment.