Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linter fixes #3

Merged
merged 6 commits into from
Apr 6, 2024
Merged
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
14 changes: 0 additions & 14 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,6 @@ import (
"github.com/gin-gonic/gin"
)

func printItemList(c *gin.Context, items []item) {
for _, item := range items {
value := item.Value
if strings.Contains(item.Name, "pwd") || strings.Contains(item.Name, "pass") {
value = strings.Repeat("-", len(value)) + " (hidden)"
}
if item.Index == 0 {
_log(c, " - %v = %v\n", item.Name, value)
} else {
_log(c, " - %v[%v] = %v\n", item.Name, item.Index, value)
}
}
}

func itemsFromFile(c *gin.Context, confFile string) []item {
conf, err := os.ReadFile(confFile)
if err != nil {
Expand Down
21 changes: 11 additions & 10 deletions dlsir.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type reason struct {

type message struct {
Action string `xml:"Action,omitempty"`
Reason reason `xml:"ReasonForContact,-"`
Reason reason `xml:"ReasonForContact"`
Nonce string `xml:"nonce,attr"`
MaxItems int `xml:"maxItems,attr,omitempty"`
Fragment string `xml:"fragment,attr,omitempty"`
Expand Down Expand Up @@ -179,7 +179,7 @@ func sendSoftware(c *gin.Context, phone *phoneDesc, msg message) (string, []item
return "SoftwareDeployment", items
}

func readAllItems(c *gin.Context, phone *phoneDesc, msg message) (string, []item) {
func readAllItems(phone *phoneDesc, msg message) (string, []item) {
return "ReadAllItems", []item{}
}

Expand All @@ -191,7 +191,11 @@ func checkReply(c *gin.Context, phone *phoneDesc, msg message) bool {
file := fmt.Sprintf("%v/%v.conf", confDumpDir, phone.Number)
content := formatItemList(msg.Items)

os.WriteFile(file, []byte(content), 0666)
err := os.WriteFile(file, []byte(content), 0666)
if err != nil {
_log(c, "failed to write to file %v with error:\n %v", file, err)
}

}

return msg.Reason.Status == "accepted"
Expand Down Expand Up @@ -319,7 +323,7 @@ func postLoginService(c *gin.Context) {
// -> software update was likely successful
_log(c, "Yay - phone came back after a software update; requesting current configuration")

action, responseItems = readAllItems(c, phone, msg)
action, responseItems = readAllItems(phone, msg)
phone.NextStep = RequestConfig
} else if msg.Reason.Value == "start-up" || msg.Reason.Value == "solicited" {
// we send the full phone configuration both on startup and explicit request
Expand Down Expand Up @@ -358,7 +362,7 @@ func postLoginService(c *gin.Context) {
action, responseItems = sendSoftware(c, phone, msg)
phone.NextStep = WaitForUpdate
} else if phone.NextStep == RequestConfig {
action, responseItems = readAllItems(c, phone, msg)
action, responseItems = readAllItems(phone, msg)
// phone.NextStep = RequestConfig
} else {
_log(c, "Error: Got unexpected NextStep = %v", phone.NextStep)
Expand Down Expand Up @@ -457,10 +461,7 @@ func main() {
tlsCert := requireItem(config, "tls-cert-file").Value
tlsKey := requireItem(config, "tls-key-file").Value

managedPhones := make([]item, 0)
for _, item := range filterItemList(config, "managed-phones", true) {
managedPhones = append(managedPhones, item)
}
managedPhones := filterItemList(config, "managed-phones", true)

manageIntervalStr := requireItem(config, "manage-interval").Value
manageInterval, err := time.ParseDuration(manageIntervalStr)
Expand All @@ -474,7 +475,7 @@ func main() {

gin.SetMode(gin.ReleaseMode)
router := gin.Default()
router.SetTrustedProxies(nil)
_ = router.SetTrustedProxies(nil)

router.GET("/file/:file", getFile)
router.POST("/DeploymentService/LoginService", postLoginService)
Expand Down
Loading