Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Application struct {
func new() *Application {
app = &Application{}
app.Name = "Patchouli"
app.Version = "0.3.0"
app.Version = "0.3.1"
app.Author = "Philipp Speck <[email protected]>"
app.Description = "Patch Management Planner"
err := app.LoadConfig()
Expand Down
2 changes: 2 additions & 0 deletions app/handler/machine/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/typomedia/patchouli/app"
"github.com/typomedia/patchouli/app/helper"
"github.com/typomedia/patchouli/app/store/boltdb"
"github.com/typomedia/patchouli/app/structs"
)
Expand Down Expand Up @@ -32,5 +33,6 @@ func Edit(c *fiber.Ctx) error {

return c.Render("app/views/machine/edit", fiber.Map{
"Machine": machine,
"Referer": helper.Referer(c),
})
}
8 changes: 7 additions & 1 deletion app/handler/machine/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ func New(c *fiber.Ctx) error {
db := boltdb.New()
db.SetBucket("machine")

config, err := db.GetConfig()
if err != nil {
return err
}
defer db.Close()

return c.Render("app/views/machine/new", fiber.Map{})
return c.Render("app/views/machine/new", fiber.Map{
"Config": config,
})
}
11 changes: 10 additions & 1 deletion app/handler/machine/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/typomedia/patchouli/app/helper"
"github.com/typomedia/patchouli/app/store/boltdb"
"github.com/typomedia/patchouli/app/structs"
"net/url"
)

