mirror of
https://github.com/fosrl/olm.git
synced 2026-03-05 10:16:46 +00:00
Compare commits
1 Commits
jit
...
dependabot
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24e0469562 |
59
api/api.go
59
api/api.go
@@ -78,13 +78,6 @@ type MetadataChangeRequest struct {
|
|||||||
Postures map[string]any `json:"postures"`
|
Postures map[string]any `json:"postures"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// JITConnectionRequest defines the structure for a dynamic Just-In-Time connection request.
|
|
||||||
// Either SiteID or ResourceID must be provided (but not necessarily both).
|
|
||||||
type JITConnectionRequest struct {
|
|
||||||
Site string `json:"site,omitempty"`
|
|
||||||
Resource string `json:"resource,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// API represents the HTTP server and its state
|
// API represents the HTTP server and its state
|
||||||
type API struct {
|
type API struct {
|
||||||
addr string
|
addr string
|
||||||
@@ -99,7 +92,6 @@ type API struct {
|
|||||||
onExit func() error
|
onExit func() error
|
||||||
onRebind func() error
|
onRebind func() error
|
||||||
onPowerMode func(PowerModeRequest) error
|
onPowerMode func(PowerModeRequest) error
|
||||||
onJITConnect func(JITConnectionRequest) error
|
|
||||||
|
|
||||||
statusMu sync.RWMutex
|
statusMu sync.RWMutex
|
||||||
peerStatuses map[int]*PeerStatus
|
peerStatuses map[int]*PeerStatus
|
||||||
@@ -151,7 +143,6 @@ func (s *API) SetHandlers(
|
|||||||
onExit func() error,
|
onExit func() error,
|
||||||
onRebind func() error,
|
onRebind func() error,
|
||||||
onPowerMode func(PowerModeRequest) error,
|
onPowerMode func(PowerModeRequest) error,
|
||||||
onJITConnect func(JITConnectionRequest) error,
|
|
||||||
) {
|
) {
|
||||||
s.onConnect = onConnect
|
s.onConnect = onConnect
|
||||||
s.onSwitchOrg = onSwitchOrg
|
s.onSwitchOrg = onSwitchOrg
|
||||||
@@ -160,7 +151,6 @@ func (s *API) SetHandlers(
|
|||||||
s.onExit = onExit
|
s.onExit = onExit
|
||||||
s.onRebind = onRebind
|
s.onRebind = onRebind
|
||||||
s.onPowerMode = onPowerMode
|
s.onPowerMode = onPowerMode
|
||||||
s.onJITConnect = onJITConnect
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start starts the HTTP server
|
// Start starts the HTTP server
|
||||||
@@ -179,7 +169,6 @@ func (s *API) Start() error {
|
|||||||
mux.HandleFunc("/health", s.handleHealth)
|
mux.HandleFunc("/health", s.handleHealth)
|
||||||
mux.HandleFunc("/rebind", s.handleRebind)
|
mux.HandleFunc("/rebind", s.handleRebind)
|
||||||
mux.HandleFunc("/power-mode", s.handlePowerMode)
|
mux.HandleFunc("/power-mode", s.handlePowerMode)
|
||||||
mux.HandleFunc("/jit-connect", s.handleJITConnect)
|
|
||||||
|
|
||||||
s.server = &http.Server{
|
s.server = &http.Server{
|
||||||
Handler: mux,
|
Handler: mux,
|
||||||
@@ -644,54 +633,6 @@ func (s *API) handleRebind(w http.ResponseWriter, r *http.Request) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// handleJITConnect handles the /jit-connect endpoint.
|
|
||||||
// It initiates a dynamic Just-In-Time connection to a site identified by either
|
|
||||||
// a site or a resource. Exactly one of the two must be provided.
|
|
||||||
func (s *API) handleJITConnect(w http.ResponseWriter, r *http.Request) {
|
|
||||||
if r.Method != http.MethodPost {
|
|
||||||
http.Error(w, "Method not allowed", http.StatusMethodNotAllowed)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var req JITConnectionRequest
|
|
||||||
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("Invalid request body: %v", err), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate that exactly one of site or resource is provided
|
|
||||||
if req.Site == "" && req.Resource == "" {
|
|
||||||
http.Error(w, "Missing required field: either site or resource must be provided", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if req.Site != "" && req.Resource != "" {
|
|
||||||
http.Error(w, "Ambiguous request: provide either site or resource, not both", http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if req.Site != "" {
|
|
||||||
logger.Info("Received JIT connection request via API: site=%s", req.Site)
|
|
||||||
} else {
|
|
||||||
logger.Info("Received JIT connection request via API: resource=%s", req.Resource)
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.onJITConnect != nil {
|
|
||||||
if err := s.onJITConnect(req); err != nil {
|
|
||||||
http.Error(w, fmt.Sprintf("JIT connection failed: %v", err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
http.Error(w, "JIT connect handler not configured", http.StatusNotImplemented)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusAccepted)
|
|
||||||
_ = json.NewEncoder(w).Encode(map[string]string{
|
|
||||||
"status": "JIT connection request accepted",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// handlePowerMode handles the /power-mode endpoint
|
// handlePowerMode handles the /power-mode endpoint
|
||||||
// This allows changing the power mode between "normal" and "low"
|
// This allows changing the power mode between "normal" and "low"
|
||||||
func (s *API) handlePowerMode(w http.ResponseWriter, r *http.Request) {
|
func (s *API) handlePowerMode(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -7,7 +7,7 @@ require (
|
|||||||
github.com/fosrl/newt v1.9.0
|
github.com/fosrl/newt v1.9.0
|
||||||
github.com/godbus/dbus/v5 v5.2.2
|
github.com/godbus/dbus/v5 v5.2.2
|
||||||
github.com/gorilla/websocket v1.5.3
|
github.com/gorilla/websocket v1.5.3
|
||||||
github.com/miekg/dns v1.1.70
|
github.com/miekg/dns v1.1.72
|
||||||
golang.org/x/sys v0.40.0
|
golang.org/x/sys v0.40.0
|
||||||
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb
|
golang.zx2c4.com/wireguard v0.0.0-20250521234502-f333402bd9cb
|
||||||
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10
|
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20241231184526-a9ab2273dd10
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -10,8 +10,8 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
|||||||
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
|
||||||
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
|
||||||
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
github.com/miekg/dns v1.1.70 h1:DZ4u2AV35VJxdD9Fo9fIWm119BsQL5cZU1cQ9s0LkqA=
|
github.com/miekg/dns v1.1.72 h1:vhmr+TF2A3tuoGNkLDFK9zi36F2LS+hKTRW0Uf8kbzI=
|
||||||
github.com/miekg/dns v1.1.70/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
|
github.com/miekg/dns v1.1.72/go.mod h1:+EuEPhdHOsfk6Wk5TT2CzssZdqkmFhf8r+aVyDEToIs=
|
||||||
github.com/vishvananda/netlink v1.3.1 h1:3AEMt62VKqz90r0tmNhog0r/PpWKmrEShJU0wJW6bV0=
|
github.com/vishvananda/netlink v1.3.1 h1:3AEMt62VKqz90r0tmNhog0r/PpWKmrEShJU0wJW6bV0=
|
||||||
github.com/vishvananda/netlink v1.3.1/go.mod h1:ARtKouGSTGchR8aMwmkzC0qiNPrrWO5JS/XMVl45+b4=
|
github.com/vishvananda/netlink v1.3.1/go.mod h1:ARtKouGSTGchR8aMwmkzC0qiNPrrWO5JS/XMVl45+b4=
|
||||||
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
|
github.com/vishvananda/netns v0.0.5 h1:DfiHV+j8bA32MFM7bfEunvT8IAqQ/NzSJHtcmW5zdEY=
|
||||||
|
|||||||
14
olm.iss
14
olm.iss
@@ -32,7 +32,7 @@ DefaultGroupName={#MyAppName}
|
|||||||
DisableProgramGroupPage=yes
|
DisableProgramGroupPage=yes
|
||||||
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
; Uncomment the following line to run in non administrative install mode (install for current user only).
|
||||||
;PrivilegesRequired=lowest
|
;PrivilegesRequired=lowest
|
||||||
OutputBaseFilename=olm_windows_installer
|
OutputBaseFilename=mysetup
|
||||||
SolidCompression=yes
|
SolidCompression=yes
|
||||||
WizardStyle=modern
|
WizardStyle=modern
|
||||||
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
; Add this to ensure PATH changes are applied and the system is prompted for a restart if needed
|
||||||
@@ -78,7 +78,7 @@ begin
|
|||||||
Result := True;
|
Result := True;
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Perform a case-insensitive check to see if the path is already present.
|
// Perform a case-insensitive check to see if the path is already present.
|
||||||
// We add semicolons to prevent partial matches (e.g., matching C:\App in C:\App2).
|
// We add semicolons to prevent partial matches (e.g., matching C:\App in C:\App2).
|
||||||
if Pos(';' + UpperCase(Path) + ';', ';' + UpperCase(OrigPath) + ';') > 0 then
|
if Pos(';' + UpperCase(Path) + ';', ';' + UpperCase(OrigPath) + ';') > 0 then
|
||||||
@@ -109,7 +109,7 @@ begin
|
|||||||
PathList.Delimiter := ';';
|
PathList.Delimiter := ';';
|
||||||
PathList.StrictDelimiter := True;
|
PathList.StrictDelimiter := True;
|
||||||
PathList.DelimitedText := OrigPath;
|
PathList.DelimitedText := OrigPath;
|
||||||
|
|
||||||
// Find and remove the matching entry (case-insensitive)
|
// Find and remove the matching entry (case-insensitive)
|
||||||
for I := PathList.Count - 1 downto 0 do
|
for I := PathList.Count - 1 downto 0 do
|
||||||
begin
|
begin
|
||||||
@@ -119,10 +119,10 @@ begin
|
|||||||
PathList.Delete(I);
|
PathList.Delete(I);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Reconstruct the PATH
|
// Reconstruct the PATH
|
||||||
NewPath := PathList.DelimitedText;
|
NewPath := PathList.DelimitedText;
|
||||||
|
|
||||||
// Write the new PATH back to the registry
|
// Write the new PATH back to the registry
|
||||||
if RegWriteExpandStringValue(HKEY_LOCAL_MACHINE,
|
if RegWriteExpandStringValue(HKEY_LOCAL_MACHINE,
|
||||||
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
|
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
|
||||||
@@ -145,8 +145,8 @@ begin
|
|||||||
// Get the application installation path
|
// Get the application installation path
|
||||||
AppPath := ExpandConstant('{app}');
|
AppPath := ExpandConstant('{app}');
|
||||||
Log('Removing PATH entry for: ' + AppPath);
|
Log('Removing PATH entry for: ' + AppPath);
|
||||||
|
|
||||||
// Remove only our path entry from the system PATH
|
// Remove only our path entry from the system PATH
|
||||||
RemovePathEntry(AppPath);
|
RemovePathEntry(AppPath);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|||||||
@@ -220,7 +220,6 @@ func (o *Olm) handleSync(msg websocket.WSMessage) {
|
|||||||
logger.Info("Sync: Adding new peer for site %d", siteId)
|
logger.Info("Sync: Adding new peer for site %d", siteId)
|
||||||
|
|
||||||
o.holePunchManager.TriggerHolePunch()
|
o.holePunchManager.TriggerHolePunch()
|
||||||
o.holePunchManager.ResetServerHolepunchInterval() // start sending immediately again so we fill in the endpoint on the cloud
|
|
||||||
|
|
||||||
// // TODO: do we need to send the message to the cloud to add the peer that way?
|
// // TODO: do we need to send the message to the cloud to add the peer that way?
|
||||||
// if err := o.peerManager.AddPeer(expectedSite); err != nil {
|
// if err := o.peerManager.AddPeer(expectedSite); err != nil {
|
||||||
|
|||||||
11
olm/olm.go
11
olm/olm.go
@@ -66,7 +66,6 @@ type Olm struct {
|
|||||||
updateRegister func(newData any)
|
updateRegister func(newData any)
|
||||||
|
|
||||||
stopPeerSend func()
|
stopPeerSend func()
|
||||||
stopPeerInit func()
|
|
||||||
|
|
||||||
// WaitGroup to track tunnel lifecycle
|
// WaitGroup to track tunnel lifecycle
|
||||||
tunnelWg sync.WaitGroup
|
tunnelWg sync.WaitGroup
|
||||||
@@ -285,16 +284,6 @@ func (o *Olm) registerAPICallbacks() {
|
|||||||
logger.Info("Processing power mode change request via API: mode=%s", req.Mode)
|
logger.Info("Processing power mode change request via API: mode=%s", req.Mode)
|
||||||
return o.SetPowerMode(req.Mode)
|
return o.SetPowerMode(req.Mode)
|
||||||
},
|
},
|
||||||
func(req api.JITConnectionRequest) error {
|
|
||||||
logger.Info("Processing JIT connect request via API: site=%s resource=%s", req.Site, req.Resource)
|
|
||||||
|
|
||||||
o.stopPeerInit, _ = o.websocket.SendMessageInterval("olm/wg/server/peer/init", map[string]interface{}{
|
|
||||||
"siteId": req.Site,
|
|
||||||
"resourceId": req.Resource,
|
|
||||||
}, 2*time.Second, 10)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user