WIP: need to develop website further
This commit is contained in:
parent
4294636641
commit
2e237a0518
4
.gitignore
vendored
4
.gitignore
vendored
@ -3,3 +3,7 @@ images
|
|||||||
|
|
||||||
# go checksums
|
# go checksums
|
||||||
go.sum
|
go.sum
|
||||||
|
|
||||||
|
# executable
|
||||||
|
ffrs-fw-dl
|
||||||
|
ffrs-fw-dl.exe
|
||||||
|
@ -17,29 +17,65 @@ manufacturers:
|
|||||||
prettyname: Aerohive
|
prettyname: Aerohive
|
||||||
- name: alfa-network
|
- name: alfa-network
|
||||||
prettyname: Alfa
|
prettyname: Alfa
|
||||||
|
- name: allnet
|
||||||
|
prettyname: ALLNET
|
||||||
|
- name: aruba
|
||||||
|
prettyname: Aruba
|
||||||
|
- name: asus
|
||||||
|
prettyname: ASUS
|
||||||
|
- name: avm
|
||||||
|
prettyname: AVM
|
||||||
- name: buffalo
|
- name: buffalo
|
||||||
prettyname: Buffalo
|
prettyname: Buffalo
|
||||||
- name: d-link
|
- name: d-link
|
||||||
prettyname: D-Link
|
prettyname: D-Link
|
||||||
|
- name: devolo
|
||||||
|
prettyname: Devolo
|
||||||
|
- name: enterasys
|
||||||
|
prettyname: Enterasys Networks
|
||||||
- name: gl-inet
|
- name: gl-inet
|
||||||
prettyname: GL-Inet
|
prettyname: GL Technologies
|
||||||
|
- name: gl.inet
|
||||||
|
prettyname: GL Technologies
|
||||||
|
- name: gl
|
||||||
|
prettyname: GL Technologies
|
||||||
- name: lemaker
|
- name: lemaker
|
||||||
prettyname: LeMaker
|
prettyname: LeMaker
|
||||||
- name: linksys
|
- name: linksys
|
||||||
prettyname: Linksys
|
prettyname: Linksys
|
||||||
|
- name: meraki
|
||||||
|
prettyname: Meraki
|
||||||
- name: netgear
|
- name: netgear
|
||||||
prettyname: Netgear
|
prettyname: Netgear
|
||||||
- name: nexx
|
- name: nexx
|
||||||
prettyname: Nexx
|
prettyname: Nexx
|
||||||
|
- name: ocedo
|
||||||
|
prettyname: Ocedo
|
||||||
|
- name: onion
|
||||||
|
prettyname: Onion Corporation
|
||||||
- name: openmesh
|
- name: openmesh
|
||||||
prettyname: Openmesh
|
prettyname: Openmesh
|
||||||
- name: raspberrypi
|
- name: raspberrypi
|
||||||
prettyname: Raspberry Pi
|
prettyname: Raspberry Pi
|
||||||
|
- name: raspberry
|
||||||
|
prettyname: Raspberry Pi
|
||||||
- name: tp-link
|
- name: tp-link
|
||||||
prettyname: TP-Link
|
prettyname: TP-Link
|
||||||
- name: ubiquiti
|
- name: ubiquiti
|
||||||
prettyname: Ubiquiti
|
prettyname: Ubiquiti
|
||||||
|
- name: ubnt
|
||||||
|
prettyname: Ubiquiti
|
||||||
|
- name: vocore
|
||||||
|
prettyname: VoCore
|
||||||
|
- name: vocore2
|
||||||
|
prettyname: VoCore
|
||||||
|
- name: wd
|
||||||
|
prettyname: Western Digital
|
||||||
- name: x86
|
- name: x86
|
||||||
prettyname: x86
|
prettyname: x86
|
||||||
|
- name: xiaomi
|
||||||
|
prettyname: Xiaomi
|
||||||
|
- name: zbt
|
||||||
|
prettyname: ZBT
|
||||||
- name: zyxel
|
- name: zyxel
|
||||||
prettyname: Zyxel
|
prettyname: Zyxel
|
||||||
|
127
main.go
127
main.go
@ -1,21 +1,55 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"text/template"
|
||||||
|
|
||||||
"git.nils.zone/nils/prettify"
|
"git.nils.zone/nils/prettify"
|
||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// constants
|
||||||
|
const (
|
||||||
|
//root = "/srv/fwuploads/"
|
||||||
|
root = "./images/"
|
||||||
|
)
|
||||||
|
|
||||||
// structs
|
// 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 {
|
type firmware struct {
|
||||||
|
Community string
|
||||||
|
domain string
|
||||||
Hersteller string
|
Hersteller string
|
||||||
Modell string
|
Modell string
|
||||||
Version string
|
Version string
|
||||||
@ -43,15 +77,26 @@ type assignments struct {
|
|||||||
Manufacturers []manufacturer `json:"manufacturers"`
|
Manufacturers []manufacturer `json:"manufacturers"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type data struct {
|
||||||
|
Name string
|
||||||
|
Title string
|
||||||
|
Body string
|
||||||
|
Skills skills
|
||||||
|
}
|
||||||
|
|
||||||
|
type skills []struct {
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
// global variables
|
// global variables
|
||||||
var branches = []string{"stable", "beta", "experimental"}
|
var branches = []string{"stable", "beta", "experimental"}
|
||||||
var installMethod = []string{"sysupgrade", "factory"}
|
var installMethod = []string{"sysupgrade", "factory"}
|
||||||
var community string
|
var community string
|
||||||
var domains []string
|
var domains []string
|
||||||
var prefix = ""
|
|
||||||
var assign assignments
|
var assign assignments
|
||||||
var currentBranch string // holds info of the current branch
|
var currentBranch string // holds info of the current branch
|
||||||
var currentMethod string // holds info of the current install method
|
var currentMethod string // holds info of the current install method
|
||||||
|
var firmwares []firmware
|
||||||
|
|
||||||
func stringInSlice(a string, list []string) bool {
|
func stringInSlice(a string, list []string) bool {
|
||||||
for _, b := range list {
|
for _, b := range list {
|
||||||
@ -69,7 +114,8 @@ func getFirmwareImages(folder string) {
|
|||||||
// check if files exist
|
// check if files exist
|
||||||
//fmt.Println(files)
|
//fmt.Println(files)
|
||||||
if files != nil {
|
if files != nil {
|
||||||
getImagePrefix(folder)
|
prefix := getImagePrefix(folder)
|
||||||
|
//fmt.Println(folder)
|
||||||
|
|
||||||
// loop through all files
|
// loop through all files
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
@ -77,15 +123,7 @@ func getFirmwareImages(folder string) {
|
|||||||
if !file.IsDir() {
|
if !file.IsDir() {
|
||||||
// check if file starts with gluon
|
// check if file starts with gluon
|
||||||
if strings.HasPrefix(file.Name(), "gluon") {
|
if strings.HasPrefix(file.Name(), "gluon") {
|
||||||
|
// get Firmware Data for file
|
||||||
//fmt.Println(file.Name())
|
|
||||||
/*
|
|
||||||
path, err := filepath.Abs(file.Name())
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
//getFirmwareData(path, prefix)
|
|
||||||
getFirmwareData(file.Name(), prefix)
|
getFirmwareData(file.Name(), prefix)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,8 +134,9 @@ func getFirmwareImages(folder string) {
|
|||||||
func getFirmwareData(image string, prefix string) {
|
func getFirmwareData(image string, prefix string) {
|
||||||
// create firmware variable
|
// create firmware variable
|
||||||
var fw firmware
|
var fw firmware
|
||||||
//fmt.Println(prefix)
|
//fmt.Println(">" + prefix + "<")
|
||||||
//fmt.Println(image)
|
//fmt.Println(image)
|
||||||
|
//fmt.Println(currentBranch, currentMethod)
|
||||||
|
|
||||||
// set the branch of firmware
|
// set the branch of firmware
|
||||||
fw.Entwicklungsstadium = currentBranch
|
fw.Entwicklungsstadium = currentBranch
|
||||||
@ -109,8 +148,19 @@ func getFirmwareData(image string, prefix string) {
|
|||||||
fw.Modell = strings.Split(image, prefix)[1]
|
fw.Modell = strings.Split(image, prefix)[1]
|
||||||
|
|
||||||
// cut away the extension
|
// 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.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]
|
// 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 {
|
for _, manufacturer := range assign.Manufacturers {
|
||||||
// check if image is from manufacturer
|
// check if image is from manufacturer
|
||||||
@ -134,9 +184,12 @@ func getFirmwareData(image string, prefix string) {
|
|||||||
out = true
|
out = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// assemble new image name (cut away manufacturer)
|
if strings.Contains(fw.Modell, "-") {
|
||||||
fw.Modell = strings.Split(fw.Modell, fw.Hersteller+"-")[1]
|
// assemble new image name (cut away manufacturer)
|
||||||
//fmt.Println(fw.Modell)
|
fw.Modell = strings.Split(fw.Modell, fw.Hersteller+"-")[1]
|
||||||
|
} else {
|
||||||
|
fw.Modell = strings.Split(fw.Modell, fw.Hersteller)[1]
|
||||||
|
}
|
||||||
|
|
||||||
// compile regex for hw revisions
|
// compile regex for hw revisions
|
||||||
r, err := regexp.Compile("(v[0-9]{1,2}$)|([-]*rev-\\w*$)|(-[a-zA-Z][0-9]{0,1}$)")
|
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)
|
log.Println(image)
|
||||||
prettify.Print(fw)
|
prettify.Print(fw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
firmwares = append(firmwares, fw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getSubdirectory(folder string) {
|
func getSubdirectory(folder string) {
|
||||||
@ -196,7 +251,7 @@ func getSubdirectory(folder string) {
|
|||||||
// check if entry is a directory
|
// check if entry is a directory
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
// check if we are at root
|
// check if we are at root
|
||||||
if folder == "./images" {
|
if folder == root {
|
||||||
community = f.Name()
|
community = f.Name()
|
||||||
//fmt.Println(community)
|
//fmt.Println(community)
|
||||||
}
|
}
|
||||||
@ -246,11 +301,18 @@ func getFilesOrFolders(folder string) []os.FileInfo {
|
|||||||
|
|
||||||
func getImagePrefix(folder string) string {
|
func getImagePrefix(folder string) string {
|
||||||
files := getFilesOrFolders(folder)
|
files := getFilesOrFolders(folder)
|
||||||
if prefix == "" {
|
//fmt.Printf("there are %v files in folder %v\n", len(files), folder)
|
||||||
prefix = files[0].Name()
|
var prefix string
|
||||||
}
|
|
||||||
for _, file := range files {
|
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
|
return prefix
|
||||||
}
|
}
|
||||||
@ -280,11 +342,26 @@ func getAssignments() assignments {
|
|||||||
return a
|
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() {
|
func main() {
|
||||||
// get all assignments from file
|
// get all assignments from file
|
||||||
assign = getAssignments()
|
assign = getAssignments()
|
||||||
|
|
||||||
// start script in images folder
|
// start script in images folder
|
||||||
getSubdirectory("./images")
|
getSubdirectory(root)
|
||||||
fmt.Println(branches)
|
//fmt.Println(branches)
|
||||||
|
|
||||||
|
//prettify.Print(assign)
|
||||||
|
startServer()
|
||||||
}
|
}
|
||||||
|
34
tmpl/index.html
Normal file
34
tmpl/index.html
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
<h1>Test</h1>
|
||||||
|
<h2>Firmwares</h2>
|
||||||
|
{{ range . }}
|
||||||
|
{{ .Hersteller }}
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
|
||||||
|
<h1>Test</h1>
|
||||||
|
<h2>Cities range</h2>
|
||||||
|
{{ range .Cities }}
|
||||||
|
<h3>{{ .Name }}</h3>
|
||||||
|
{{ range .Images }}
|
||||||
|
 <b>Name:</b> {{ .Name }}<br>
|
||||||
|
 <b>Prettyname:</b> {{ .Prettyname }}<br>
|
||||||
|
{{ end }}
|
||||||
|
</p>
|
||||||
|
{{ end }}
|
||||||
|
<form>
|
||||||
|
<fieldset>
|
||||||
|
<legend>Select Manufacturer</legend>
|
||||||
|
<p>
|
||||||
|
<label>Select list</label>
|
||||||
|
<select id = "manufacturers">
|
||||||
|
{{ range .Manufacturers }}
|
||||||
|
<option value = "{{ .Name }}">{{ .Name }}</option>
|
||||||
|
{{ end }}
|
||||||
|
</select>
|
||||||
|
</p>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue
Block a user