func Save(c *fiber.Ctx) error {
Expand Down Expand Up @@ -43,6 +44,14 @@ func Save(c *fiber.Ctx) error {

machine := structs.Machine{}
helper.DecodeQuery(request, &machine)

values, _ := url.ParseQuery(request)
if values.Get("internet_access") == "on" {
machine.InternetAccess = true
} else {
machine.InternetAccess = false
}

machine.Id = id
machine.System = system
machine.Operator = operator
Expand All @@ -51,5 +60,5 @@ func Save(c *fiber.Ctx) error {

defer db.Close()

return c.Redirect("/machine")
return c.Redirect(values.Get("_referer"))
}
10 changes: 10 additions & 0 deletions app/helper/helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper

import (
"github.com/gofiber/fiber/v2"
"net/url"
"strconv"
"time"
Expand Down Expand Up @@ -42,3 +43,12 @@ func UnixToDate(timestamp string) time.Time {
i, _ := strconv.ParseInt(timestamp, 10, 64)
return time.Unix(i, 0)
}

func Referer(c *fiber.Ctx) string {
referer := c.GetReqHeaders()["Referer"][0]
refUrl, err := url.Parse(referer)
if err != nil {
return ""
}
return refUrl.Path
}
4 changes: 3 additions & 1 deletion app/store/boltdb/boltdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"go.etcd.io/bbolt"
)

const INTERVAL_WARNING_DIVISOR = 30

var Config = bbolt.Options{
Timeout: 1 * time.Second,
}
Expand Down Expand Up @@ -265,7 +267,7 @@ func (bolt *Bolt) GetActiveMachines() (structs.Machines, error) {

Machines[i].Days = interval - int(currentDate.Sub(date).Hours()/24)

if Machines[i].Days <= interval/3 && Machines[i].Days > 0 {
if Machines[i].Days <= interval/INTERVAL_WARNING_DIVISOR && Machines[i].Days > 0 {
Machines[i].Status = "warning"
} else if Machines[i].Days <= interval && Machines[i].Days > 0 {
Machines[i].Status = "success"
Expand Down
31 changes: 16 additions & 15 deletions app/structs/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ func (a ByDate) Less(i, j int) bool {
}

type Machine struct {
Id string `json:"id"`
Name string `json:"name"`
System System `json:"system"`
Location string `json:"location"`
Ip string `json:"ip"`
Fqdn string `json:"fqdn"`
Service string `json:"service"`
Comment string `json:"comment"`
Backup string `json:"backup"`
Operator Operator `json:"operator"`
Update Update `json:"update"` // last update
Days int `json:"days"` // remaining days
Status string `json:"status"` // status color
Inactive bool `json:"inactive"`
Interval int `json:"interval"`
Id string `json:"id"`
Name string `json:"name"`
System System `json:"system"`
Location string `json:"location"`
Ip string `json:"ip"`
Fqdn string `json:"fqdn"`
Service string `json:"service"`
Comment string `json:"comment"`
Backup string `json:"backup"`
Operator Operator `json:"operator"`
Update Update `json:"update"` // last update
Days int `json:"days"` // remaining days
Status string `json:"status"` // status color
Inactive bool `json:"inactive"`
Interval int `json:"interval"`
InternetAccess bool `json:"internet_access"`
}
14 changes: 13 additions & 1 deletion app/views/dashboard/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@
{{ .System.Name }}
</td>
<td>{{ .Ip }}</td>
<td>{{ .Fqdn }}</td>
<td>
{{ if .InternetAccess }}
<em
data-tooltip="{{ .Name }} is accessible from the web">
<i class="ri-global-line has-access"></i>
</em>

{{ else }}
<i class="ri-global-line"></i>
{{ end }}

{{ .Fqdn }}
</td>
{{ if .Operator.Email }}
<td><i class="ri-menu-search-line"></i> <a href="/filter/operator/{{ .Operator.Id}}">{{ .Operator.Name }}</a></td>
{{ else }}
Expand Down
11 changes: 11 additions & 0 deletions app/views/machine/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
<div class="container">
<form action="/machine/save/{{.Machine.Id}}" method="post" id="edit">
<input type="hidden" name="_method" value="PATCH">
<input type="hidden" name="_referer" value="{{.Referer}}">
<input type="hidden" name="inactive" value="{{.Machine.Inactive}}">
<div>
<div>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="{{.Machine.Name}}" required>
</div>
<div>
<label for="internet_access">
{{ if .Machine.InternetAccess }}
<input type="checkbox" id="internet_access" name="internet_access" role="switch" checked="checked">
{{ else }}
<input type="checkbox" id="internet_access" name="internet_access" role="switch">
{{ end }}
accessible from web
</label>
</div>
<div>
<label for="interval">Interval</label>
<input type="text" name="interval" id="interval" value="{{.Machine.Interval}}">
Expand Down
14 changes: 13 additions & 1 deletion app/views/machine/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,19 @@
{{ .System.Name }}
</td>
<td>{{ .Ip }}</td>
<td>{{ .Fqdn }}</td>
<td>
{{ if .InternetAccess }}
<em
data-tooltip="{{ .Name }} is accessible from the web">
<i class="ri-global-line has-access"></i>
</em>

{{ else }}
<i class="ri-global-line"></i>
{{ end }}

{{ .Fqdn }}
</td>
<td>{{ .Interval }}</td>
{{if .Operator.Email}}
<td><i class="ri-menu-search-line"></i> <a href="/machine/filter/operator/{{ .Operator.Id}}">{{ .Operator.Name }}</a></td>
Expand Down
10 changes: 8 additions & 2 deletions app/views/machine/new.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@
<label for="name">Name</label>
<input type="text" name="name" id="name" value="{{.Machine.Name}}" required>
</div>
<div>
<label for="internet_access">
<input type="checkbox" id="internet_access" name="internet_access" role="switch">
accessible from web
</label>
</div>
<div>
<label for="interval">Interval</label>
<input type="text" name="interval" id="interval" value="{{.Machine.Interval}}">
<input type="text" name="interval" id="interval" value="{{.Config.General.Interval}}">
</div>
<div>
<label for="system">System</label>
Expand All @@ -25,7 +31,7 @@
</div>
<div>
<label for="ip">IP</label>
<input type="text" name="ip" id="ip" value="{{.Machine.Ip}}">
<input type="text" name="ip" id="ip" value="{{.Machine.Ip}}" required>
</div>
<div>
<label for="fqdn">FQDN</label>
Expand Down
19 changes: 9 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,25 @@ go 1.24.1
require (
github.com/XotoX1337/tinymail v0.7.0
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1
github.com/gofiber/fiber/v2 v2.52.6
github.com/gofiber/fiber/v2 v2.52.9
github.com/gofiber/template/html/v2 v2.1.3
github.com/gorilla/schema v1.4.1
github.com/oklog/ulid/v2 v2.1.0
github.com/oklog/ulid/v2 v2.1.1
github.com/robfig/cron/v3 v3.0.1
go.etcd.io/bbolt v1.4.0
go.etcd.io/bbolt v1.4.3
)

require (
github.com/andybalholm/brotli v1.1.0 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/gofiber/template v1.8.3 // indirect
github.com/gofiber/utils v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/klauspost/compress v1.18.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.51.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
golang.org/x/sys v0.29.0 // indirect
github.com/valyala/fasthttp v1.66.0 // indirect
golang.org/x/sys v0.36.0 // indirect
)
41 changes: 20 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
github.com/XotoX1337/tinymail v0.7.0 h1:KvIaWvUSorZTh+DiY/iJfH5P7hjLen2AaWnelIJfY24=
github.com/XotoX1337/tinymail v0.7.0/go.mod h1:eQ8xKUuxppTrCGPkBAtROv20OK1eRw9rsVto9yuwgPY=
github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M=
github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY=
github.com/andybalholm/brotli v1.2.0 h1:ukwgCxwYrmACq68yiUqwIWnGY0cTPox/M94sVwToPjQ=
github.com/andybalholm/brotli v1.2.0/go.mod h1:rzTDkvFWvIrjDXZHkuS16NPggd91W3kUSvPlQ1pLaKY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1 h1:FWNFq4fM1wPfcK40yHE5UO3RUdSNPaBC+j3PokzA6OQ=
github.com/gocarina/gocsv v0.0.0-20240520201108-78e41c74b4b1/go.mod h1:5YoVOkjYAQumqlV356Hj3xeYh4BdZuLE0/nRkf2NKkI=
github.com/gofiber/fiber/v2 v2.52.6 h1:Rfp+ILPiYSvvVuIPvxrBns+HJp8qGLDnLJawAu27XVI=
github.com/gofiber/fiber/v2 v2.52.6/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/fiber/v2 v2.52.9 h1:YjKl5DOiyP3j0mO61u3NTmK7or8GzzWzCFzkboyP5cw=
github.com/gofiber/fiber/v2 v2.52.9/go.mod h1:YEcBbO/FB+5M1IZNBP9FO3J9281zgPAreiI1oqg8nDw=
github.com/gofiber/template v1.8.3 h1:hzHdvMwMo/T2kouz2pPCA0zGiLCeMnoGsQZBTSYgZxc=
github.com/gofiber/template v1.8.3/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
github.com/gofiber/template/html/v2 v2.1.3 h1:n1LYBtmr9C0V/k/3qBblXyMxV5B0o/gpb6dFLp8ea+o=
Expand All @@ -18,39 +18,38 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E=
github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM=
github.com/klauspost/compress v1.17.9 h1:6KIumPrER1LHsvBVuDa0r5xaG0Es51mhhB9BQB2qeMA=
github.com/klauspost/compress v1.17.9/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/oklog/ulid/v2 v2.1.0 h1:+9lhoxAP56we25tyYETBBY1YLA2SaoLvUFgrP2miPJU=
github.com/oklog/ulid/v2 v2.1.0/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/oklog/ulid/v2 v2.1.1 h1:suPZ4ARWLOJLegGFiZZ1dFAkqzhMjL3J1TzI+5wHz8s=
github.com/oklog/ulid/v2 v2.1.1/go.mod h1:rcEKHmBBKfef9DhnvX7y1HZBYxjXb0cP5ExxNsTT1QQ=
github.com/pborman/getopt v0.0.0-20170112200414-7148bc3a4c30/go.mod h1:85jBQOZwpVEaDAr341tbn15RS4fCAsIst0qp7i8ex1o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.51.0 h1:8b30A5JlZ6C7AS81RsWjYMQmrZG6feChmgAolCl1SqA=
github.com/valyala/fasthttp v1.51.0/go.mod h1:oI2XroL+lI7vdXyYoQk03bXBThfFl2cVdIA3Xl7cH8g=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
go.etcd.io/bbolt v1.4.0 h1:TU77id3TnN/zKr7CO/uk+fBCwF2jGcMuw2B/FMAzYIk=
go.etcd.io/bbolt v1.4.0/go.mod h1:AsD+OCi/qPN1giOX1aiLAha3o1U8rAz65bvN4j0sRuk=
github.com/valyala/fasthttp v1.66.0 h1:M87A0Z7EayeyNaV6pfO3tUTUiYO0dZfEJnRGXTVNuyU=
github.com/valyala/fasthttp v1.66.0/go.mod h1:Y4eC+zwoocmXSVCB1JmhNbYtS7tZPRI2ztPB72EVObs=
github.com/xyproto/randomstring v1.0.5 h1:YtlWPoRdgMu3NZtP45drfy1GKoojuR7hmRcnhZqKjWU=
github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E=
go.etcd.io/bbolt v1.4.3 h1:dEadXpI6G79deX5prL3QRNP6JB8UxVkqo4UPnHaNXJo=
go.etcd.io/bbolt v1.4.3/go.mod h1:tKQlpPaYCVFctUIgFKFnAlvbmB3tpy1vkTnDWohtc0E=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
3 changes: 3 additions & 0 deletions public/css/styles.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion public/css/styles.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions public/css/styles.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@color-danger: #ffcccc;
@color-warning: #f8f9c7;
@color-success: #ccfecc;
@color-link: rgb(16, 149, 193);

body {
font-family: @font-family;
Expand Down Expand Up @@ -111,6 +112,10 @@ i.mail-fail {
font-size: 20pt;
}

i.ri-global-line.has-access {
color: @color-link;
}

.btn-danger {
background: #D93526;
}
Expand Down