mirror of
https://github.com/outbackdingo/labca.git
synced 2026-01-27 10:19:34 +00:00
Refactor some deprecated code
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"os"
|
||||
"os/exec"
|
||||
@@ -124,12 +123,12 @@ func preCreateTasks(path string) error {
|
||||
}
|
||||
|
||||
if _, err := os.Stat(path + "serial"); os.IsNotExist(err) {
|
||||
if err := ioutil.WriteFile(path+"serial", []byte("1000\n"), 0644); err != nil {
|
||||
if err := os.WriteFile(path+"serial", []byte("1000\n"), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if _, err := os.Stat(path + "crlnumber"); os.IsNotExist(err) {
|
||||
if err = ioutil.WriteFile(path+"crlnumber", []byte("1000\n"), 0644); err != nil {
|
||||
if err = os.WriteFile(path+"crlnumber", []byte("1000\n"), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -301,7 +300,7 @@ func (ci *CertificateInfo) Import(path string, certBase string, tmpDir string, t
|
||||
|
||||
// Upload a certificate and key file
|
||||
func (ci *CertificateInfo) Upload(path string, certBase string, tmpKey string, tmpCert string) error {
|
||||
if err := ioutil.WriteFile(tmpKey, []byte(ci.Key), 0644); err != nil {
|
||||
if err := os.WriteFile(tmpKey, []byte(ci.Key), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -322,7 +321,7 @@ func (ci *CertificateInfo) Upload(path string, certBase string, tmpKey string, t
|
||||
return reportError(err)
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(tmpCert, []byte(ci.Certificate), 0644); err != nil {
|
||||
if err := os.WriteFile(tmpCert, []byte(ci.Certificate), 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -494,7 +493,7 @@ func (ci *CertificateInfo) Create(path string, certBase string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpDir, err := ioutil.TempDir("", "labca")
|
||||
tmpDir, err := os.MkdirTemp("", "labca")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ func _parseLine(line string, loc *time.Location) Activity {
|
||||
|
||||
line = _removeAnsiColors(line)
|
||||
|
||||
re := regexp.MustCompile("^.*\\|\\s*(\\S)(\\S+) (\\S+) (\\S+) (.*)$")
|
||||
re := regexp.MustCompile(`^.*\|\s*(\S)(\S+) (\S+) (\S+) (.*)$`)
|
||||
result := re.FindStringSubmatch(line)
|
||||
if len(result) == 0 {
|
||||
return activity
|
||||
|
||||
22
gui/main.go
22
gui/main.go
@@ -16,7 +16,6 @@ import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math"
|
||||
"math/big"
|
||||
@@ -1250,7 +1249,7 @@ func getLog(w http.ResponseWriter, r *http.Request, logType string) string {
|
||||
|
||||
fmt.Fprintf(conn, "log-"+logType+"\n")
|
||||
reader := bufio.NewReader(conn)
|
||||
contents, err := ioutil.ReadAll(reader)
|
||||
contents, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
errorHandler(w, r, err, http.StatusInternalServerError)
|
||||
return ""
|
||||
@@ -1321,14 +1320,11 @@ func writer(ws *websocket.Conn, logType string) {
|
||||
|
||||
go showLog(ws, logType)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-pingTicker.C:
|
||||
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||
// Probably "websocket: close sent"
|
||||
return
|
||||
}
|
||||
for range pingTicker.C {
|
||||
ws.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||
// Probably "websocket: close sent"
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1396,7 +1392,7 @@ func _buildCI(r *http.Request, session *sessions.Session, isRoot bool) *Certific
|
||||
}
|
||||
|
||||
func issuerNameID(certfile string) (int64, error) {
|
||||
cf, err := ioutil.ReadFile(certfile)
|
||||
cf, err := os.ReadFile(certfile)
|
||||
if err != nil {
|
||||
log.Printf("issuerNameID: could not read cert file: %v", err)
|
||||
return 0, err
|
||||
@@ -1534,7 +1530,7 @@ func _hostCommand(w http.ResponseWriter, r *http.Request, command string, params
|
||||
}
|
||||
|
||||
reader := bufio.NewReader(conn)
|
||||
message, err := ioutil.ReadAll(reader)
|
||||
message, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
errorHandler(w, r, err, http.StatusInternalServerError)
|
||||
return false
|
||||
@@ -1762,7 +1758,7 @@ func _setupAdminUser(w http.ResponseWriter, r *http.Request) bool {
|
||||
|
||||
fmt.Fprintf(conn, "backup-restore\n"+header.Filename+"\n")
|
||||
reader := bufio.NewReader(conn)
|
||||
message, err := ioutil.ReadAll(reader)
|
||||
message, err := io.ReadAll(reader)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
reg.Errors["File"] = "Could not import backup file: error reading control response"
|
||||
|
||||
Reference in New Issue
Block a user