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
|
|
|
|
2024-07-04 11:47:05 +02:00
|
|
|
"github.com/rclone/rclone/fs"
|
2022-12-11 15:47:47 +01:00
|
|
|
libhttp "github.com/rclone/rclone/lib/http"
|
2018-03-05 12:44:16 +01:00
|
|
|
)
|
|
|
|
|
2024-07-04 11:47:05 +02:00
|
|
|
// OptionsInfo describes the Options in use
|
|
|
|
var OptionsInfo = fs.Options{{
|
|
|
|
Name: "rc",
|
|
|
|
Default: false,
|
|
|
|
Help: "Enable the remote control server",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_files",
|
|
|
|
Default: "",
|
|
|
|
Help: "Path to local files to serve on the HTTP server",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_serve",
|
|
|
|
Default: false,
|
|
|
|
Help: "Enable the serving of remote objects",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_serve_no_modtime",
|
|
|
|
Default: false,
|
|
|
|
Help: "Don't read the modification time (can speed things up)",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_no_auth",
|
|
|
|
Default: false,
|
|
|
|
Help: "Don't require auth for certain methods",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_web_gui",
|
|
|
|
Default: false,
|
|
|
|
Help: "Launch WebGUI on localhost",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_web_gui_update",
|
|
|
|
Default: false,
|
|
|
|
Help: "Check and update to latest version of web gui",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_web_gui_force_update",
|
|
|
|
Default: false,
|
|
|
|
Help: "Force update to latest version of web gui",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_web_gui_no_open_browser",
|
|
|
|
Default: false,
|
|
|
|
Help: "Don't open the browser automatically",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_web_fetch_url",
|
|
|
|
Default: "https://api.github.com/repos/rclone/rclone-webui-react/releases/latest",
|
|
|
|
Help: "URL to fetch the releases for webgui",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_enable_metrics",
|
|
|
|
Default: false,
|
2024-09-06 16:00:36 +02:00
|
|
|
Help: "Enable the Prometheus metrics path at the remote control server",
|
|
|
|
Groups: "RC,Metrics",
|
2024-07-04 11:47:05 +02:00
|
|
|
}, {
|
|
|
|
Name: "rc_job_expire_duration",
|
|
|
|
Default: 60 * time.Second,
|
|
|
|
Help: "Expire finished async jobs older than this value",
|
|
|
|
Groups: "RC",
|
|
|
|
}, {
|
|
|
|
Name: "rc_job_expire_interval",
|
|
|
|
Default: 10 * time.Second,
|
|
|
|
Help: "Interval to check for expired async jobs",
|
|
|
|
Groups: "RC",
|
2024-09-06 16:00:36 +02:00
|
|
|
}, {
|
|
|
|
Name: "metrics_addr",
|
|
|
|
Default: []string{""},
|
|
|
|
Help: "IPaddress:Port or :Port to bind metrics server to",
|
|
|
|
Groups: "Metrics",
|
2024-07-04 11:47:05 +02:00
|
|
|
}}.
|
|
|
|
AddPrefix(libhttp.ConfigInfo, "rc", "RC").
|
|
|
|
AddPrefix(libhttp.AuthConfigInfo, "rc", "RC").
|
|
|
|
AddPrefix(libhttp.TemplateConfigInfo, "rc", "RC").
|
2024-09-06 16:00:36 +02:00
|
|
|
AddPrefix(libhttp.ConfigInfo, "metrics", "Metrics").
|
|
|
|
AddPrefix(libhttp.AuthConfigInfo, "metrics", "Metrics").
|
|
|
|
AddPrefix(libhttp.TemplateConfigInfo, "metrics", "Metrics").
|
2024-07-04 11:47:05 +02:00
|
|
|
SetDefault("rc_addr", []string{"localhost:5572"})
|
2018-03-05 12:44:16 +01:00
|
|
|
|
2024-07-04 11:47:05 +02:00
|
|
|
func init() {
|
|
|
|
fs.RegisterGlobalOptions(fs.OptionsInfo{Name: "rc", Opt: &Opt, Options: OptionsInfo})
|
2018-03-05 12:44:16 +01:00
|
|
|
}
|
|
|
|
|
2024-07-04 11:47:05 +02:00
|
|
|
// Options contains options for the remote control server
|
|
|
|
type Options struct {
|
|
|
|
HTTP libhttp.Config `config:"rc"`
|
|
|
|
Auth libhttp.AuthConfig `config:"rc"`
|
|
|
|
Template libhttp.TemplateConfig `config:"rc"`
|
|
|
|
Enabled bool `config:"rc"` // set to enable the server
|
|
|
|
Files string `config:"rc_files"` // set to enable serving files locally
|
|
|
|
Serve bool `config:"rc_serve"` // set to serve files from remotes
|
|
|
|
ServeNoModTime bool `config:"rc_serve_no_modtime"` // don't read the modification time
|
|
|
|
NoAuth bool `config:"rc_no_auth"` // set to disable auth checks on AuthRequired methods
|
|
|
|
WebUI bool `config:"rc_web_gui"` // set to launch the web ui
|
|
|
|
WebGUIUpdate bool `config:"rc_web_gui_update"` // set to check new update
|
|
|
|
WebGUIForceUpdate bool `config:"rc_web_gui_force_update"` // set to force download new update
|
|
|
|
WebGUINoOpenBrowser bool `config:"rc_web_gui_no_open_browser"` // set to disable auto opening browser
|
|
|
|
WebGUIFetchURL string `config:"rc_web_fetch_url"` // set the default url for fetching webgui
|
|
|
|
EnableMetrics bool `config:"rc_enable_metrics"` // set to disable prometheus metrics on /metrics
|
2024-09-06 16:00:36 +02:00
|
|
|
MetricsHTTP libhttp.Config `config:"metrics"`
|
|
|
|
MetricsAuth libhttp.AuthConfig `config:"metrics"`
|
|
|
|
MetricsTemplate libhttp.TemplateConfig `config:"metrics"`
|
2024-07-04 11:47:05 +02:00
|
|
|
JobExpireDuration time.Duration `config:"rc_job_expire_duration"`
|
|
|
|
JobExpireInterval time.Duration `config:"rc_job_expire_interval"`
|
2018-03-05 12:44:16 +01:00
|
|
|
}
|
|
|
|
|
2024-07-04 11:47:05 +02:00
|
|
|
// Opt is the default values used for Options
|
|
|
|
var Opt Options
|
|
|
|
|
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)
|
|
|
|
}
|