settings.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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/sharelatex/data'
  44. const TMP_DIR = '/var/lib/sharelatex/tmp'
  45. const settings = {
  46. clsi: {
  47. optimiseInDocker: process.env.OPTIMISE_PDF === 'true',
  48. },
  49. brandPrefix: '',
  50. allowAnonymousReadAndWriteSharing:
  51. process.env.SHARELATEX_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. key_schema: {
  73. // document-updater
  74. blockingKey({ doc_id }) {
  75. return `Blocking:${doc_id}`
  76. },
  77. docLines({ doc_id }) {
  78. return `doclines:${doc_id}`
  79. },
  80. docOps({ doc_id }) {
  81. return `DocOps:${doc_id}`
  82. },
  83. docVersion({ doc_id }) {
  84. return `DocVersion:${doc_id}`
  85. },
  86. docHash({ doc_id }) {
  87. return `DocHash:${doc_id}`
  88. },
  89. projectKey({ doc_id }) {
  90. return `ProjectId:${doc_id}`
  91. },
  92. docsInProject({ project_id }) {
  93. return `DocsIn:${project_id}`
  94. },
  95. ranges({ doc_id }) {
  96. return `Ranges:${doc_id}`
  97. },
  98. // document-updater:realtime
  99. pendingUpdates({ doc_id }) {
  100. return `PendingUpdates:${doc_id}`
  101. },
  102. // document-updater:history
  103. uncompressedHistoryOps({ doc_id }) {
  104. return `UncompressedHistoryOps:${doc_id}`
  105. },
  106. docsWithHistoryOps({ project_id }) {
  107. return `DocsWithHistoryOps:${project_id}`
  108. },
  109. // document-updater:lock
  110. blockingKey({ doc_id }) {
  111. return `Blocking:${doc_id}`
  112. },
  113. // realtime
  114. clientsInProject({ project_id }) {
  115. return `clients_in_project:${project_id}`
  116. },
  117. connectedUser({ project_id, client_id }) {
  118. return `connected_user:${project_id}:${client_id}`
  119. },
  120. },
  121. }),
  122. fairy: redisConfig,
  123. // document-updater
  124. realtime: redisConfig,
  125. documentupdater: redisConfig,
  126. lock: redisConfig,
  127. history: redisConfig,
  128. websessions: redisConfig,
  129. api: redisConfig,
  130. pubsub: redisConfig,
  131. project_history: redisConfig,
  132. project_history_migration: {
  133. host: redisConfig.host,
  134. port: redisConfig.port,
  135. password: redisConfig.password,
  136. maxRetriesPerRequest: parseInt(
  137. process.env.REDIS_MAX_RETRIES_PER_REQUEST || '20'
  138. ),
  139. key_schema: {
  140. projectHistoryOps({ projectId }) {
  141. return `ProjectHistory:Ops:{${projectId}}` // NOTE: the extra braces are intentional
  142. },
  143. },
  144. },
  145. },
  146. // Local disk caching
  147. // ------------------
  148. path: {
  149. // If we ever need to write something to disk (e.g. incoming requests
  150. // that need processing but may be too big for memory), then write
  151. // them to disk here:
  152. dumpFolder: Path.join(TMP_DIR, 'dumpFolder'),
  153. // Where to write uploads before they are processed
  154. uploadFolder: Path.join(TMP_DIR, 'uploads'),
  155. // Where to write intermediate file for full project history migration
  156. projectHistories: Path.join(TMP_DIR, 'projectHistories'),
  157. // Where to write the project to disk before running LaTeX on it
  158. compilesDir: Path.join(DATA_DIR, 'compiles'),
  159. // Where to cache downloaded URLs for the CLSI
  160. clsiCacheDir: Path.join(DATA_DIR, 'cache'),
  161. // Where to write the output files to disk after running LaTeX
  162. outputDir: Path.join(DATA_DIR, 'output'),
  163. },
  164. // Server Config
  165. // -------------
  166. // Where your instance of Overleaf Community Edition can be found publicly. This is used
  167. // when emails are sent out and in generated links:
  168. siteUrl: (siteUrl = process.env.OVERLEAF_SITE_URL || 'http://localhost'),
  169. // Status page URL as displayed on the maintenance/500 pages.
  170. statusPageUrl: process.env.OVERLEAF_STATUS_PAGE_URL,
  171. // The name this is used to describe your Overleaf Community Edition Installation
  172. appName: process.env.OVERLEAF_APP_NAME || 'Overleaf Community Edition',
  173. restrictInvitesToExistingAccounts:
  174. process.env.OVERLEAF_RESTRICT_INVITES_TO_EXISTING_ACCOUNTS === 'true',
  175. nav: {
  176. title:
  177. process.env.OVERLEAF_NAV_TITLE ||
  178. process.env.OVERLEAF_APP_NAME ||
  179. 'Overleaf Community Edition',
  180. },
  181. // The email address which users will be directed to as the main point of
  182. // contact for this installation of Overleaf Community Edition.
  183. adminEmail: process.env.OVERLEAF_ADMIN_EMAIL || 'placeholder@example.com',
  184. // If provided, a sessionSecret is used to sign cookies so that they cannot be
  185. // spoofed. This is recommended.
  186. security: {
  187. sessionSecret:
  188. process.env.OVERLEAF_SESSION_SECRET || process.env.CRYPTO_RANDOM,
  189. },
  190. // These credentials are used for authenticating api requests
  191. // between services that may need to go over public channels
  192. httpAuthUsers,
  193. // Should javascript assets be served minified or not.
  194. useMinifiedJs: true,
  195. // Should static assets be sent with a header to tell the browser to cache
  196. // them. This should be false in development where changes are being made,
  197. // but should be set to true in production.
  198. cacheStaticAssets: true,
  199. // If you are running Overleaf Community Edition over https, set this to true to send the
  200. // cookie with a secure flag (recommended).
  201. secureCookie: process.env.OVERLEAF_SECURE_COOKIE != null,
  202. // If you are running Overleaf Community Edition behind a proxy (like Apache, Nginx, etc)
  203. // then set this to true to allow it to correctly detect the forwarded IP
  204. // address and http/https protocol information.
  205. behindProxy: process.env.OVERLEAF_BEHIND_PROXY || false,
  206. trustedProxyIps: process.env.SHARELATEX_TRUSTED_PROXY_IPS,
  207. // The amount of time, in milliseconds, until the (rolling) cookie session expires
  208. cookieSessionLength: parseInt(
  209. process.env.OVERLEAF_COOKIE_SESSION_LENGTH || 5 * 24 * 60 * 60 * 1000, // default 5 days
  210. 10
  211. ),
  212. redisLockTTLSeconds: parseInt(
  213. process.env.SHARELATEX_REDIS_LOCK_TTL_SECONDS || '60',
  214. 10
  215. ),
  216. i18n: {
  217. subdomainLang: {
  218. www: {
  219. lngCode: process.env.SHARELATEX_SITE_LANGUAGE || 'en',
  220. url: siteUrl,
  221. },
  222. },
  223. defaultLng: process.env.SHARELATEX_SITE_LANGUAGE || 'en',
  224. },
  225. currentImageName: process.env.TEX_LIVE_DOCKER_IMAGE,
  226. apis: {
  227. web: {
  228. url: 'http://localhost:3000',
  229. user: httpAuthUser,
  230. pass: httpAuthPass,
  231. },
  232. project_history: {
  233. sendProjectStructureOps: true,
  234. url: 'http://localhost:3054',
  235. },
  236. v1_history: {
  237. url: process.env.V1_HISTORY_URL || 'http://localhost:3100/api',
  238. user: 'staging',
  239. pass: process.env.STAGING_PASSWORD,
  240. requestTimeout: parseInt(
  241. process.env.OVERLEAF_HISTORY_V1_HTTP_REQUEST_TIMEOUT || '300000', // default is 5min
  242. 10
  243. ),
  244. },
  245. },
  246. references: {},
  247. notifications: undefined,
  248. defaultFeatures: {
  249. collaborators: -1,
  250. dropbox: true,
  251. versioning: true,
  252. compileTimeout: parseIntOrFail(process.env.COMPILE_TIMEOUT || 180),
  253. compileGroup: 'standard',
  254. trackChanges: true,
  255. templates: true,
  256. references: true,
  257. },
  258. }
  259. // # OPTIONAL CONFIGURABLE SETTINGS
  260. if (process.env.OVERLEAF_LEFT_FOOTER != null) {
  261. try {
  262. settings.nav.left_footer = JSON.parse(process.env.OVERLEAF_LEFT_FOOTER)
  263. } catch (error) {
  264. e = error
  265. console.error('could not parse OVERLEAF_LEFT_FOOTER, not valid JSON')
  266. }
  267. }
  268. if (process.env.OVERLEAF_RIGHT_FOOTER != null) {
  269. settings.nav.right_footer = process.env.OVERLEAF_RIGHT_FOOTER
  270. try {
  271. settings.nav.right_footer = JSON.parse(process.env.OVERLEAF_RIGHT_FOOTER)
  272. } catch (error1) {
  273. e = error1
  274. console.error('could not parse OVERLEAF_RIGHT_FOOTER, not valid JSON')
  275. }
  276. }
  277. if (process.env.OVERLEAF_HEADER_IMAGE_URL != null) {
  278. settings.nav.custom_logo = process.env.OVERLEAF_HEADER_IMAGE_URL
  279. }
  280. if (process.env.SHARELATEX_HEADER_NAV_LINKS != null) {
  281. console.error(`\
  282. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  283. #
  284. # WARNING: SHARELATEX_HEADER_NAV_LINKS is no longer supported
  285. # See https://github.com/overleaf/overleaf/wiki/Configuring-Headers,-Footers-&-Logo
  286. #
  287. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\
  288. `)
  289. }
  290. if (process.env.OVERLEAF_HEADER_EXTRAS != null) {
  291. try {
  292. settings.nav.header_extras = JSON.parse(process.env.OVERLEAF_HEADER_EXTRAS)
  293. } catch (error2) {
  294. e = error2
  295. console.error('could not parse OVERLEAF_HEADER_EXTRAS, not valid JSON')
  296. }
  297. }
  298. // Sending Email
  299. // -------------
  300. //
  301. // You must configure a mail server to be able to send invite emails from
  302. // Overleaf Community Edition. The config settings are passed to nodemailer. See the nodemailer
  303. // documentation for available options:
  304. //
  305. // http://www.nodemailer.com/docs/transports
  306. if (process.env.OVERLEAF_EMAIL_FROM_ADDRESS != null) {
  307. settings.email = {
  308. fromAddress: process.env.OVERLEAF_EMAIL_FROM_ADDRESS,
  309. replyTo: process.env.OVERLEAF_EMAIL_REPLY_TO || '',
  310. driver: process.env.OVERLEAF_EMAIL_DRIVER,
  311. parameters: {
  312. // AWS Creds
  313. AWSAccessKeyID: process.env.OVERLEAF_EMAIL_AWS_SES_ACCESS_KEY_ID,
  314. AWSSecretKey: process.env.OVERLEAF_EMAIL_AWS_SES_SECRET_KEY,
  315. // SMTP Creds
  316. host: process.env.OVERLEAF_EMAIL_SMTP_HOST,
  317. port: process.env.OVERLEAF_EMAIL_SMTP_PORT,
  318. secure: parse(process.env.OVERLEAF_EMAIL_SMTP_SECURE),
  319. ignoreTLS: parse(process.env.OVERLEAF_EMAIL_SMTP_IGNORE_TLS),
  320. name: process.env.OVERLEAF_EMAIL_SMTP_NAME,
  321. logger: process.env.OVERLEAF_EMAIL_SMTP_LOGGER === 'true',
  322. },
  323. textEncoding: process.env.OVERLEAF_EMAIL_TEXT_ENCODING,
  324. template: {
  325. customFooter: process.env.OVERLEAF_CUSTOM_EMAIL_FOOTER,
  326. },
  327. }
  328. if (process.env.OVERLEAF_EMAIL_AWS_SES_REGION != null) {
  329. settings.email.parameters.region = process.env.OVERLEAF_EMAIL_AWS_SES_REGION
  330. }
  331. if (
  332. process.env.OVERLEAF_EMAIL_SMTP_USER != null ||
  333. process.env.OVERLEAF_EMAIL_SMTP_PASS != null
  334. ) {
  335. settings.email.parameters.auth = {
  336. user: process.env.OVERLEAF_EMAIL_SMTP_USER,
  337. pass: process.env.OVERLEAF_EMAIL_SMTP_PASS,
  338. }
  339. }
  340. if (process.env.OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH != null) {
  341. settings.email.parameters.tls = {
  342. rejectUnauthorized: parse(
  343. process.env.OVERLEAF_EMAIL_SMTP_TLS_REJECT_UNAUTH
  344. ),
  345. }
  346. }
  347. }
  348. // i18n
  349. if (process.env.SHARELATEX_LANG_DOMAIN_MAPPING != null) {
  350. settings.i18n.subdomainLang = parse(
  351. process.env.SHARELATEX_LANG_DOMAIN_MAPPING
  352. )
  353. }
  354. // Password Settings
  355. // -----------
  356. // These restrict the passwords users can use when registering
  357. // opts are from http://antelle.github.io/passfield
  358. if (
  359. process.env.SHARELATEX_PASSWORD_VALIDATION_PATTERN ||
  360. process.env.SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH ||
  361. process.env.SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH
  362. ) {
  363. settings.passwordStrengthOptions = {
  364. pattern: process.env.SHARELATEX_PASSWORD_VALIDATION_PATTERN || 'aA$3',
  365. length: {
  366. min: process.env.SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH || 8,
  367. max: process.env.SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH || 72,
  368. },
  369. }
  370. }
  371. // ######################
  372. // Overleaf Server Pro
  373. // ######################
  374. if (parse(process.env.SHARELATEX_IS_SERVER_PRO) === true) {
  375. settings.bypassPercentageRollouts = true
  376. settings.apis.references = { url: 'http://localhost:3040' }
  377. }
  378. // Compiler
  379. // --------
  380. if (process.env.SANDBOXED_COMPILES === 'true') {
  381. settings.clsi = {
  382. dockerRunner: true,
  383. docker: {
  384. image: process.env.TEX_LIVE_DOCKER_IMAGE,
  385. env: {
  386. HOME: '/tmp',
  387. PATH:
  388. process.env.COMPILER_PATH ||
  389. '/usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  390. },
  391. user: 'www-data',
  392. },
  393. }
  394. if (settings.path == null) {
  395. settings.path = {}
  396. }
  397. settings.path.synctexBaseDir = () => '/compile'
  398. if (process.env.SANDBOXED_COMPILES_SIBLING_CONTAINERS === 'true') {
  399. console.log('Using sibling containers for sandboxed compiles')
  400. if (process.env.SANDBOXED_COMPILES_HOST_DIR) {
  401. settings.path.sandboxedCompilesHostDir =
  402. process.env.SANDBOXED_COMPILES_HOST_DIR
  403. } else {
  404. console.error(
  405. 'Sibling containers, but SANDBOXED_COMPILES_HOST_DIR not set'
  406. )
  407. }
  408. }
  409. }
  410. // Templates
  411. // ---------
  412. if (process.env.OVERLEAF_TEMPLATES_USER_ID) {
  413. settings.templates = {
  414. mountPointUrl: '/templates',
  415. user_id: process.env.OVERLEAF_TEMPLATES_USER_ID,
  416. }
  417. settings.templateLinks = parse(
  418. process.env.OVERLEAF_NEW_PROJECT_TEMPLATE_LINKS
  419. )
  420. }
  421. // /Learn
  422. // -------
  423. if (process.env.OVERLEAF_PROXY_LEARN != null) {
  424. settings.proxyLearn = parse(process.env.OVERLEAF_PROXY_LEARN)
  425. if (settings.proxyLearn) {
  426. settings.nav.header_extras = [
  427. {
  428. url: '/learn',
  429. text: 'documentation',
  430. },
  431. ].concat(settings.nav.header_extras || [])
  432. }
  433. }
  434. // /References
  435. // -----------
  436. if (process.env.SHARELATEX_ELASTICSEARCH_URL != null) {
  437. settings.references.elasticsearch = {
  438. host: process.env.SHARELATEX_ELASTICSEARCH_URL,
  439. }
  440. }
  441. // filestore
  442. switch (process.env.OVERLEAF_FILESTORE_BACKEND) {
  443. case 's3':
  444. settings.filestore = {
  445. backend: 's3',
  446. stores: {
  447. user_files: process.env.OVERLEAF_FILESTORE_USER_FILES_BUCKET_NAME,
  448. template_files:
  449. process.env.OVERLEAF_FILESTORE_TEMPLATE_FILES_BUCKET_NAME,
  450. },
  451. s3: {
  452. key:
  453. process.env.OVERLEAF_FILESTORE_S3_ACCESS_KEY_ID ||
  454. process.env.AWS_ACCESS_KEY_ID,
  455. secret:
  456. process.env.OVERLEAF_FILESTORE_S3_SECRET_ACCESS_KEY ||
  457. process.env.AWS_SECRET_ACCESS_KEY,
  458. endpoint: process.env.OVERLEAF_FILESTORE_S3_ENDPOINT,
  459. pathStyle: process.env.OVERLEAF_FILESTORE_S3_PATH_STYLE === 'true',
  460. region:
  461. process.env.OVERLEAF_FILESTORE_S3_REGION ||
  462. process.env.AWS_DEFAULT_REGION,
  463. },
  464. }
  465. break
  466. default:
  467. settings.filestore = {
  468. backend: 'fs',
  469. stores: {
  470. user_files: Path.join(DATA_DIR, 'user_files'),
  471. template_files: Path.join(DATA_DIR, 'template_files'),
  472. },
  473. }
  474. }
  475. // With lots of incoming and outgoing HTTP connections to different services,
  476. // sometimes long running, it is a good idea to increase the default number
  477. // of sockets that Node will hold open.
  478. const http = require('http')
  479. http.globalAgent.maxSockets = 300
  480. const https = require('https')
  481. https.globalAgent.maxSockets = 300
  482. module.exports = settings