commit 842b2ad9472334063fd73a77c7d3ef18b61a9e67 Author: alyx Date: Wed Aug 11 05:51:25 2021 -0500 Initial commit. Generator works, maybe the actions will diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..48c4cff --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,27 @@ +name: Publish Site +on: [ push ] +env: + MELI_SITE: "16bce269-25b6-4b78-9839-38cb12ef4236" +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '12' + - uses: actions/setup-go@v2 + - name: "build" + run: go run main.go + - name: "publish" + run: | + npx -p "@getmeli/cli" meli upload ./public \ + --url "https://pages.qa" \ + --site "$MELI_SITE" \ + --token "$MELI_TOKEN" \ + --release "$GITHUB_SHA" + env: + MELI_TOKEN: ${{ secrets.MELI_TOKEN }} + # Enable PR previews: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..46f5006 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +public/* diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..bc685ab --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/alyx/cwssg + +go 1.16 + +require golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0db5138 --- /dev/null +++ b/go.sum @@ -0,0 +1,7 @@ +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d h1:20cMwl2fHAzkJMEA+8J4JgqBQcQGzbisXo31MIeenXI= +golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/main.go b/main.go new file mode 100644 index 0000000..6c6c5fe --- /dev/null +++ b/main.go @@ -0,0 +1,129 @@ +package main + +import ( + "encoding/json" + "fmt" + "html/template" + "io/ioutil" + "net" + "net/http" + "os" + "strconv" + "strings" + + "golang.org/x/net/publicsuffix" +) + +type WebLink struct { + Name string + URL string +} + +type TemplateData struct { + Links []*Server + //Sites []WebLink + //Webchats []WebLink + /* I'll make these work eventually lol */ +} + +type Server struct { + Name string + UpstreamServerName string + UpstreamServer *Server + HopCount int + Info string +} + +func (s *Server) String() string { + return fmt.Sprintf("%q -> %q (%p) (%d) %s", s.Name, s.UpstreamServerName, s.UpstreamServer, s.HopCount, s.Info) +} + +func main() { + var activeServers []*Server + resp, err := http.Get("https://plas.netsplit.nl/data/api/v1/links") + if err != nil { + panic(err) + } + + data, err := ioutil.ReadAll(resp.Body) + if err != nil { + panic(err) + } + + res := ParseJSON(data) + for _, s := range res { + //fmt.Println(s) + eTLD, icann := publicsuffix.PublicSuffix(s.Name) + if icann || strings.IndexByte(eTLD, '.') >= 0 { + _, err := net.LookupIP(s.Name) + if err == nil { + activeServers = append(activeServers, s) + } + } + } + + f := makeFolderAndFile() + defer f.Close() + + tmpl := template.Must(template.ParseFiles("template.html")) + tmpl.Execute(f, &TemplateData{Links: activeServers}) +} + +func makeFolderAndFile() *os.File { + if _, err := os.Stat("./public"); os.IsNotExist(err) { + os.Mkdir("./public", os.ModeDir|0755) + } + f, err := os.OpenFile("./public/index.html", os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0600) + if err != nil { + panic(err) + } + + return f +} + +func ParseJSON(data []byte) []*Server { + type GrossServerBase struct { + Name string `json:"server_name"` + UpstreamName string `json:"upstream_server_name"` + HopCount string `json:"hop_count"` + Info string `json:"info"` + } + var temp struct { + Links map[string]GrossServerBase `json:"links"` + } + + if err := json.Unmarshal(data, &temp); err != nil { + panic(err) + } + out := make([]*Server, 0, len(temp.Links)) + + for n, s := range temp.Links { + hopCount, err := strconv.Atoi(s.HopCount) + if err != nil { + fmt.Fprintln(os.Stderr, "Unexpected error while parsing hopcount: ", err) + hopCount = -1 + } + realServer := &Server{ + Name: s.Name, + UpstreamServerName: s.UpstreamName, + UpstreamServer: nil, + HopCount: hopCount, + Info: s.Info, + } + out = append(out, realServer) + if n != s.Name { + fmt.Fprintf(os.Stderr, "Server names are unexpectedly nonequal: %s != %s\n", n, s.Name) + } + } + + for _, s := range out { + for _, other := range out { + if s.UpstreamServerName == other.Name { + s.UpstreamServer = other + break + } + } + } + + return out +} diff --git a/template.html b/template.html new file mode 100644 index 0000000..0628f31 --- /dev/null +++ b/template.html @@ -0,0 +1,58 @@ + + + + +COLD WET CHATS + + + + +
+
+
+ +
+Tower of Piss +
+in alpha +
+
+Other pissnet sites +
+
+pissnet (mirror) | Impeerialfamily | OpenPiss +
+
+Jabber +
+#pissnet@xmppiss.eta.st +
+
+Pissnet Servers +
+
+Webchats +
+qwebirc | thelounge +
+
+ +Servers +
+
+Round Robin: irc.letspiss.net +
+
+{{range .Links}} +{{.Name}} +
+{{end}} +
+
+
+ + + +