settings.js 16 KB

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