initialize

This commit is contained in:
eyedeekay
2025-03-17 17:28:29 -04:00
parent 9d1afc0ff7
commit 9e280e92c2
4 changed files with 152 additions and 0 deletions

7
handlers.go Normal file
View File

@ -0,0 +1,7 @@
package jumpserver
import "net/http"
func (j *JumpServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Serve the jump server
}

43
host.go Normal file
View File

@ -0,0 +1,43 @@
package jumpserver
import (
"fmt"
"strings"
"time"
"github.com/go-i2p/i2pkeys"
)
// Hostname is a struct that contains an I2PAddr and a hostname.
// This is used to store the hostnames of the jump server.
type Hostname struct {
*i2pkeys.I2PAddr `json:"i2paddr"` // The I2PAddr of the hostname
time.Time `json:"time"` // The time the hostname was added to the jump server
Registrant `json:"registrant"` // The registrant of the hostname
Hostname string `json:"hostname"` // The hostname of the jump server
}
func (h *Hostname) String() string {
return fmt.Sprintf("%s:%s:%s", h.Hostname, h.I2PAddr.Base32(), h.Registrant)
}
func (h *Hostname) FullSearch(query string) (bool, bool, bool, bool, bool) {
registrar, text, tag := h.Registrant.DataSearch(query)
addr := h.AddrSearch(query)
host := h.HostSearch(query)
return registrar, text, tag, addr, host
}
func (h *Hostname) AddrSearch(query string) bool {
if strings.Contains(h.Base32(), query) {
return true
}
return false
}
func (h *Hostname) HostSearch(query string) bool {
if strings.Contains(h.Hostname, query) {
return true
}
return false
}

63
registrant.go Normal file
View File

@ -0,0 +1,63 @@
package jumpserver
import (
"fmt"
"strings"
)
// Registrant is a struct that contains the type, name and tags of the registrant.
// This is used to store the registrant metadata of the hostname.
type Registrant struct {
Type string `json:"type"` // The type of the registrant, e.g. "user" or "service"
Name string `json:"name"` // The name of the registrant, either the username of the registrant or the hostname of the service
Tags []string `json:"tags"` // The tags of the registry, e.g. "admin", "web", "game" etc.
Description string `json:"description"` // The description of the registrant obtained from the meta-tags provided by the page, if any
}
func (r *Registrant) String() string {
return fmt.Sprintf("%s:%s:%s:%s", r.Type, r.Name, r.Tags, r.Description)
}
func (r *Registrant) ByUser() bool {
if r.Type == "user" {
return true
}
return false
}
func (r *Registrant) ByService() bool {
if r.Type == "service" {
return true
}
return false
}
func (r *Registrant) HasTag(tag string) bool {
for _, t := range r.Tags {
if t == tag {
return true
}
}
return false
}
func (r *Registrant) DataSearch(query string) (bool, bool, bool) {
registrar := r.RegistrarSearch(query)
text := r.TextSearch(query)
tag := r.HasTag(query)
return registrar, text, tag
}
func (r *Registrant) TextSearch(query string) bool {
if strings.Contains(r.Description, query) {
return true
}
return false
}
func (r *Registrant) RegistrarSearch(query string) bool {
if strings.Contains(r.Name, query) {
return true
}
return false
}

39
server.go Normal file
View File

@ -0,0 +1,39 @@
package jumpserver
type JumpServer struct {
Hostnames []*Hostname `json:"hostnames"` // The hostnames of the jump server
}
func (j *JumpServer) AddHostname(h *Hostname) {
j.Hostnames = append(j.Hostnames, h)
}
func (j *JumpServer) RemoveHostname(h *Hostname) {
for i, host := range j.Hostnames {
if host == h {
j.Hostnames = append(j.Hostnames[:i], j.Hostnames[i+1:]...)
}
}
}
type SearchResult struct {
*Hostname
Registrar bool
Text bool
Tag bool
Addr bool
Host bool
}
type SearchResults []*SearchResult
func (j *JumpServer) Search(query string) []*Hostname {
var hosts []*Hostname
for _, host := range j.Hostnames {
registrar, text, tag, addr, hostname := host.FullSearch(query)
if registrar || text || tag || addr || hostname {
hosts = append(hosts, host)
}
}
return hosts
}