Generates backend server config (with rpcauth) and client config
parent
95f6b78b6f
commit
5d44ff33ff
|
@ -13,6 +13,7 @@ shift 2
|
|||
|
||||
mkdir -p build
|
||||
cp -r /src/build/templates build
|
||||
cp -r /src/build/scripts build
|
||||
cp -r /src/configs .
|
||||
mkdir -p /go/src/blockbook/build && cp -r /src/build/tools /go/src/blockbook/build/tools
|
||||
go run build/templates/generate.go $coin
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2015-2018 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
import sys
|
||||
import os
|
||||
from random import SystemRandom
|
||||
import base64
|
||||
import hmac
|
||||
|
||||
def generate_salt():
|
||||
# This uses os.urandom() underneath
|
||||
cryptogen = SystemRandom()
|
||||
|
||||
# Create 16 byte hex salt
|
||||
salt_sequence = [cryptogen.randrange(256) for _ in range(16)]
|
||||
return ''.join([format(r, 'x') for r in salt_sequence])
|
||||
|
||||
def generate_password():
|
||||
"""Create 32 byte b64 password"""
|
||||
return base64.urlsafe_b64encode(os.urandom(32)).decode('utf-8')
|
||||
|
||||
def password_to_hmac(salt, password):
|
||||
m = hmac.new(bytearray(salt, 'utf-8'), bytearray(password, 'utf-8'), 'SHA256')
|
||||
return m.hexdigest()
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 2:
|
||||
sys.stderr.write('Please include username (and an optional password, will generate one if not provided) as an argument.\n')
|
||||
sys.exit(0)
|
||||
|
||||
username = sys.argv[1]
|
||||
|
||||
salt = generate_salt()
|
||||
if len(sys.argv) > 2:
|
||||
password = sys.argv[2]
|
||||
else:
|
||||
password = generate_password()
|
||||
password_hmac = password_to_hmac(salt, password)
|
||||
|
||||
print('String to be appended to bitcoin.conf:')
|
||||
print('rpcauth={0}:{1}${2}'.format(username, salt, password_hmac))
|
||||
print('Your password:\n{0}'.format(password))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -3,8 +3,7 @@ daemon=1
|
|||
server=1
|
||||
{{if .Backend.Mainnet}}mainnet=1{{else}}testnet=1{{end}}
|
||||
nolisten=1
|
||||
rpcuser={{.IPC.RPCUser}}
|
||||
rpcpassword={{.IPC.RPCPass}}
|
||||
{{generateRPCAuth .IPC.RPCUser .IPC.RPCPass -}}
|
||||
rpcport={{.Ports.BackendRPC}}
|
||||
txindex=1
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{{define "main" -}}
|
||||
rpcuser={{.IPC.RPCUser}}
|
||||
rpcpassword={{.IPC.RPCPass}}
|
||||
rpcport={{.Ports.BackendRPC}}
|
||||
{{end}}
|
|
@ -0,0 +1,30 @@
|
|||
{{define "main" -}}
|
||||
daemon=1
|
||||
server=1
|
||||
{{if .Backend.Mainnet}}mainnet=1{{else}}testnet=1{{end}}
|
||||
nolisten=1
|
||||
rpcuser={{.IPC.RPCUser}}
|
||||
rpcpassword={{.IPC.RPCPass}}
|
||||
rpcport={{.Ports.BackendRPC}}
|
||||
txindex=1
|
||||
|
||||
zmqpubhashtx={{template "IPC.MessageQueueBindingTemplate" .}}
|
||||
zmqpubhashblock={{template "IPC.MessageQueueBindingTemplate" .}}
|
||||
|
||||
rpcworkqueue=1100
|
||||
maxmempool=2000
|
||||
dbcache=1000
|
||||
|
||||
{{- if .Backend.AdditionalParams}}
|
||||
# generated from additional_params
|
||||
{{- range $name, $value := .Backend.AdditionalParams}}
|
||||
{{- if eq $name "addnode"}}
|
||||
{{- range $index, $node := $value}}
|
||||
addnode={{$node}}
|
||||
{{- end}}
|
||||
{{- else}}
|
||||
{{$name}}={{$value}}
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
{{- end}}
|
||||
{{end}}
|
|
@ -0,0 +1,5 @@
|
|||
{{define "main" -}}
|
||||
rpcuser={{.IPC.RPCUser}}
|
||||
rpcpassword={{.IPC.RPCPass}}
|
||||
rpcport={{.Ports.BackendRPC}}
|
||||
{{end}}
|
|
@ -1,3 +1,4 @@
|
|||
{{define "main" -}}
|
||||
{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf
|
||||
{{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}_client.conf
|
||||
{{end}}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
{{define "main" -}}
|
||||
#!/usr/bin/dh-exec
|
||||
backend/* {{.Env.BackendInstallPath}}/{{.Coin.Alias}}
|
||||
backend.conf => {{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf
|
||||
server.conf => {{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}.conf
|
||||
client.conf => {{.Env.BackendInstallPath}}/{{.Coin.Alias}}/{{.Coin.Alias}}_client.conf
|
||||
{{end}}
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
package build
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"text/template"
|
||||
"time"
|
||||
|
@ -59,7 +61,8 @@ type Config struct {
|
|||
ServiceAdditionalParamsTemplate string `json:"service_additional_params_template"`
|
||||
ProtectMemory bool `json:"protect_memory"`
|
||||
Mainnet bool `json:"mainnet"`
|
||||
ConfigFile string `json:"config_file"`
|
||||
ServerConfigFile string `json:"server_config_file"`
|
||||
ClientConfigFile string `json:"client_config_file"`
|
||||
AdditionalParams interface{} `json:"additional_params"`
|
||||
} `json:"backend"`
|
||||
Blockbook struct {
|
||||
|
@ -90,6 +93,17 @@ func jsonToString(msg json.RawMessage) (string, error) {
|
|||
return string(d), nil
|
||||
}
|
||||
|
||||
func generateRPCAuth(user, pass string) (string, error) {
|
||||
cmd := exec.Command("/bin/bash", "-c", "build/scripts/rpcauth.py \"$0\" \"$1\" | sed -n -e 2p", user, pass)
|
||||
var out bytes.Buffer
|
||||
cmd.Stdout = &out
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return out.String(), nil
|
||||
}
|
||||
|
||||
func (c *Config) ParseTemplate() *template.Template {
|
||||
templates := map[string]string{
|
||||
"IPC.RPCURLTemplate": c.IPC.RPCURLTemplate,
|
||||
|
@ -103,7 +117,8 @@ func (c *Config) ParseTemplate() *template.Template {
|
|||
}
|
||||
|
||||
funcMap := template.FuncMap{
|
||||
"jsonToString": jsonToString,
|
||||
"jsonToString": jsonToString,
|
||||
"generateRPCAuth": generateRPCAuth,
|
||||
}
|
||||
|
||||
t := template.New("").Funcs(funcMap)
|
||||
|
@ -230,7 +245,10 @@ func GeneratePackageDefinitions(config *Config, templateDir, outputDir string) e
|
|||
}
|
||||
|
||||
if !isEmpty(config, "backend") {
|
||||
err = writeBackendConfigFile(config, outputDir)
|
||||
err = writeBackendServerConfigFile(config, outputDir)
|
||||
if err == nil {
|
||||
err = writeBackendClientConfigFile(config, outputDir)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -262,17 +280,42 @@ func writeTemplate(path string, info os.FileInfo, templ *template.Template, conf
|
|||
return nil
|
||||
}
|
||||
|
||||
func writeBackendConfigFile(config *Config, outputDir string) error {
|
||||
out, err := os.OpenFile(filepath.Join(outputDir, "backend/backend.conf"), os.O_CREATE|os.O_WRONLY, 0644)
|
||||
func writeBackendServerConfigFile(config *Config, outputDir string) error {
|
||||
out, err := os.OpenFile(filepath.Join(outputDir, "backend/server.conf"), os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if config.Backend.ConfigFile == "" {
|
||||
if config.Backend.ServerConfigFile == "" {
|
||||
return nil
|
||||
} else {
|
||||
in, err := os.Open(filepath.Join(outputDir, "backend/config", config.Backend.ConfigFile))
|
||||
in, err := os.Open(filepath.Join(outputDir, "backend/config", config.Backend.ServerConfigFile))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer in.Close()
|
||||
|
||||
_, err = io.Copy(out, in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeBackendClientConfigFile(config *Config, outputDir string) error {
|
||||
out, err := os.OpenFile(filepath.Join(outputDir, "backend/client.conf"), os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer out.Close()
|
||||
|
||||
if config.Backend.ClientConfigFile == "" {
|
||||
return nil
|
||||
} else {
|
||||
in, err := os.Open(filepath.Join(outputDir, "backend/config", config.Backend.ClientConfigFile))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf"
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf"
|
||||
},
|
||||
"blockbook": {
|
||||
"package_name": "blockbook-bcash",
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf"
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf"
|
||||
},
|
||||
"blockbook": {
|
||||
"package_name": "blockbook-bcash-testnet",
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"mempoolexpiry": 72,
|
||||
"timeout": 768,
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin.conf",
|
||||
"client_config_file": "bitcoin_client.conf",
|
||||
"additional_params": {
|
||||
"deprecatedrpc": "estimatefee"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin.conf",
|
||||
"client_config_file": "bitcoin_client.conf",
|
||||
"additional_params": {
|
||||
"deprecatedrpc": "estimatefee"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"mempoolexpiry": 72
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"mempoolexpiry": 72
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": false,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1",
|
||||
"rpcthreads": 16,
|
||||
|
|
|
@ -32,7 +32,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": ""
|
||||
"server_config_file": "",
|
||||
"client_config_file": ""
|
||||
},
|
||||
"blockbook": {
|
||||
"package_name": "blockbook-ethereum-classic",
|
||||
|
|
|
@ -34,7 +34,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": ""
|
||||
"server_config_file": "",
|
||||
"client_config_file": ""
|
||||
},
|
||||
"blockbook": {
|
||||
"package_name": "blockbook-ethereum",
|
||||
|
|
|
@ -33,7 +33,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": ""
|
||||
"server_config_file": "",
|
||||
"client_config_file": ""
|
||||
},
|
||||
"blockbook": {
|
||||
"package_name": "blockbook-ethereum-testnet-ropsten",
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1",
|
||||
"upnp": 0,
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
"service_additional_params_template": "",
|
||||
"protect_memory": true,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"whitelist": "127.0.0.1"
|
||||
}
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
"service_additional_params_template": "Environment=\"HOME={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend\"",
|
||||
"protect_memory": false,
|
||||
"mainnet": true,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"addnode": [
|
||||
"mainnet.z.cash"
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
"service_additional_params_template": "Environment=\"HOME={{.Env.BackendDataPath}}/{{.Coin.Alias}}/backend\"",
|
||||
"protect_memory": false,
|
||||
"mainnet": false,
|
||||
"config_file": "bitcoin.conf",
|
||||
"server_config_file": "bitcoin_like.conf",
|
||||
"client_config_file": "bitcoin_like_client.conf",
|
||||
"additional_params": {
|
||||
"addnode": [
|
||||
"testnet.z.cash"
|
||||
|
|
Loading…
Reference in New Issue