Skip to content

Commit 7b2a399

Browse files
committed
Update of dependencies and improvements for Debian based distros
Changes: * Add support for FreeBSD * Updated go.mod files * Improved logger.go * Updated dependencies * Fixed systemd service for Debian based distributions * Various other improvements
1 parent 7fed22d commit 7b2a399

12 files changed

+79
-73
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: "Release"
22

33
on:
4-
create:
5-
tags:
6-
- v*
4+
pull_request:
5+
push:
76

87
jobs:
98
build:

.goreleaser.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ builds:
44
- linux
55
- windows
66
- darwin
7+
- freebsd
78
goarch:
89
- amd64
910
- arm64
@@ -27,7 +28,7 @@ nfpms:
2728
homepage: https://github.com/4ndyZ/MAC-API
2829
file_name_template: "{{ tolower .ProjectName }}-{{ tolower .Tag }}.{{ .Os }}.{{ tolower .Arch }}"
2930
license: GPL-3.0
30-
# Build as deb for Debian based distors and rpm for RedHat based distros
31+
# Build as deb for Debian based distributions and rpm for RedHat based distributions
3132
formats:
3233
- deb
3334
- rpm
@@ -41,8 +42,12 @@ nfpms:
4142
owner: root
4243
group: mac-api
4344
# Systemd service file
44-
- src: service/service.service
45+
- src: service/service_deb.service
4546
dst: /usr/lib/systemd/system/mac-api.service
47+
packager: deb
48+
- src: service/service_rpm.service
49+
dst: /usr/lib/systemd/system/mac-api.service
50+
packager: rpm
4651
# Install and remove scripts
4752
scripts:
4853
preinstall: "scripts/preinstall.sh"

LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ state the exclusion of warranty; and each file should have at least
632632
the "copyright" line and a pointer to where the full notice is found.
633633

634634
MAC-API
635-
Copyright (C) 2021-2022 AndyZ (AndyCraftz)
635+
Copyright (C) 2021-2022 Andreas Seidl <AndyZ>
636636

637637
This program is free software: you can redistribute it and/or modify
638638
it under the terms of the GNU General Public License as published by
@@ -652,7 +652,7 @@ Also add information on how to contact you by electronic and paper mail.
652652
If the program does terminal interaction, make it output a short
653653
notice like this when it starts in an interactive mode:
654654

655-
MAC-API Copyright (C) 2021-2022 AndyZ (AndyCraftz)
655+
MAC-API Copyright (C) 2021-2022 Andreas Seidl <AndyZ>
656656
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657657
This is free software, and you are welcome to redistribute it
658658
under certain conditions; type `show c' for details.

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# MAC-API
22
This projects provides an easy to deploy API to lookup up MAC-Vendors using the MAC address or OUI.
33

4-
The API provides a fast webserver written in Golang as API endpoint. The service is getting the data from the offical IEEE MAC address assignment.
4+
The API provides a fast webserver written in Golang as API endpoint. The service is getting the data from the official IEEE MAC address assignment.
55

66
## Function
77
The API provides two endpoints for requests. The first one `/v1/oui` provides information about Vendor OUIs. The seconds one `/v1/mac` provides information about a MAC address
@@ -53,7 +53,7 @@ Content-Length: 130
5353
```
5454

5555
## Prerequisites
56-
It is recommend to have a server where you can deploy the API, but it is also possible to start the microservice manually on a local machine.
56+
It is recommended to have a server where you can deploy the API, but it is also possible to start the microservice manually on a local machine.
5757

