From 2e237a051856ec7bcdea7dd8187eac1d03e7a34e Mon Sep 17 00:00:00 2001
From: Nils Jakobi
Date: Mon, 11 May 2020 01:19:55 +0200
Subject: [PATCH] WIP: need to develop website further
---
.gitignore | 4 ++
assignments.yml | 38 ++++++++++++++-
main.go | 127 ++++++++++++++++++++++++++++++++++++++----------
tmpl/index.html | 34 +++++++++++++
4 files changed, 177 insertions(+), 26 deletions(-)
create mode 100644 tmpl/index.html
diff --git a/.gitignore b/.gitignore
index be8c9aa..ef62c30 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,7 @@ images
# go checksums
go.sum
+
+# executable
+ffrs-fw-dl
+ffrs-fw-dl.exe
diff --git a/assignments.yml b/assignments.yml
index 268601c..cac72d0 100644
--- a/assignments.yml
+++ b/assignments.yml
@@ -17,29 +17,65 @@ manufacturers:
prettyname: Aerohive
- name: alfa-network
prettyname: Alfa
+ - name: allnet
+ prettyname: ALLNET
+ - name: aruba
+ prettyname: Aruba
+ - name: asus
+ prettyname: ASUS
+ - name: avm
+ prettyname: AVM
- name: buffalo
prettyname: Buffalo
- name: d-link
prettyname: D-Link
+ - name: devolo
+ prettyname: Devolo
+ - name: enterasys
+ prettyname: Enterasys Networks
- name: gl-inet
- prettyname: GL-Inet
+ prettyname: GL Technologies
+ - name: gl.inet
+ prettyname: GL Technologies
+ - name: gl
+ prettyname: GL Technologies
- name: lemaker
prettyname: LeMaker
- name: linksys
prettyname: Linksys
+ - name: meraki
+ prettyname: Meraki
- name: netgear
prettyname: Netgear
- name: nexx
prettyname: Nexx
+ - name: ocedo
+ prettyname: Ocedo
+ - name: onion
+ prettyname: Onion Corporation
- name: openmesh
prettyname: Openmesh
- name: raspberrypi
prettyname: Raspberry Pi
+ - name: raspberry
+ prettyname: Raspberry Pi
- name: tp-link
prettyname: TP-Link
- name: ubiquiti
prettyname: Ubiquiti
+ - name: ubnt
+ prettyname: Ubiquiti
+ - name: vocore
+ prettyname: VoCore
+ - name: vocore2
+ prettyname: VoCore
+ - name: wd
+ prettyname: Western Digital
- name: x86
prettyname: x86
+ - name: xiaomi
+ prettyname: Xiaomi
+ - name: zbt
+ prettyname: ZBT
- name: zyxel
prettyname: Zyxel
diff --git a/main.go b/main.go
index d29c5f6..227cce5 100644
--- a/main.go
+++ b/main.go
@@ -1,21 +1,55 @@
package main
import (
- "fmt"
"io/ioutil"
"log"
+ "net/http"
"os"
"path/filepath"
"regexp"
"strings"
+ "text/template"
"git.nils.zone/nils/prettify"
"github.com/sergi/go-diff/diffmatchpatch"
"gopkg.in/yaml.v2"
)
+// constants
+const (
+ //root = "/srv/fwuploads/"
+ root = "./images/"
+)
+
// structs
+
+type branch struct {
+ Name string
+}
+
+type method struct {
+ Name string
+ branch []branch
+}
+
+type version struct {
+ Name string
+ method []method
+}
+
+type model struct {
+ Name string
+ Version []version
+}
+
+type vendor struct {
+ Name string
+ Models []model
+}
+
type firmware struct {
+ Community string
+ domain string
Hersteller string
Modell string
Version string
@@ -43,15 +77,26 @@ type assignments struct {
Manufacturers []manufacturer `json:"manufacturers"`
}
+type data struct {
+ Name string
+ Title string
+ Body string
+ Skills skills
+}
+
+type skills []struct {
+ Name string
+}
+
// global variables
var branches = []string{"stable", "beta", "experimental"}
var installMethod = []string{"sysupgrade", "factory"}
var community string
var domains []string
-var prefix = ""
var assign assignments
var currentBranch string // holds info of the current branch
var currentMethod string // holds info of the current install method
+var firmwares []firmware
func stringInSlice(a string, list []string) bool {
for _, b := range list {
@@ -69,7 +114,8 @@ func getFirmwareImages(folder string) {
// check if files exist
//fmt.Println(files)
if files != nil {
- getImagePrefix(folder)
+ prefix := getImagePrefix(folder)
+ //fmt.Println(folder)
// loop through all files
for _, file := range files {
@@ -77,15 +123,7 @@ func getFirmwareImages(folder string) {
if !file.IsDir() {
// check if file starts with gluon
if strings.HasPrefix(file.Name(), "gluon") {
-
- //fmt.Println(file.Name())
- /*
- path, err := filepath.Abs(file.Name())
- if err != nil {
- panic(err)
- }
- */
- //getFirmwareData(path, prefix)
+ // get Firmware Data for file
getFirmwareData(file.Name(), prefix)
}
}
@@ -96,8 +134,9 @@ func getFirmwareImages(folder string) {
func getFirmwareData(image string, prefix string) {
// create firmware variable
var fw firmware
- //fmt.Println(prefix)
+ //fmt.Println(">" + prefix + "<")
//fmt.Println(image)
+ //fmt.Println(currentBranch, currentMethod)
// set the branch of firmware
fw.Entwicklungsstadium = currentBranch
@@ -109,8 +148,19 @@ func getFirmwareData(image string, prefix string) {
fw.Modell = strings.Split(image, prefix)[1]
// cut away the extension
- //fw.Modell = strings.TrimSuffix(fw.Modell, filepath.Ext(fw.Modell)) // this has issues with img.gz use below until we have an image with a "." in it
- fw.Modell = strings.Split(fw.Modell, ".")[0]
+ fw.Modell = strings.TrimSuffix(fw.Modell, filepath.Ext(fw.Modell)) // this has issues with img.gz use below until we have an image with a "." in it
+ // quickfix for .img.gz
+ if filepath.Ext(fw.Modell) == ".img" {
+ // remove .img as well
+ fw.Modell = strings.TrimSuffix(fw.Modell, filepath.Ext(fw.Modell))
+ }
+
+ // remove sysupgrade suffix
+ if strings.HasSuffix(fw.Modell, "-sysupgrade") {
+ fw.Modell = strings.TrimSuffix(fw.Modell, "-sysupgrade")
+ }
+ //fmt.Println(fw.Modell)
+ //fw.Modell = strings.Split(fw.Modell, ".")[0]
for _, manufacturer := range assign.Manufacturers {
// check if image is from manufacturer
@@ -134,9 +184,12 @@ func getFirmwareData(image string, prefix string) {
out = true
}
- // assemble new image name (cut away manufacturer)
- fw.Modell = strings.Split(fw.Modell, fw.Hersteller+"-")[1]
- //fmt.Println(fw.Modell)
+ if strings.Contains(fw.Modell, "-") {
+ // assemble new image name (cut away manufacturer)
+ fw.Modell = strings.Split(fw.Modell, fw.Hersteller+"-")[1]
+ } else {
+ fw.Modell = strings.Split(fw.Modell, fw.Hersteller)[1]
+ }
// compile regex for hw revisions
r, err := regexp.Compile("(v[0-9]{1,2}$)|([-]*rev-\\w*$)|(-[a-zA-Z][0-9]{0,1}$)")
@@ -185,6 +238,8 @@ func getFirmwareData(image string, prefix string) {
log.Println(image)
prettify.Print(fw)
}
+
+ firmwares = append(firmwares, fw)
}
func getSubdirectory(folder string) {
@@ -196,7 +251,7 @@ func getSubdirectory(folder string) {
// check if entry is a directory
if f.IsDir() {
// check if we are at root
- if folder == "./images" {
+ if folder == root {
community = f.Name()
//fmt.Println(community)
}
@@ -246,11 +301,18 @@ func getFilesOrFolders(folder string) []os.FileInfo {
func getImagePrefix(folder string) string {
files := getFilesOrFolders(folder)
- if prefix == "" {
- prefix = files[0].Name()
- }
+ //fmt.Printf("there are %v files in folder %v\n", len(files), folder)
+ var prefix string
for _, file := range files {
- prefix = diffStrings(file.Name(), prefix)
+ // check if file starts with gluon
+ if strings.HasPrefix(file.Name(), "gluon") {
+ // set prefix as file name first
+ if prefix == "" {
+ prefix = file.Name()
+ }
+ // diff the prefix until it is correct
+ prefix = diffStrings(file.Name(), prefix)
+ }
}
return prefix
}
@@ -280,11 +342,26 @@ func getAssignments() assignments {
return a
}
+func handler(w http.ResponseWriter, r *http.Request) {
+ t, _ := template.ParseFiles("tmpl/index.html")
+
+ //t.Execute(w, assign)
+ t.Execute(w, firmwares)
+}
+
+func startServer() {
+ http.HandleFunc("/", handler)
+ http.ListenAndServe(":8080", nil)
+}
+
func main() {
// get all assignments from file
assign = getAssignments()
// start script in images folder
- getSubdirectory("./images")
- fmt.Println(branches)
+ getSubdirectory(root)
+ //fmt.Println(branches)
+
+ //prettify.Print(assign)
+ startServer()
}
diff --git a/tmpl/index.html b/tmpl/index.html
new file mode 100644
index 0000000..eb9a084
--- /dev/null
+++ b/tmpl/index.html
@@ -0,0 +1,34 @@
+
+
+ Test
+ Firmwares
+ {{ range . }}
+ {{ .Hersteller }}
+ {{ end }}
+
+
+ Test
+ Cities range
+ {{ range .Cities }}
+ {{ .Name }}
+ {{ range .Images }}
+ Name: {{ .Name }}
+ Prettyname: {{ .Prettyname }}
+ {{ end }}
+
+ {{ end }}
+
+
+
\ No newline at end of file