up
This commit is contained in:
parent
9110ab9ec3
commit
102a48fa12
45
main.go
45
main.go
@ -253,25 +253,30 @@ func startHTTP() {
|
|||||||
_ = app.Run(":8080")
|
_ = app.Run(":8080")
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
// ---------- Main ----------
|
||||||
// SFTP sur 2222 (root = ./upload)
|
|
||||||
go startSFTPServer(SFTPBaseDir)
|
|
||||||
|
|
||||||
// HTTP normal
|
func main() {
|
||||||
startHTTP()
|
|
||||||
|
go startSFTPServer(SFTPBaseDir)
|
||||||
|
|
||||||
|
|
||||||
|
// Serveur HTTP Gin
|
||||||
|
bd := db.InitDB()
|
||||||
|
app := gin.Default()
|
||||||
|
|
||||||
|
api := app.Group("/api/v1")
|
||||||
|
routes.AddRoutes(api, bd)
|
||||||
|
utils.CreateDefaultFolder(bd)
|
||||||
|
|
||||||
|
app.Static("/static", "./web")
|
||||||
|
app.NoRoute(func(c *gin.Context) {
|
||||||
|
if strings.HasPrefix(c.Request.URL.Path, "/api/") {
|
||||||
|
c.JSON(404, gin.H{"error": "Not found"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.File("./web/index.html")
|
||||||
|
})
|
||||||
|
|
||||||
|
log.Println("[HTTP] Serveur Gin sur http://localhost:8080")
|
||||||
|
app.Run(":8080")
|
||||||
}
|
}
|
||||||
func loadOrCreateRSAHostKey(path string) (ssh.Signer, error) {
|
|
||||||
if _, err := os.Stat(path); err == nil {
|
|
||||||
b, err := os.ReadFile(path)
|
|
||||||
if err != nil { return nil, err }
|
|
||||||
return ssh.ParsePrivateKey(b)
|
|
||||||
}
|
|
||||||
// Génère une clé RSA 2048
|
|
||||||
priv, err := rsa.GenerateKey(rand.Reader, 2048)
|
|
||||||
if err != nil { return nil, err }
|
|
||||||
// Encode en PEM "RSA PRIVATE KEY" (PKCS#1)
|
|
||||||
pkcs1 := x509.MarshalPKCS1PrivateKey(priv)
|
|
||||||
pemBytes := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: pkcs1})
|
|
||||||
if err := os.WriteFile(path, pemBytes, 0o600); err != nil { return nil, err }
|
|
||||||
return ssh.ParsePrivateKey(pemBytes)
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user