5858
## Installation and configuration
5959
Download the prebuilt binary packages from the [release page](https://github.com/4ndyZ/MAC-API/releases) and install them on your server.
@@ -82,23 +82,23 @@ Now you are able to install the package.
8282

8383
After installing the package configure the API. The configuration file is located under `/etc/mac-api/config.yml`.
8484

85-
No you you are able to enable the Systemd service using `systemctl`.
85+
Now you are able to enable the Systemd service using `systemctl`.
8686
`sudo systemctl enable mac-api`
8787

8888
And start the service also using `systemctl`.
8989
`sudo systemctl start mac-api`
9090

9191
#### Windows/Other
92-
If you plan to run the API on Windows or another OS the whole process is a bit more complicated because there is no installation package avaible only prebuilt binaries.
92+
If you plan to run the API on Windows or another OS the whole process is a bit more complicated because there is no installation package available only prebuilt binaries.
9393

9494
Download the prebuilt binary for your operating system.
9595

96-
Exctract the prebuilt binary and change the configuration file located under `config/config.conf`.
96+
Extract the prebuilt binary and change the configuration file located under `config/config.conf`.
9797

9898
After successful changing the configuration file you are able to run the prebuilt binary.
9999

100100
### Configuration
101-
The API tries to access the configuration file located under `/etc/mac-api/config.conf`. It the configuration file is not accessable or found the API will fallback to the local file located unter `config/config.conf`.
101+
The API tries to access the configuration file located under `/etc/mac-api/config.conf`. If the configuration file is not accessible or found the API will fall back to the local file located under `config/config.conf`.
102102

103103
### Logging
104104
The API while try to put the log file in the `/var/log/mac-api` folder. If the service is not able to access or find that folder, the logging file gets created in the local folder `logs`.

app.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ func (a *App) Refresh() {
5555
func (a *App) Run() {
5656

5757
ctx, cancel := context.WithCancel(context.Background())
58-
5958
httpServer := &http.Server{
6059
Addr: *a.address,
6160
Handler: a.router,
@@ -88,8 +87,6 @@ func (a *App) Run() {
8887
Log.Logger.Info().Msg("API Webserver stopped.")
8988
cancel()
9089
Log.Logger.Info().Msg("API stopped.")
91-
// Rotate log file
92-
Log.Rotate()
9390
// Exit
9491
os.Exit(1)
9592
}()

go.mod

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
module github.com/4ndyZ/MAC-API/m/v2
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/gorilla/mux v1.8.0
7-
github.com/rs/zerolog v1.26.1
7+
github.com/rs/zerolog v1.27.0
88
gopkg.in/natefinch/lumberjack.v2 v2.0.0
9-
gopkg.in/yaml.v2 v2.4.0
9+
gopkg.in/yaml.v3 v3.0.1
1010
)
1111

12-
require github.com/BurntSushi/toml v0.3.1 // indirect
12+
require (
13+
github.com/BurntSushi/toml v1.1.0 // indirect
14+
github.com/mattn/go-colorable v0.1.12 // indirect
15+
github.com/mattn/go-isatty v0.0.14 // indirect
16+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 // indirect
17+
gopkg.in/yaml.v2 v2.4.0 // indirect
18+
)

go.sum

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,25 @@
1-
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2-
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3-
github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
1+
github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I=
2+
github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
3+
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
44
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
55
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
66
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
7+
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
8+
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
9+
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
10+
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
711
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
812
github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
9-
github.com/rs/zerolog v1.26.1 h1:/ihwxqH+4z8UxyI70wM1z9yCvkWcfz/a3mj48k/Zngc=
10-
github.com/rs/zerolog v1.26.1/go.mod h1:/wSSJWX7lVrsOwlbyTRSOJvqRlc+WjWlfes+CiJ+tmc=
11-
github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
12-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
13-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
14-
golang.org/x/crypto v0.0.0-20211215165025-cf75a172585e/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
15-
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
16-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
17-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
18-
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
19-
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
20-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
21-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
22-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
23-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
24-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
25-
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
26-
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
27-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
28-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
29-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
30-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
31-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
32-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
33-
golang.org/x/tools v0.1.7/go.mod h1:LGqMHiF4EqQNHR1JncWGqT5BVaXmza+X+BDGol+dOxo=
34-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
35-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
36-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
13+
github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs=
14+
github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U=
15+
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
16+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 h1:foEbQz/B0Oz6YIqu/69kfXPYeFQAuuMYFkjaqXzl5Wo=
17+
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
3718
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
3819
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
3920
gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8=
4021
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
4122
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
4223
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
24+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
25+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

handler.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (a *App) ParseMACData(body *[][]string) ([]OUI, error) {
4848
func (a *App) GetOUI(w http.ResponseWriter, r *http.Request) {
4949
input := strings.ToUpper((mux.Vars(r))["oui"]) // Convert OUI to upper case
5050

51-
// Remove all non HEX chars
51+
// Remove all non-HEX chars
5252
reg, _ := regexp.Compile("[^0-9A-F]+")
5353
request := reg.ReplaceAllString(input, "")
5454

@@ -76,7 +76,7 @@ func (a *App) GetOUI(w http.ResponseWriter, r *http.Request) {
7676
func (a *App) GetMAC(w http.ResponseWriter, r *http.Request) {
7777
input := strings.ToUpper((mux.Vars(r))["mac"]) // Convert OUI to upper case
7878

79-
// Remove all non HEX chars
79+
// Remove all non-HEX chars
8080
reg := regexp.MustCompile("[^0-9A-F]+")
8181
request := reg.ReplaceAllString(input, "")
8282

@@ -120,7 +120,10 @@ func (a *App) respondWithJSON(w http.ResponseWriter, code int, payload interface
120120

121121
w.Header().Set("Content-Type", "application/json")
122122
w.WriteHeader(code)
123-
w.Write(response)
123+
_, err := w.Write(response)
124+
if err != nil {
125+
return
126+
}
124127
}
125128

126129
// Send a JSON error message

logger.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func (l *Logger) Initialize(f string) {
2121
// Create file writer
2222
fileWriter := &lumberjack.Logger{
2323
Filename: f,
24-
MaxSize: 100, // Megabytes
25-
MaxBackups: 3,
26-
MaxAge: 28, // Days: true
24+
MaxSize: 10, // Megabytes
25+
MaxBackups: 5,
26+
MaxAge: 28, // Days
2727
LocalTime: true,
2828
}
2929
multi := zerolog.MultiLevelWriter(consoleWriter, fileWriter)
@@ -48,11 +48,3 @@ func (l *Logger) EnableDebug(debug bool) {
4848
}
4949
}
5050
}
51-
52-
// Rotate log file
53-
func (l *Logger) Rotate() {
54-
err := l.fileWriter.Rotate()
55-
if err != nil {
56-
Log.Logger.Warn().Str("error", err.Error()).Msg("Unable to rotate log file.")
57-
}
58-
}

main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ package main
22

33
import (
44
"flag"
5-
"gopkg.in/yaml.v2"
5+
"gopkg.in/yaml.v3"
66
"io/ioutil"
77
"os"
88
"strings"
99
)
1010

11-
var Log Logger = Logger{}
11+
var Log = Logger{}
1212

1313
func main() {
1414
// Create configuration object
@@ -67,7 +67,6 @@ func main() {
6767
if configuration.Logging.Debug {
6868
Log.EnableDebug(true)
6969
}
70-
7170
// Create app worker
7271
a := App{}
7372
a.Initialize("http://standards-oui.ieee.org/oui/oui.csv", configuration.Address, configuration.TimeInterval)

service/service_deb.service

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
[Unit]
2+
Description=MAC-API Service
3+
ConditionPathExists=/usr/bin/mac-api
4+
After=network.target
5+
StartLimitIntervalSec=60
6+
7+
[Service]
8+
Type=simple
9+
User=mac-api
10+
Group=mac-api
11+
12+
Restart=on-failure
13+
RestartSec=10
14+
15+
ExecStart=/usr/bin/mac-api
16+
17+
# Make sure log directory exists
18+
ExecStartPre=+/bin/mkdir -p /var/log/mac-api
19+
ExecStartPre=+/bin/chown mac-api:mac-api /var/log/mac-api
20+
ExecStartPre=+/bin/chmod 0744 /var/log/mac-api
21+
22+
[Install]
23+
WantedBy=multi-user.target

service/service.service renamed to service/service_rpm.service

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Description=MAC-API Service
33
ConditionPathExists=/usr/local/bin/mac-api
44
After=network.target
5+
StartLimitIntervalSec=60
56

67
[Service]
78
Type=simple
@@ -10,15 +11,13 @@ Group=mac-api
1011

1112
Restart=on-failure
1213
RestartSec=10
13-
startLimitIntervalSec=60
1414

1515
ExecStart=/usr/local/bin/mac-api
1616

1717
# Make sure log directory exists
18-
PermissionsStartOnly=true
19-
ExecStartPre=/bin/mkdir -p /var/log/mac-api
20-
ExecStartPre=/bin/chown mac-api:mac-api /var/log/mac-api
21-
ExecStartPre=/bin/chmod 0744 /var/log/mac-api
18+
ExecStartPre=+/bin/mkdir -p /var/log/mac-api
19+
ExecStartPre=+/bin/chown mac-api:mac-api /var/log/mac-api
20+
ExecStartPre=+/bin/chmod 0744 /var/log/mac-api
2221

2322
[Install]
2423
WantedBy=multi-user.target

0 commit comments

Comments
 (0)