config.go 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. package config
  2. import (
  3. "fmt"
  4. )
  5. // Action represents the core functionality of OliveTin - commands that show up
  6. // as buttons in the UI.
  7. type Action struct {
  8. ID string
  9. Title string
  10. Icon string
  11. Shell string
  12. Exec []string
  13. ShellAfterCompleted string
  14. Timeout int
  15. Acls []string
  16. Entity string
  17. Hidden bool
  18. ExecOnStartup bool
  19. ExecOnCron []string
  20. ExecOnFileCreatedInDir []string
  21. ExecOnFileChangedInDir []string
  22. ExecOnCalendarFile string
  23. Triggers []string
  24. MaxConcurrent int
  25. MaxRate []RateSpec
  26. Arguments []ActionArgument
  27. PopupOnStart string
  28. SaveLogs SaveLogsConfig
  29. }
  30. // ActionArgument objects appear on Actions.
  31. type ActionArgument struct {
  32. Name string
  33. Title string
  34. Description string
  35. Type string
  36. Default string
  37. Choices []ActionArgumentChoice
  38. Entity string
  39. RejectNull bool
  40. Suggestions map[string]string
  41. }
  42. // ActionArgumentChoice represents a predefined choice for an argument.
  43. type ActionArgumentChoice struct {
  44. Value string
  45. Title string
  46. }
  47. // RateSpec allows you to set a max frequency for an action.
  48. type RateSpec struct {
  49. Limit int
  50. Duration string
  51. }
  52. // Entity represents a "thing" that can have multiple actions associated with it.
  53. // for example, a media player with a start and stop action.
  54. type EntityFile struct {
  55. File string
  56. Name string
  57. Icon string
  58. }
  59. // PermissionsList defines what users can do with an action.
  60. type PermissionsList struct {
  61. View bool
  62. Exec bool
  63. Logs bool
  64. Kill bool
  65. }
  66. // AccessControlList defines what permissions apply to a user or user group.
  67. type AccessControlList struct {
  68. Name string
  69. AddToEveryAction bool
  70. MatchUsergroups []string
  71. MatchUsernames []string
  72. Permissions PermissionsList
  73. Policy ConfigurationPolicy
  74. }
  75. // ConfigurationPolicy defines global settings which are overridden with an ACL.
  76. type ConfigurationPolicy struct {
  77. ShowDiagnostics bool
  78. ShowLogList bool
  79. }
  80. type PrometheusConfig struct {
  81. Enabled bool
  82. DefaultGoMetrics bool
  83. }
  84. // Config is the global config used through the whole app.
  85. type Config struct {
  86. UseSingleHTTPFrontend bool
  87. ThemeName string
  88. ThemeCacheDisabled bool
  89. ListenAddressSingleHTTPFrontend string
  90. ListenAddressWebUI string
  91. ListenAddressRestActions string
  92. ListenAddressGrpcActions string
  93. ListenAddressPrometheus string
  94. ExternalRestAddress string
  95. LogLevel string
  96. LogDebugOptions LogDebugOptions
  97. LogHistoryPageSize int64
  98. Actions []*Action `mapstructure:"actions"`
  99. Entities []*EntityFile `mapstructure:"entities"`
  100. Dashboards []*DashboardComponent `mapstructure:"dashboards"`
  101. CheckForUpdates bool
  102. PageTitle string
  103. ShowFooter bool
  104. ShowNavigation bool
  105. ShowNewVersions bool
  106. EnableCustomJs bool
  107. AuthJwtCookieName string
  108. AuthJwtHeader string
  109. AuthJwtAud string
  110. AuthJwtDomain string
  111. AuthJwtCertsURL string
  112. AuthJwtHmacSecret string // mutually exclusive with pub key config fields
  113. AuthJwtClaimUsername string
  114. AuthJwtClaimUserGroup string
  115. AuthJwtPubKeyPath string // will read pub key from file on disk
  116. AuthHttpHeaderUsername string
  117. AuthHttpHeaderUserGroup string
  118. AuthHttpHeaderUserGroupSep string
  119. AuthLocalUsers AuthLocalUsersConfig
  120. AuthLoginUrl string
  121. AuthRequireGuestsToLogin bool
  122. AuthOAuth2RedirectURL string
  123. AuthOAuth2Providers map[string]*OAuth2Provider
  124. DefaultPermissions PermissionsList
  125. DefaultPolicy ConfigurationPolicy
  126. AccessControlLists []*AccessControlList
  127. WebUIDir string
  128. CronSupportForSeconds bool
  129. SectionNavigationStyle string
  130. DefaultPopupOnStart string
  131. InsecureAllowDumpOAuth2UserData bool
  132. InsecureAllowDumpVars bool
  133. InsecureAllowDumpSos bool
  134. InsecureAllowDumpActionMap bool
  135. InsecureAllowDumpJwtClaims bool
  136. Prometheus PrometheusConfig
  137. SaveLogs SaveLogsConfig
  138. DefaultIconForActions string
  139. DefaultIconForDirectories string
  140. DefaultIconForBack string
  141. AdditionalNavigationLinks []*NavigationLink
  142. ServiceHostMode string
  143. StyleMods []string
  144. usedConfigDir string
  145. }
  146. type AuthLocalUsersConfig struct {
  147. Enabled bool
  148. Users []*LocalUser
  149. }
  150. type LocalUser struct {
  151. Username string
  152. Usergroup string
  153. Password string
  154. }
  155. type OAuth2Provider struct {
  156. Name string
  157. Title string
  158. ClientID string
  159. ClientSecret string
  160. Icon string
  161. Scopes []string
  162. AuthUrl string
  163. TokenUrl string
  164. WhoamiUrl string
  165. UsernameField string
  166. UserGroupField string
  167. InsecureSkipVerify bool
  168. CallbackTimeout int
  169. CertBundlePath string
  170. }
  171. type NavigationLink struct {
  172. Title string
  173. Url string
  174. Target string
  175. }
  176. type SaveLogsConfig struct {
  177. ResultsDirectory string
  178. OutputDirectory string
  179. }
  180. type LogDebugOptions struct {
  181. SingleFrontendRequests bool
  182. SingleFrontendRequestHeaders bool
  183. AclCheckStarted bool
  184. AclMatched bool
  185. AclNotMatched bool
  186. AclNoneMatched bool
  187. }
  188. type DashboardComponent struct {
  189. Title string
  190. Type string
  191. Entity string
  192. Icon string
  193. CssClass string
  194. Contents []DashboardComponent
  195. }
  196. func DefaultConfig() *Config {
  197. return DefaultConfigWithBasePort(1337)
  198. }
  199. // DefaultConfig gets a new Config structure with sensible default values.
  200. func DefaultConfigWithBasePort(basePort int) *Config {
  201. config := Config{}
  202. config.UseSingleHTTPFrontend = true
  203. config.PageTitle = "OliveTin"
  204. config.ShowFooter = true
  205. config.ShowNavigation = true
  206. config.ShowNewVersions = true
  207. config.EnableCustomJs = false
  208. config.ExternalRestAddress = "."
  209. config.LogLevel = "INFO"
  210. config.LogHistoryPageSize = 10
  211. config.CheckForUpdates = false
  212. config.DefaultPermissions.Exec = true
  213. config.DefaultPermissions.View = true
  214. config.DefaultPermissions.Logs = true
  215. config.DefaultPermissions.Kill = true
  216. config.AuthJwtClaimUsername = "name"
  217. config.AuthJwtClaimUserGroup = "group"
  218. config.AuthRequireGuestsToLogin = false
  219. config.WebUIDir = "./webui"
  220. config.CronSupportForSeconds = false
  221. config.SectionNavigationStyle = "sidebar"
  222. config.DefaultPopupOnStart = "nothing"
  223. config.InsecureAllowDumpVars = false
  224. config.InsecureAllowDumpSos = false
  225. config.InsecureAllowDumpActionMap = false
  226. config.InsecureAllowDumpJwtClaims = false
  227. config.Prometheus.Enabled = false
  228. config.Prometheus.DefaultGoMetrics = false
  229. config.DefaultIconForActions = "😀"
  230. config.DefaultIconForDirectories = "&#128193"
  231. config.DefaultIconForBack = "«"
  232. config.ThemeCacheDisabled = false
  233. config.ServiceHostMode = ""
  234. config.ListenAddressSingleHTTPFrontend = fmt.Sprintf("0.0.0.0:%d", basePort)
  235. config.ListenAddressRestActions = fmt.Sprintf("localhost:%d", basePort+1)
  236. config.ListenAddressGrpcActions = fmt.Sprintf("localhost:%d", basePort+2)
  237. config.ListenAddressWebUI = fmt.Sprintf("localhost:%d", basePort+3)
  238. config.ListenAddressPrometheus = fmt.Sprintf("localhost:%d", basePort+4)
  239. config.DefaultPolicy.ShowDiagnostics = true
  240. config.DefaultPolicy.ShowLogList = true
  241. return &config
  242. }