First working backend implementation
This commit is contained in:
parent
c44a18acb3
commit
c6bf995d81
|
@ -5,8 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
const HostExpirationSeconds int = 10 * 24 * 60 * 60 // 10 Days
|
const HostExpirationSeconds int = 10 * 24 * 60 * 60 // 10 Days
|
||||||
|
@ -78,5 +78,5 @@ func (self *Host) IsIPv4() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
return False
|
return false
|
||||||
}
|
}
|
||||||
|
|
40
ddns.go
40
ddns.go
|
@ -1,12 +1,14 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/pboehm/ddns/connection"
|
"github.com/pboehm/ddns/connection"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func HandleErr(err error) {
|
func HandleErr(err error) {
|
||||||
|
@ -16,7 +18,43 @@ func HandleErr(err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunBackend() {
|
func RunBackend() {
|
||||||
/* code */
|
conn := connection.OpenConnection()
|
||||||
|
defer conn.Close()
|
||||||
|
|
||||||
|
fmt.Printf("OK\tDDNS Go Backend\n")
|
||||||
|
|
||||||
|
bio := bufio.NewReader(os.Stdin)
|
||||||
|
|
||||||
|
for {
|
||||||
|
line, _, err := bio.ReadLine()
|
||||||
|
HandleErr(err)
|
||||||
|
|
||||||
|
parts := strings.Split(string(line), "\t")
|
||||||
|
if len(parts) == 6 {
|
||||||
|
query_name := parts[1]
|
||||||
|
fqdn_parts := strings.Split(query_name, ".")
|
||||||
|
|
||||||
|
query_class := parts[2]
|
||||||
|
query_id := parts[4]
|
||||||
|
|
||||||
|
if len(fqdn_parts) > 0 {
|
||||||
|
if conn.HostExist(fqdn_parts[0]) {
|
||||||
|
host := conn.GetHost(fqdn_parts[0])
|
||||||
|
|
||||||
|
record := "A"
|
||||||
|
if !host.IsIPv4() {
|
||||||
|
record = "AAAA"
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("DATA\t%s\t%s\t%s\t10\t%s\t%s\n",
|
||||||
|
query_name, query_class, record, query_id, host.Ip)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("END\n")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func RunWebService() {
|
func RunWebService() {
|
||||||
|
|
Loading…
Reference in New Issue