feature: Adds autostart support.
This commit is contained in:
parent
8ba0424512
commit
5c45533371
6 changed files with 46 additions and 8 deletions
|
@ -105,7 +105,7 @@ func LookupBackend(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.Backend != nil {
|
if req.Backend != nil {
|
||||||
queryString = append(queryString, "isbot = ?")
|
queryString = append(queryString, "is_bot = ?")
|
||||||
queryParameters = append(queryParameters, req.Backend)
|
queryParameters = append(queryParameters, req.Backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -124,22 +124,22 @@ func LookupProxy(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.SourcePort != nil {
|
if req.SourcePort != nil {
|
||||||
queryString = append(queryString, "sourceport = ?")
|
queryString = append(queryString, "source_port = ?")
|
||||||
queryParameters = append(queryParameters, req.SourcePort)
|
queryParameters = append(queryParameters, req.SourcePort)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.DestinationPort != nil {
|
if req.DestinationPort != nil {
|
||||||
queryString = append(queryString, "destinationport = ?")
|
queryString = append(queryString, "destination_port = ?")
|
||||||
queryParameters = append(queryParameters, req.DestinationPort)
|
queryParameters = append(queryParameters, req.DestinationPort)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.ProviderID != nil {
|
if req.ProviderID != nil {
|
||||||
queryString = append(queryString, "backendid = ?")
|
queryString = append(queryString, "backend_id = ?")
|
||||||
queryParameters = append(queryParameters, req.ProviderID)
|
queryParameters = append(queryParameters, req.ProviderID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.AutoStart != nil {
|
if req.AutoStart != nil {
|
||||||
queryString = append(queryString, "autostart = ?")
|
queryString = append(queryString, "auto_start = ?")
|
||||||
queryParameters = append(queryParameters, req.AutoStart)
|
queryParameters = append(queryParameters, req.AutoStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ func LookupUser(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if req.IsBot != nil {
|
if req.IsBot != nil {
|
||||||
queryString = append(queryString, "isbot = ?")
|
queryString = append(queryString, "is_bot = ?")
|
||||||
queryParameters = append(queryParameters, req.IsBot)
|
queryParameters = append(queryParameters, req.IsBot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,6 +152,43 @@ func entrypoint(cCtx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
backendruntime.RunningBackends[backend.ID] = backendInstance
|
backendruntime.RunningBackends[backend.ID] = backendInstance
|
||||||
|
|
||||||
|
log.Infof("Successfully initialized backend #%d", backend.ID)
|
||||||
|
|
||||||
|
autoStartProxies := []dbcore.Proxy{}
|
||||||
|
|
||||||
|
if err := dbcore.DB.Where("backend_id = ? AND auto_start = true", backend.ID).Find(&autoStartProxies).Error; err != nil {
|
||||||
|
log.Errorf("Failed to query proxies to autostart: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, proxy := range autoStartProxies {
|
||||||
|
log.Infof("Starting up route #%d for backend #%d: %s", proxy.ID, backend.ID, proxy.Name)
|
||||||
|
|
||||||
|
backendInstance.RuntimeCommands <- &commonbackend.AddProxy{
|
||||||
|
Type: "addProxy",
|
||||||
|
SourceIP: proxy.SourceIP,
|
||||||
|
SourcePort: proxy.SourcePort,
|
||||||
|
DestPort: proxy.DestinationPort,
|
||||||
|
Protocol: proxy.Protocol,
|
||||||
|
}
|
||||||
|
|
||||||
|
backendResponse := <-backendInstance.RuntimeCommands
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
|
case error:
|
||||||
|
log.Errorf("Failed to get response for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, responseMessage.Error())
|
||||||
|
continue
|
||||||
|
case *commonbackend.ProxyStatusResponse:
|
||||||
|
if !responseMessage.IsActive {
|
||||||
|
log.Warnf("Failed to start proxy for backend #%d and route #%d", proxy.BackendID, proxy.ID)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Errorf("Got illegal response type for backend #%d and proxy #%d: %T", proxy.BackendID, proxy.ID, responseMessage)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("Successfully started backend #%d", backend.ID)
|
log.Infof("Successfully started backend #%d", backend.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,7 @@ body:json {
|
||||||
|
|
||||||
"destinationPort": 9000,
|
"destinationPort": 9000,
|
||||||
|
|
||||||
"providerID": 2
|
"providerID": 2,
|
||||||
|
"autoStart": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,6 @@ post {
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiMSJdLCJleHAiOjE3MzUwNzY0MTEsIm5iZiI6MTczNDk5MDAxMSwiaWF0IjoxNzM0OTkwMDExfQ.N9TLraX4peHt7FKv8tPcHuEzL0K7T2IBEw3piQS_4OY",
|
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiMSJdLCJleHAiOjE3MzUwNzY0MTEsIm5iZiI6MTczNDk5MDAxMSwiaWF0IjoxNzM0OTkwMDExfQ.N9TLraX4peHt7FKv8tPcHuEzL0K7T2IBEw3piQS_4OY",
|
||||||
"id": 1
|
"id": 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue