Implement cross-platform log streaming for frpc instances with support for Windows, systemd, and init.d systems. Includes WebSocket API endpoint for real-time log streaming, token validation, and instance ownership checks. Update README and API documentation to reflect new functionality. The implementation handles: - Platform-specific log collection (Windows Event Log, journalctl, log files) - WebSocket-based real-time streaming - Token validation and instance access control - Log level parsing and formatting - Historical log retrieval since service start
51 lines
2.0 KiB
Go
51 lines
2.0 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"super-frpc/frpLogger"
|
|
"super-frpc/postLog"
|
|
)
|
|
|
|
func setupRoutes() {
|
|
postLog.Info("Setting up routes...")
|
|
http.HandleFunc("/system/getStatus", GetStatusHandler)
|
|
http.HandleFunc("/system/getSoftwareInfo", GetSoftwareInfoHandler)
|
|
systemLogHandler := postLog.NewLogSocketHandler(postLog.GetLogBroadcaster())
|
|
http.HandleFunc("/system/getLogs", systemLogHandler.Handle)
|
|
|
|
http.HandleFunc("/register", RegisterHandler)
|
|
http.HandleFunc("/login", LoginHandler)
|
|
http.HandleFunc("/logout", LogoutHandler)
|
|
|
|
http.HandleFunc("/userMgr/create", CreateUserHandler)
|
|
http.HandleFunc("/userMgr/remove", RemoveUserHandler)
|
|
http.HandleFunc("/userMgr/list", ListUserHandler)
|
|
// http.HandleFunc("/userMgr/modify", ModifyUserHandler)
|
|
|
|
http.HandleFunc("/sessionMgr/list", ListActiveSessionsHandler)
|
|
http.HandleFunc("/sessionMgr/remove", RemoveSessionHandler)
|
|
|
|
http.HandleFunc("/frpcAct/instanceMgr/create", CreateInstanceHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/delete", DeleteInstanceHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/modify", ModifyInstanceHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/list", ListInstancesHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/start", StartInstanceHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/stop", StopInstanceHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/restart", RestartInstanceHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/status", GetInstanceStatusHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/getInfo", GetInstanceInfoHandler)
|
|
http.HandleFunc("/frpcAct/instanceMgr/logs", frpLogger.NewInstanceLogHandler(ValidateTokenFromMap).ServeHTTP)
|
|
http.HandleFunc("/frpcAct/proxyMgr/create", CreateProxyHandler)
|
|
http.HandleFunc("/frpcAct/proxyMgr/delete", DeleteProxyHandler)
|
|
http.HandleFunc("/frpcAct/proxyMgr/list", ListProxiesHandler)
|
|
|
|
http.HandleFunc("/", NotFoundHandler)
|
|
|
|
}
|
|
|
|
func NotFoundHandler(w http.ResponseWriter, r *http.Request) {
|
|
postLog.Error(fmt.Sprintf("Route not found: %s %s", r.Method, r.URL.Path))
|
|
SendErrorResponse(w, http.StatusNotFound, "Invalid request path")
|
|
}
|