A couple of minor changes
This commit is contained in:
@@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/thequux/pdns-auto-update/common"
|
||||
"github.com/thequux/qddns/common"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
@@ -16,6 +16,7 @@ var domain = flag.String("domain", "", "The domain to update")
|
||||
var token = flag.String("token", "", "The authorization token")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
req, err := http.NewRequest("POST", *server+"/update/"+*domain, strings.NewReader(""))
|
||||
|
||||
if err != nil {
|
||||
@@ -26,10 +27,12 @@ func main() {
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stdout, "Failed to send request: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to read response")
|
||||
os.Exit(1)
|
||||
}
|
||||
rj := common.Response{}
|
||||
json.Unmarshal(body, &rj)
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/jackc/pgx/v4/pgxpool"
|
||||
"github.com/thequux/pdns-auto-update/common"
|
||||
"github.com/thequux/qddns/common"
|
||||
_ "go.uber.org/zap"
|
||||
"net"
|
||||
"net/http"
|
||||
@@ -18,7 +18,7 @@ var db *pgxpool.Pool
|
||||
func main() {
|
||||
conn, err := pgxpool.Connect(context.Background(), os.Getenv("QDDNS_DB"))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Unabled to connect to database: %v")
|
||||
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v")
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close()
|
||||
@@ -28,7 +28,7 @@ func main() {
|
||||
r := gin.Default()
|
||||
r.POST("/update/:domain", func(c *gin.Context) {
|
||||
authHdr := strings.Fields(c.GetHeader("Authorization"))
|
||||
domain := c.Param("domain");
|
||||
domain := c.Param("domain")
|
||||
|
||||
clientIP := c.ClientIP()
|
||||
ip := net.ParseIP(clientIP)
|
||||
@@ -54,7 +54,7 @@ func main() {
|
||||
return
|
||||
}
|
||||
// check token validity
|
||||
row := tx.QueryRow(c, "SELECT COUNT(*) from qddns_auth WHERE token = $1 AND domain = $2", token, domain);
|
||||
row := tx.QueryRow(c, "SELECT COUNT(*) from qddns_auth WHERE token = $1 AND domain = $2", token, domain)
|
||||
var rcount int
|
||||
if err := row.Scan(&rcount); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, common.Response{Status: "error", Message: "Failed to check token " + err.Error(), Code: "QDE0002"})
|
||||
|
||||
42
flake.lock
generated
Normal file
42
flake.lock
generated
Normal file
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"nodes": {
|
||||
"flake-utils": {
|
||||
"locked": {
|
||||
"lastModified": 1656928814,
|
||||
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1659526864,
|
||||
"narHash": "sha256-XFzXrc1+6DZb9hBgHfEzfwylPUSqVFJbQPs8eOgYufU=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "478f3cbc8448b5852539d785fbfe9a53304133be",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"ref": "nixos-22.05",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"flake-utils": "flake-utils",
|
||||
"nixpkgs": "nixpkgs"
|
||||
}
|
||||
}
|
||||
},
|
||||
"root": "root",
|
||||
"version": 7
|
||||
}
|
||||
12
flake.nix
12
flake.nix
@@ -8,7 +8,17 @@
|
||||
pname = "qddns";
|
||||
version = "1.0";
|
||||
src = ./.;
|
||||
vendorSha256 = "";
|
||||
vendorSha256 = "sha256-B8OGkL5tortYmdgUD4K5CYUSMgj4T1wFkRhGllsKy60=";
|
||||
|
||||
preferLocalBuild = true;
|
||||
};
|
||||
apps.qddns-server = {
|
||||
type = "app";
|
||||
program = "${defaultPackage}/bin/qddns-server";
|
||||
};
|
||||
apps.qddns-client = {
|
||||
type = "app";
|
||||
program = "${defaultPackage}/bin/qddns-client";
|
||||
};
|
||||
devShells.default = pkgs.mkShell {
|
||||
nativeBuildInputs = [
|
||||
|
||||
Reference in New Issue
Block a user