| @@ -6,4 +6,10 @@ type Article struct { | ||
| Header map[string][]string | ||
| Text string | ||
| Attachments []Attachment | ||
| MessageID string | ||
| Newsgroup string | ||
| Reference string | ||
| Path string | ||
| Posted int64 | ||
| Addr string | ||
| } | ||
| @@ -4,4 +4,5 @@ type Attachment struct { | ||
| Path string | ||
| Name string | ||
| Mime string | ||
| Hash string | ||
| } | ||
| @@ -1,4 +1,8 @@ | ||
| package model | ||
|
|
||
| type BoardPage struct { | ||
| Board string | ||
| Page int | ||
| Pages int | ||
| Threads []Thread | ||
| } |
| @@ -1,4 +1,26 @@ | ||
| package model | ||
|
|
||
| type Post struct { | ||
| Board string | ||
| PostName string | ||
| PostSubject string | ||
| PostMessage string | ||
| message_rendered string | ||
| Message_id string | ||
| MessagePath string | ||
| Addr string | ||
| OP bool | ||
| Posted int64 | ||
| Parent string | ||
| Sage bool | ||
| Key string | ||
| Files []*Attachment | ||
| HashLong string | ||
| HashShort string | ||
| URL string | ||
| Tripcode string | ||
| BodyMarkup string | ||
| PostMarkup string | ||
| PostPrefix string | ||
| index int | ||
| } |
| @@ -1,4 +1,6 @@ | ||
| package model | ||
|
|
||
| type Thread struct { | ||
| Root *Post | ||
| Replies []*Post | ||
| } |
| @@ -85,4 +85,3 @@ func GetFilenameForHistory(webroot_dir string) string { | ||
| func GetFilenameForUkko(webroot_dir string) string { | ||
| return filepath.Join(webroot_dir, "ukko.html") | ||
| } | ||
| @@ -0,0 +1,91 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "encoding/base64" | ||
| "fmt" | ||
| "github.com/majestrate/srndv2/lib/crypto/nacl" | ||
| "log" | ||
| "net" | ||
| ) | ||
|
|
||
| // given an address | ||
| // generate a new encryption key for it | ||
| // return the encryption key and the encrypted address | ||
| func NewAddrEnc(addr string) (string, string) { | ||
| key_bytes := nacl.RandBytes(encAddrBytes()) | ||
| key := base64.StdEncoding.EncodeToString(key_bytes) | ||
| return key, EncAddr(addr, key) | ||
| } | ||
|
|
||
| // xor address with a one time pad | ||
| // if the address isn't long enough it's padded with spaces | ||
| func EncAddr(addr, key string) string { | ||
| key_bytes, err := base64.StdEncoding.DecodeString(key) | ||
|
|
||
| if err != nil { | ||
| log.Println("encAddr() key base64 decode", err) | ||
| return "" | ||
| } | ||
|
|
||
| if len(addr) > len(key_bytes) { | ||
| log.Println("encAddr() len(addr) > len(key_bytes)") | ||
| return "" | ||
| } | ||
|
|
||
| // pad with spaces | ||
| for len(addr) < len(key_bytes) { | ||
| addr += " " | ||
| } | ||
|
|
||
| addr_bytes := []byte(addr) | ||
| res_bytes := make([]byte, len(addr_bytes)) | ||
| for idx, b := range key_bytes { | ||
| res_bytes[idx] = addr_bytes[idx] ^ b | ||
| } | ||
|
|
||
| return base64.StdEncoding.EncodeToString(res_bytes) | ||
| } | ||
|
|
||
| // number of bytes to use in otp | ||
| func encAddrBytes() int { | ||
| return 64 | ||
| } | ||
|
|
||
| func IsSubnet(cidr string) (bool, *net.IPNet) { | ||
| _, ipnet, err := net.ParseCIDR(cidr) | ||
| if err == nil { | ||
| return true, ipnet | ||
| } | ||
| return false, nil | ||
| } | ||
|
|
||
| func IPNet2MinMax(inet *net.IPNet) (min, max net.IP) { | ||
| netb := []byte(inet.IP) | ||
| maskb := []byte(inet.Mask) | ||
| maxb := make([]byte, len(netb)) | ||
|
|
||
| for i, _ := range maxb { | ||
| maxb[i] = netb[i] | (^maskb[i]) | ||
| } | ||
| min = net.IP(netb) | ||
| max = net.IP(maxb) | ||
| return | ||
| } | ||
|
|
||
| func ZeroIPString(ip net.IP) string { | ||
| p := ip | ||
|
|
||
| if len(ip) == 0 { | ||
| return "<nil>" | ||
| } | ||
|
|
||
| if p4 := p.To4(); len(p4) == net.IPv4len { | ||
| return fmt.Sprintf("%03d.%03d.%03d.%03d", p4[0], p4[1], p4[2], p4[3]) | ||
| } | ||
| if len(p) == net.IPv6len { | ||
| //>IPv6 | ||
| //ishygddt | ||
| return fmt.Sprintf("[%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]", p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]) | ||
| } | ||
| return "?" | ||
| } |
| @@ -0,0 +1,29 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "crypto/sha512" | ||
| "encoding/base64" | ||
| "encoding/hex" | ||
| "github.com/majestrate/srndv2/lib/crypto/nacl" | ||
| ) | ||
|
|
||
| // generate a login salt for nntp users | ||
| func GenLoginCredSalt() (salt string) { | ||
| salt = randStr(128) | ||
| return | ||
| } | ||
|
|
||
| // do nntp login credential hash given password and salt | ||
| func NntpLoginCredHash(passwd, salt string) (str string) { | ||
| var b []byte | ||
| b = append(b, []byte(passwd)...) | ||
| b = append(b, []byte(salt)...) | ||
| h := sha512.Sum512(b) | ||
| str = base64.StdEncoding.EncodeToString(h[:]) | ||
| return | ||
| } | ||
|
|
||
| // make a random string | ||
| func randStr(length int) string { | ||
| return hex.EncodeToString(nacl.RandBytes(length))[length:] | ||
| } |
| @@ -0,0 +1,8 @@ | ||
| package util | ||
|
|
||
| import "strings" | ||
|
|
||
| func IsSage(str string) bool { | ||
| str = strings.ToLower(str) | ||
| return str == "sage" || strings.HasPrefix(str, "sage ") | ||
| } |
| @@ -0,0 +1,8 @@ | ||
| package util | ||
|
|
||
| import "time" | ||
|
|
||
| // time for right now as int64 | ||
| func TimeNow() int64 { | ||
| return time.Now().UTC().Unix() | ||
| } |