partial
This commit is contained in:
parent
1ac076319a
commit
5af1629cc5
9 changed files with 103 additions and 3 deletions
|
|
@ -50,10 +50,10 @@ edit `Caddyfile` to set the boltcard domain name
|
||||||
### database creation
|
### database creation
|
||||||
edit `create_db.sql` to set the cardapp password
|
edit `create_db.sql` to set the cardapp password
|
||||||
`$ sudo -u postgres createuser -s ubuntu`
|
`$ sudo -u postgres createuser -s ubuntu`
|
||||||
`$ ./s_create_db`
|
`$ script/s_create_db`
|
||||||
|
|
||||||
### boltcard service install
|
### boltcard service install
|
||||||
`$ ./s_build`
|
`$ script/s_build`
|
||||||
`$ sudo systemctl enable boltcard`
|
`$ sudo systemctl enable boltcard`
|
||||||
`$ sudo systemctl status boltcard`
|
`$ sudo systemctl status boltcard`
|
||||||
|
|
||||||
|
|
|
||||||
100
internalapi/updateboltcard.go
Normal file
100
internalapi/updateboltcard.go
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/hex"
|
||||||
|
"github.com/boltcard/boltcard/db"
|
||||||
|
"github.com/boltcard/boltcard/resp_err"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func updateboltcard(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if db.Get_setting("FUNCTION_INTERNAL_API") != "ENABLE" {
|
||||||
|
msg := "updateboltcard: internal API function is not enabled"
|
||||||
|
log.Debug(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
tx_max_str := r.URL.Query().Get("tx_max")
|
||||||
|
tx_max, err := strconv.Atoi(tx_max_str)
|
||||||
|
if err != nil {
|
||||||
|
msg := "updateboltcard: tx_max is not a valid integer"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
enable_flag_str := r.URL.Query().Get("enable")
|
||||||
|
enable_flag, err := strconv.ParseBool(enable_flag_str)
|
||||||
|
if err != nil {
|
||||||
|
msg := "updateboltcard: enable is not a valid boolean"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
card_name := r.URL.Query().Get("card_name")
|
||||||
|
|
||||||
|
// check if card_name already exists
|
||||||
|
//TODO: allow multiple deactivated cards with the same card_name
|
||||||
|
card_count, err := db.Get_card_name_count(card_name)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if card_count == 0 {
|
||||||
|
msg := "updateboltcard: the card name does not exist in the database"
|
||||||
|
log.Warn(msg)
|
||||||
|
resp_err.Write_message(w, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// log the request
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"card_name": card_name, "tx_max": tx_max,
|
||||||
|
"enable": enable_flag}).Info("createboltcard API request")
|
||||||
|
|
||||||
|
// create the keys
|
||||||
|
|
||||||
|
one_time_code := random_hex()
|
||||||
|
k0_auth_key := random_hex()
|
||||||
|
k2_cmac_key := random_hex()
|
||||||
|
k3 := random_hex()
|
||||||
|
k4 := random_hex()
|
||||||
|
|
||||||
|
// update the card record
|
||||||
|
|
||||||
|
err = db.Update_card(card_name, tx_max, enable_flag)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// return the URI + one_time_code
|
||||||
|
|
||||||
|
hostdomain := db.Get_setting("HOST_DOMAIN")
|
||||||
|
url := ""
|
||||||
|
if strings.HasSuffix(hostdomain, ".onion") {
|
||||||
|
url = "http://" + hostdomain + "/new?a=" + one_time_code
|
||||||
|
} else {
|
||||||
|
url = "https://" + hostdomain + "/new?a=" + one_time_code
|
||||||
|
}
|
||||||
|
|
||||||
|
// log the response
|
||||||
|
|
||||||
|
log.WithFields(log.Fields{
|
||||||
|
"card_name": card_name, "url": url}).Info("updateboltcard API response")
|
||||||
|
|
||||||
|
jsonData := []byte(`{"status":"OK",` +
|
||||||
|
`"url":"` + url + `"}`)
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
w.Write(jsonData)
|
||||||
|
}
|
||||||
|
|
@ -20,7 +20,7 @@ CREATE TABLE cards (
|
||||||
tx_limit_sats INT NOT NULL,
|
tx_limit_sats INT NOT NULL,
|
||||||
day_limit_sats INT NOT NULL,
|
day_limit_sats INT NOT NULL,
|
||||||
lnurlp_enable CHAR(1) NOT NULL DEFAULT 'N',
|
lnurlp_enable CHAR(1) NOT NULL DEFAULT 'N',
|
||||||
card_name VARCHAR(100) UNIQUE NOT NULL DEFAULT '',
|
card_name VARCHAR(100) NOT NULL DEFAULT '',
|
||||||
email_address VARCHAR(100) DEFAULT '',
|
email_address VARCHAR(100) DEFAULT '',
|
||||||
email_enable CHAR(1) NOT NULL DEFAULT 'N',
|
email_enable CHAR(1) NOT NULL DEFAULT 'N',
|
||||||
uid_privacy CHAR(1) NOT NULL DEFAULT 'N',
|
uid_privacy CHAR(1) NOT NULL DEFAULT 'N',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue