2018-03-05 12:44:16 +01:00
|
|
|
// Package rc implements a remote control server and registry for rclone
|
|
|
|
//
|
|
|
|
// To register your internal calls, call rc.Add(path, function). Your
|
2023-03-25 08:20:46 +01:00
|
|
|
// function should take and return a Param. It can also return an
|
2018-03-05 12:44:16 +01:00
|
|
|
// error. Use rc.NewError to wrap an existing error along with an
|
|
|
|
// http response type if another response other than 500 internal
|
|
|
|
// error is required on error.
|
|
|
|
package rc
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2018-04-06 21:33:51 +02:00
|
|
|
"io"
|
2018-05-11 12:12:58 +02:00
|
|
|
_ "net/http/pprof" // install the pprof http handlers
|
2019-08-10 18:12:22 +02:00
|
|
|
"time"
|
2018-03-05 12:44:16 +01:00
|
|
|
|
2022-12-11 15:47:47 +01:00
|
|
|
libhttp "github.com/rclone/rclone/lib/http"
|
2018-03-05 12:44:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Options contains options for the remote control server
|
|
|
|
type Options struct {
|
2022-12-11 15:47:47 +01:00
|
|
|
HTTP libhttp.Config
|
|
|
|
Auth libhttp.AuthConfig
|
|
|
|
Template libhttp.TemplateConfig
|
2019-08-08 06:56:58 +02:00
|
|
|
Enabled bool // set to enable the server
|
|
|
|
Serve bool // set to serve files from remotes
|
|
|
|
Files string // set to enable serving files locally
|
|
|
|
NoAuth bool // set to disable auth checks on AuthRequired methods
|
|
|
|
WebUI bool // set to launch the web ui
|
2020-01-12 10:12:04 +01:00
|
|
|
WebGUIUpdate bool // set to check new update
|
|
|
|
WebGUIForceUpdate bool // set to force download new update
|
|
|
|
WebGUINoOpenBrowser bool // set to disable auto opening browser
|
2019-08-08 06:56:58 +02:00
|
|
|
WebGUIFetchURL string // set the default url for fetching webgui
|
|
|
|
AccessControlAllowOrigin string // set the access control for CORS configuration
|
2020-02-26 09:34:32 +01:00
|
|
|
EnableMetrics bool // set to disable prometheus metrics on /metrics
|
2019-08-10 18:12:22 +02:00
|
|
|
JobExpireDuration time.Duration
|
|
|
|
JobExpireInterval time.Duration
|
2018-03-05 12:44:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultOpt is the default values used for Options
|
|
|
|
var DefaultOpt = Options{
|
2022-12-11 15:47:47 +01:00
|
|
|
HTTP: libhttp.DefaultCfg(),
|
|
|
|
Auth: libhttp.DefaultAuthCfg(),
|
|
|
|
Template: libhttp.DefaultTemplateCfg(),
|
2019-08-10 18:12:22 +02:00
|
|
|
Enabled: false,
|
|
|
|
JobExpireDuration: 60 * time.Second,
|
|
|
|
JobExpireInterval: 10 * time.Second,
|
2018-03-05 12:44:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2022-12-11 15:47:47 +01:00
|
|
|
DefaultOpt.HTTP.ListenAddr = []string{"localhost:5572"}
|
2018-03-05 12:44:16 +01:00
|
|
|
}
|
|
|
|
|
2018-04-06 21:33:51 +02:00
|
|
|
// WriteJSON writes JSON in out to w
|
|
|
|
func WriteJSON(w io.Writer, out Params) error {
|
|
|
|
enc := json.NewEncoder(w)
|
|
|
|
enc.SetIndent("", "\t")
|
|
|
|
return enc.Encode(out)
|
|
|
|
}
|