settings.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. /* eslint-disable
  2. camelcase,
  3. no-cond-assign,
  4. no-dupe-keys,
  5. no-unused-vars,
  6. */
  7. // TODO: This file was created by bulk-decaffeinate.
  8. // Fix any style issues and re-enable lint.
  9. /*
  10. * decaffeinate suggestions:
  11. * DS205: Consider reworking code to avoid use of IIFEs
  12. * DS207: Consider shorter variations of null checks
  13. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  14. */
  15. let redisConfig, siteUrl
  16. let e
  17. const Path = require('path')
  18. // These credentials are used for authenticating api requests
  19. // between services that may need to go over public channels
  20. const httpAuthUser = process.env.WEB_API_USER
  21. const httpAuthPass = process.env.WEB_API_PASSWORD
  22. const httpAuthUsers = {}
  23. if (httpAuthUser && httpAuthPass) {
  24. httpAuthUsers[httpAuthUser] = httpAuthPass
  25. }
  26. const parse = function (option) {
  27. if (option != null) {
  28. try {
  29. const opt = JSON.parse(option)
  30. return opt
  31. } catch (err) {
  32. throw new Error(`problem parsing ${option}, invalid JSON`)
  33. }
  34. }
  35. }
  36. const parseIntOrFail = function (value) {
  37. const parsedValue = parseInt(value, 10)
  38. if (isNaN(parsedValue)) {
  39. throw new Error(`'${value}' is an invalid integer`)
  40. }
  41. return parsedValue
  42. }
  43. const DATA_DIR = '/var/lib/overleaf/data'
  44. const TMP_DIR = '/var/lib/overleaf/tmp'
  45. const settings = {
  46. clsi: {
  47. optimiseInDocker: process.env.OPTIMISE_PDF === 'true',
  48. },
  49. brandPrefix: '',
  50. allowAnonymousReadAndWriteSharing:
  51. process.env.OVERLEAF_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING === 'true',
  52. // Databases
  53. // ---------
  54. // Overleaf Community Edition's main persistent data store is MongoDB (http://www.mongodb.org/)
  55. // Documentation about the URL connection string format can be found at:
  56. //
  57. // http://docs.mongodb.org/manual/reference/connection-string/
  58. //
  59. // The following works out of the box with Mongo's default settings:
  60. mongo: {
  61. url: process.env.OVERLEAF_MONGO_URL || 'mongodb://dockerhost/sharelatex',
  62. },
  63. // Redis is used in Overleaf Community Edition for high volume queries, like real-time
  64. // editing, and session management.
  65. //
  66. // The following config will work with Redis's default settings:
  67. redis: {
  68. web: (redisConfig = {
  69. host: process.env.OVERLEAF_REDIS_HOST || 'dockerhost',
  70. port: process.env.OVERLEAF_REDIS_PORT || '6379',
  71. password: process.env.OVERLEAF_REDIS_PASS || undefined,
  72. tls: process.env.OVERLEAF_REDIS_TLS === 'true' ? {} : undefined,
  73. key_schema: {
  74. // document-updater
  75. blockingKey({ doc_id }) {
  76. return `Blocking:${doc_id}`
  77. },
  78. docLines({ doc_id }) {
  79. return `doclines:${doc_id}`
  80. },
  81. docOps({ doc_id }) {
  82. return `DocOps:${doc_id}`
  83. },
  84. docVersion({ doc_id }) {
  85. return `DocVersion:${doc_id}`
  86. },
  87. docHash({ doc_id }) {
  88. return `DocHash:${doc_id}`
  89. },
  90. projectKey({ doc_id }) {
  91. return `ProjectId:${doc_id}`
  92. },
  93. docsInProject({ project_id }) {
  94. return `DocsIn:${project_id}`
  95. },
  96. ranges({ doc_id }) {
  97. return `Ranges:${doc_id}`
  98. },
  99. // document-updater:realtime
  100. pendingUpdates({ doc_id }) {
  101. return `PendingUpdates:${doc_id}`
  102. },
  103. // document-updater:history
  104. uncompressedHistoryOps({ doc_id }) {
  105. return `UncompressedHistoryOps:${doc_id}`
  106. },
  107. docsWithHistoryOps({ project_id }) {
  108. return `DocsWithHistoryOps:${project_id}`
  109. },
  110. // document-updater:lock
  111. blockingKey({ doc_id }) {
  112. return `Blocking:${doc_id}`
  113. },
  114. // realtime
  115. clientsInProject({ project_id }) {
  116. return `clients_in_project:${project_id}`
  117. },
  118. connectedUser({ project_id, client_id }) {
  119. return `connected_user:${project_id}:${client_id}`
  120. },
  121. },
  122. }),
  123. fairy: redisConfig,
  124. // document-updater
  125. realtime: redisConfig,
  126. documentupdater: redisConfig,
  127. lock: redisConfig,
  128. history: redisConfig,
  129. websessions: redisConfig,
  130. api: redisConfig,
  131. pubsub: redisConfig,
  132. project_history: redisConfig,
  133. references: redisConfig,
  134. project_history_migration: {
  135. host: redisConfig.host,
  136. port: redisConfig.port,
  137. password: redisConfig.password,
  138. maxRetriesPerRequest: parseInt(
  139. process.env.REDIS_MAX_RETRIES_PER_REQUEST || '20'
  140. ),
  141. key_schema: {
  142. projectHistoryOps({ projectId }) {
  143. return `ProjectHistory:Ops:{${projectId}}` // NOTE: the extra braces are intentional
  144. },
  145. },
  146. },
  147. },
  148. // Local disk caching
  149. // ------------------
  150. path: {
  151. // If we ever need to write something to disk (e.g. incoming requests
  152. // that need processing but may be too big for memory), then write
  153. // them to disk here:
  154. dumpFolder: Path.join(TMP_DIR, 'dumpFolder'),
  155. // Where to write uploads before they are processed
  156. uploadFolder: Path.join(TMP_DIR, 'uploads'),
  157. // Where to write intermediate file for full project history migration
  158. projectHistories: Path.join(TMP_DIR, 'projectHistories'),
  159. // Where to write the project to disk before running LaTeX on it
  160. compilesDir: Path.join(DATA_DIR, 'compiles'),
  161. // Where to cache downloaded URLs for the CLSI
  162. clsiCacheDir: Path.join(DATA_DIR, 'cache'),
  163. // Where to write the output files to disk after running LaTeX
  164. outputDir: Path.join(DATA_DIR, 'output'),
  165. },
  166. // Server Config
  167. // -------------
  168. // Where your instance of Overleaf Community Edition can be found publicly. This is used
  169. // when emails are sent out and in generated links:
  170. siteUrl: (siteUrl = process.env.OVERLEAF_SITE_URL || 'http://localhost'),
  171. // Status page URL as displayed on the maintenance/500 pages.
  172. statusPageUrl: process.env.OVERLEAF_STATUS_PAGE_URL
  173. ? // Add https:// protocol prefix if not set (Allow plain-text http:// for Server Pro/CE).
  174. process.env.OVERLEAF_STATUS_PAGE_URL.startsWith('http://') ||
  175. process.env.OVERLEAF_STATUS_PAGE_URL.startsWith('https://')
  176. ? process.env.OVERLEAF_STATUS_PAGE_URL
  177. : `https://${process.env.OVERLEAF_STATUS_PAGE_URL}`
  178. : undefined,
  179. maintenanceMessage: process.env.OVERLEAF_MAINTENANCE_MESSAGE,
  180. maintenanceMessageHTML: process.env.OVERLEAF_MAINTENANCE_MESSAGE_HTML,
  181. // The name this is used to describe your Overleaf Community Edition Installation
  182. appName: process.env.OVERLEAF_APP_NAME || 'Overleaf Community Edition',
  183. restrictInvitesToExistingAccounts:
  184. process.env.OVERLEAF_RESTRICT_INVITES_TO_EXISTING_ACCOUNTS === 'true',
  185. nav: {
  186. title:
  187. process.env.OVERLEAF_NAV_TITLE ||
  188. process.env.OVERLEAF_APP_NAME ||
  189. 'Overleaf Community Edition',
  190. },
  191. // The email address which users will be directed to as the main point of
  192. // contact for this installation of Overleaf Community Edition.
  193. adminEmail: process.env.OVERLEAF_ADMIN_EMAIL || 'placeholder@example.com',
  194. // If provided, a sessionSecret is used to sign cookies so that they cannot be
  195. // spoofed. This is recommended.
  196. security: {
  197. sessionSecret:
  198. process.env.OVERLEAF_SESSION_SECRET || process.env.CRYPTO_RANDOM,
  199. },
  200. csp: {
  201. enabled: process.env.OVERLEAF_CSP_ENABLED !== 'false',
  202. },
  203. rateLimit: {
  204. subnetRateLimiterDisabled:
  205. process.env.SUBNET_RATE_LIMITER_DISABLED !== 'false',
  206. },
  207. // These credentials are used for authenticating api requests
  208. // between services that may need to go over public channels
  209. httpAuthUsers,
  210. // Should javascript assets be served minified or not.
  211. useMinifiedJs: true,
  212. // Should static assets be sent with a header to tell the browser to cache
  213. // them. This should be false in development where changes are being made,
  214. // but should be set to true in production.
  215. cacheStaticAssets: true,
  216. // If you are running Overleaf Community Edition over https, set this to true to send the
  217. // cookie with a secure flag (recommended).
  218. secureCookie: process.env.OVERLEAF_SECURE_COOKIE != null,
  219. // If you are running Overleaf Community Edition behind a proxy (like Apache, Nginx, etc)
  220. // then set this to true to allow it to correctly detect the forwarded IP
  221. // address and http/https protocol information.
  222. behindProxy: true,
  223. trustedProxyIps: process.env.OVERLEAF_TRUSTED_PROXY_IPS || 'loopback',
  224. // The amount of time, in milliseconds, until the (rolling) cookie session expires
  225. cookieSessionLength: parseInt(
  226. process.env.OVERLEAF_COOKIE_SESSION_LENGTH || 5 * 24 * 60 * 60 * 1000, // default 5 days
  227. 10
  228. ),
  229. redisLockTTLSeconds: parseInt(
  230. process.env.OVERLEAF_REDIS_LOCK_TTL_SECONDS || '60',
  231. 10
  232. ),
  233. i18n: {
  234. subdomainLang: {
  235. www: {
  236. lngCode: process.env.OVERLEAF_SITE_LANGUAGE || 'en',
  237. url: siteUrl,
  238. },
  239. },
  240. defaultLng: process.env.OVERLEAF_SITE_LANGUAGE || 'en',
  241. },
  242. currentImageName: process.env.TEX_LIVE_DOCKER_IMAGE,
  243. apis: {
  244. web: {
  245. url: 'http://127.0.0.1:3000',
  246. user: httpAuthUser,
  247. pass: httpAuthPass,
  248. },
  249. project_history: {
  250. sendProjectStructureOps: true,
  251. url: 'http://127.0.0.1:3054',
  252. },
  253. v1_history: {
  254. url: process.env.V1_HISTORY_URL || 'http://127.0.0.1:3100/api',
  255. user: 'staging',
  256. pass: process.env.STAGING_PASSWORD,
  257. requestTimeout: parseInt(
  258. process.env.OVERLEAF_HISTORY_V1_HTTP_REQUEST_TIMEOUT || '300000', // default is 5min
  259. 10
  260. ),
  261. },
  262. },
  263. references: {},
  264. notifications: undefined,
  265. defaultFeatures: {
  266. collaborators: -1,
  267. dropbox: true,
  268. versioning: true,
  269. compileTimeout: parseIntOrFail(process.env.COMPILE_TIMEOUT || 180),
  270. compileGroup: 'standard',
  271. trackChanges: true,
  272. references: true,
  273. },
  274. }
  275. // # OPTIONAL CONFIGURABLE SETTINGS
  276. if (process.env.OVERLEAF_LEFT_FOOTER != null) {
  277. try {
  278. settings.nav.left_footer = JSON.parse(process.env.OVERLEAF_LEFT_FOOTER)
  279. } catch (error) {
  280. e = error
  281. console.error('could not parse OVERLEAF_LEFT_FOOTER, not valid JSON')
  282. }
  283. }
  284. if (process.env.OVERLEAF_RIGHT_FOOTER != null) {
  285. settings.nav.right_footer = process.env.OVERLEAF_RIGHT_FOOTER
  286. try {
  287. settings.nav.right_footer = JSON.parse(process.env.OVERLEAF_RIGHT_FOOTER)
  288. } catch (error1) {
  289. e = error1
  290. console.error('could not parse OVERLEAF_RIGHT_FOOTER, not valid JSON')
  291. }
  292. }
  293. if (process.env.OVERLEAF_HEADER_IMAGE_URL != null) {
  294. settings.nav.custom_logo = process.env.OVERLEAF_HEADER_IMAGE_URL
  295. }
  296. if (process.env.OVERLEAF_HEADER_EXTRAS != null) {
  297. try {
  298. settings.nav.header_extras = JSON.parse(process.env.OVERLEAF_HEADER_EXTRAS)
  299. } catch (error2) {
  300. e = error2
  301. console.error('could not parse OVERLEAF_HEADER_EXTRAS, not valid JSON')
  302. }
  303. }
  304. if (process.env.OVERLEAF_LOGIN_SUPPORT_TEXT != null) {
  305. settings.nav.login_support_text = process.env.OVERLEAF_LOGIN_SUPPORT_TEXT
  306. }
  307. if (process.env.OVERLEAF_LOGIN_SUPPORT_TITLE != null) {
  308. settings.nav.login_support_title = process.env.OVERLEAF_LOGIN_SUPPORT_TITLE
  309. }
  310. // Sending Email
  311. // -------------
  312. //
  313. // You must configure a mail server to be able to send invite emails from
  314. // Overleaf Community Edition. The config settings are passed to nodemailer. See the nodemailer
  315. // documentation for available options:
  316. //
  317. // http://www.nodemailer.com/docs/transports
  318. if (process.env.OVERLEAF_EMAIL_FROM_ADDRESS != null) {
  319. settings.email = {
  320. fromAddress: process.env.OVERLEAF_EMAIL_FROM_ADDRESS,
  321. replyTo: process.env.OVERLEAF_EMAIL_REPLY_TO || '',
  322. driver: process.env.OVERLEAF_EMAIL_DRIVER,
  323. parameters: {
  324. // AWS Creds
  325. AWSAccessKeyID: process.env.OVERLEAF_EMAIL_AWS_SES_ACCESS_KEY_ID,
  326. AWSSecretKey: process.env.OVERLEAF_EMAIL_AWS_SES_SECRET_KEY,
  327. // SMTP Creds
  328. host: process.env.OVERLEAF_EMAIL_SMTP_HOST,
  329. port: process.env.OVERLEAF_EMAIL_SMTP_PORT,
  330. secure: parse(process.env.OVERLEAF_EMAIL_SMTP_SECURE),
  331. ignoreTLS: parse(process.env.OVERLEAF_EMAIL_SMTP_IGNORE_TLS),
  332. name: process.env.OVERLEAF_EMAIL_SMTP_NAME,
  333. logger: process.env.OVERLEAF_EMAIL_SMTP_LOGGER === 'true',
  334. },
  335. textEncoding: process.env.OVERLEAF_EMAIL_TEXT_ENCODING,
  336. template: {
  337. customFooter: process.env.OVERLEAF_CUSTOM_EMAIL_FOOTER,
  338. },
  339. }
  340. if (process.env.OVERLEAF_EMAIL_AWS_SES_REGION != null) {
  341. settings.email.parameters.region = process.env.OVERLEAF_EMAIL_AWS_SES_REGION
  342. }
  343. if (
  344. process.env.OVERLEAF_EMAIL_SMTP_USER != null ||
  345. process.env.OVERLEAF_EMAIL_SMTP_PASS != null
  346. ) {
  347. settings.email.parameters.auth = {
  348. user: process.env.OVERLEAF_EMAIL_SMTP_USER,
  349. pass: process.env.OVERLEAF_EMAIL_SMTP_PASS,
  350. }
  351. }
  352. if (process.env.OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH != null) {
  353. settings.email.parameters.tls = {
  354. rejectUnauthorized: parse(
  355. process.env.OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH
  356. ),
  357. }
  358. }
  359. }
  360. // i18n
  361. if (process.env.OVERLEAF_LANG_DOMAIN_MAPPING != null) {
  362. settings.i18n.subdomainLang = parse(process.env.OVERLEAF_LANG_DOMAIN_MAPPING)
  363. }
  364. // Password Settings
  365. // -----------
  366. // These restrict the passwords users can use when registering
  367. // opts are from http://antelle.github.io/passfield
  368. if (
  369. process.env.OVERLEAF_PASSWORD_VALIDATION_PATTERN ||
  370. process.env.OVERLEAF_PASSWORD_VALIDATION_MIN_LENGTH ||
  371. process.env.OVERLEAF_PASSWORD_VALIDATION_MAX_LENGTH
  372. ) {
  373. settings.passwordStrengthOptions = {
  374. pattern: process.env.OVERLEAF_PASSWORD_VALIDATION_PATTERN || 'aA$3',
  375. length: {
  376. min: process.env.OVERLEAF_PASSWORD_VALIDATION_MIN_LENGTH || 8,
  377. max: process.env.OVERLEAF_PASSWORD_VALIDATION_MAX_LENGTH || 72,
  378. },
  379. }
  380. }
  381. // /References
  382. // -----------
  383. if (process.env.OVERLEAF_ELASTICSEARCH_URL != null) {
  384. settings.references.elasticsearch = {
  385. host: process.env.OVERLEAF_ELASTICSEARCH_URL,
  386. }
  387. }
  388. // filestore
  389. switch (process.env.OVERLEAF_FILESTORE_BACKEND) {
  390. case 's3':
  391. settings.filestore = {
  392. backend: 's3',
  393. stores: {
  394. template_files:
  395. process.env.OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME,
  396. project_blobs: process.env.OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET,
  397. global_blobs: process.env.OVERLEAF_HISTORY_BLOBS_BUCKET,
  398. },
  399. s3: {
  400. key:
  401. process.env.OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID ||
  402. process.env.AWS_ACCESS_KEY_ID,
  403. secret:
  404. process.env.OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY ||
  405. process.env.AWS_SECRET_ACCESS_KEY,
  406. endpoint: process.env.OVERLEAF_FILESTORE_S3_ENDPOINT,
  407. pathStyle: process.env.OVERLEAF_FILESTORE_S3_PATH_STYLE === 'true',
  408. region:
  409. process.env.OVERLEAF_FILESTORE_S3_REGION ||
  410. process.env.AWS_DEFAULT_REGION,
  411. },
  412. }
  413. break
  414. default:
  415. settings.filestore = {
  416. backend: 'fs',
  417. stores: {
  418. template_files: Path.join(DATA_DIR, 'template_files'),
  419. // NOTE: The below paths are hard-coded in server-ce/config/production.json, so hard code them here as well.
  420. // We can use DATA_DIR after switching history-v1 from 'config' to '@overleaf/settings'.
  421. project_blobs:
  422. process.env.OVERLEAF_HISTORY_PROJECT_BLOBS_BUCKET ||
  423. '/var/lib/overleaf/data/history/overleaf-project-blobs',
  424. global_blobs:
  425. process.env.OVERLEAF_HISTORY_BLOBS_BUCKET ||
  426. '/var/lib/overleaf/data/history/overleaf-global-blobs',
  427. },
  428. }
  429. }
  430. if (
  431. !settings.trustedProxyIps.includes('loopback') &&
  432. !settings.trustedProxyIps.includes('localhost') &&
  433. !settings.trustedProxyIps.includes('127.0.0.1')
  434. ) {
  435. throw new Error(
  436. 'OVERLEAF_TRUSTED_PROXY_IPS must include one of "loopback", "localhost" or "127.0.0.1", which trusts the nginx instance running inside the container'
  437. )
  438. }
  439. // With lots of incoming and outgoing HTTP connections to different services,
  440. // sometimes long running, it is a good idea to increase the default number
  441. // of sockets that Node will hold open.
  442. const http = require('http')
  443. http.globalAgent.maxSockets = 300
  444. const https = require('https')
  445. https.globalAgent.maxSockets = 300
  446. module.exports = settings