settings.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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. i18n: {
  211. subdomainLang: {
  212. www: {
  213. lngCode: process.env.SHARELATEX_SITE_LANGUAGE || 'en',
  214. url: siteUrl,
  215. },
  216. },
  217. defaultLng: process.env.SHARELATEX_SITE_LANGUAGE || 'en',
  218. },
  219. currentImageName: process.env.TEX_LIVE_DOCKER_IMAGE,
  220. apis: {
  221. web: {
  222. url: 'http://localhost:3000',
  223. user: httpAuthUser,
  224. pass: httpAuthPass,
  225. },
  226. project_history: {
  227. sendProjectStructureOps: true,
  228. url: 'http://localhost:3054',
  229. },
  230. v1_history: {
  231. url: process.env.V1_HISTORY_URL || 'http://localhost:3100/api',
  232. user: 'staging',
  233. pass: process.env.STAGING_PASSWORD,
  234. requestTimeout: parseInt(
  235. process.env.SHARELATEX_HISTORY_V1_HTTP_REQUEST_TIMEOUT || '300000', // default is 5min
  236. 10
  237. ),
  238. },
  239. },
  240. references: {},
  241. notifications: undefined,
  242. defaultFeatures: {
  243. collaborators: -1,
  244. dropbox: true,
  245. versioning: true,
  246. compileTimeout: parseIntOrFail(process.env.COMPILE_TIMEOUT || 180),
  247. compileGroup: 'standard',
  248. trackChanges: true,
  249. templates: true,
  250. references: true,
  251. },
  252. }
  253. // # OPTIONAL CONFIGURABLE SETTINGS
  254. if (process.env.SHARELATEX_LEFT_FOOTER != null) {
  255. try {
  256. settings.nav.left_footer = JSON.parse(process.env.SHARELATEX_LEFT_FOOTER)
  257. } catch (error) {
  258. e = error
  259. console.error('could not parse SHARELATEX_LEFT_FOOTER, not valid JSON')
  260. }
  261. }
  262. if (process.env.SHARELATEX_RIGHT_FOOTER != null) {
  263. settings.nav.right_footer = process.env.SHARELATEX_RIGHT_FOOTER
  264. try {
  265. settings.nav.right_footer = JSON.parse(process.env.SHARELATEX_RIGHT_FOOTER)
  266. } catch (error1) {
  267. e = error1
  268. console.error('could not parse SHARELATEX_RIGHT_FOOTER, not valid JSON')
  269. }
  270. }
  271. if (process.env.SHARELATEX_HEADER_IMAGE_URL != null) {
  272. settings.nav.custom_logo = process.env.SHARELATEX_HEADER_IMAGE_URL
  273. }
  274. if (process.env.SHARELATEX_HEADER_NAV_LINKS != null) {
  275. console.error(`\
  276. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  277. #
  278. # WARNING: SHARELATEX_HEADER_NAV_LINKS is no longer supported
  279. # See https://github.com/sharelatex/sharelatex/wiki/Configuring-Headers,-Footers-&-Logo
  280. #
  281. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\
  282. `)
  283. }
  284. if (process.env.SHARELATEX_HEADER_EXTRAS != null) {
  285. try {
  286. settings.nav.header_extras = JSON.parse(
  287. process.env.SHARELATEX_HEADER_EXTRAS
  288. )
  289. } catch (error2) {
  290. e = error2
  291. console.error('could not parse SHARELATEX_HEADER_EXTRAS, not valid JSON')
  292. }
  293. }
  294. // Sending Email
  295. // -------------
  296. //
  297. // You must configure a mail server to be able to send invite emails from
  298. // ShareLaTeX. The config settings are passed to nodemailer. See the nodemailer
  299. // documentation for available options:
  300. //
  301. // http://www.nodemailer.com/docs/transports
  302. if (process.env.SHARELATEX_EMAIL_FROM_ADDRESS != null) {
  303. settings.email = {
  304. fromAddress: process.env.SHARELATEX_EMAIL_FROM_ADDRESS,
  305. replyTo: process.env.SHARELATEX_EMAIL_REPLY_TO || '',
  306. driver: process.env.SHARELATEX_EMAIL_DRIVER,
  307. parameters: {
  308. // AWS Creds
  309. AWSAccessKeyID: process.env.SHARELATEX_EMAIL_AWS_SES_ACCESS_KEY_ID,
  310. AWSSecretKey: process.env.SHARELATEX_EMAIL_AWS_SES_SECRET_KEY,
  311. // SMTP Creds
  312. host: process.env.SHARELATEX_EMAIL_SMTP_HOST,
  313. port: process.env.SHARELATEX_EMAIL_SMTP_PORT,
  314. secure: parse(process.env.SHARELATEX_EMAIL_SMTP_SECURE),
  315. ignoreTLS: parse(process.env.SHARELATEX_EMAIL_SMTP_IGNORE_TLS),
  316. name: process.env.SHARELATEX_EMAIL_SMTP_NAME,
  317. logger: process.env.SHARELATEX_EMAIL_SMTP_LOGGER === 'true',
  318. },
  319. textEncoding: process.env.SHARELATEX_EMAIL_TEXT_ENCODING,
  320. template: {
  321. customFooter: process.env.SHARELATEX_CUSTOM_EMAIL_FOOTER,
  322. },
  323. }
  324. if (process.env.SHARELATEX_EMAIL_AWS_SES_REGION != null) {
  325. settings.email.parameters.region =
  326. process.env.SHARELATEX_EMAIL_AWS_SES_REGION
  327. }
  328. if (
  329. process.env.SHARELATEX_EMAIL_SMTP_USER != null ||
  330. process.env.SHARELATEX_EMAIL_SMTP_PASS != null
  331. ) {
  332. settings.email.parameters.auth = {
  333. user: process.env.SHARELATEX_EMAIL_SMTP_USER,
  334. pass: process.env.SHARELATEX_EMAIL_SMTP_PASS,
  335. }
  336. }
  337. if (process.env.SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH != null) {
  338. settings.email.parameters.tls = {
  339. rejectUnauthorized: parse(
  340. process.env.SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH
  341. ),
  342. }
  343. }
  344. }
  345. // i18n
  346. if (process.env.SHARELATEX_LANG_DOMAIN_MAPPING != null) {
  347. settings.i18n.subdomainLang = parse(
  348. process.env.SHARELATEX_LANG_DOMAIN_MAPPING
  349. )
  350. }
  351. // Password Settings
  352. // -----------
  353. // These restrict the passwords users can use when registering
  354. // opts are from http://antelle.github.io/passfield
  355. if (
  356. process.env.SHARELATEX_PASSWORD_VALIDATION_PATTERN ||
  357. process.env.SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH ||
  358. process.env.SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH
  359. ) {
  360. settings.passwordStrengthOptions = {
  361. pattern: process.env.SHARELATEX_PASSWORD_VALIDATION_PATTERN || 'aA$3',
  362. length: {
  363. min: process.env.SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH || 8,
  364. max: process.env.SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH || 72,
  365. },
  366. }
  367. }
  368. // ######################
  369. // ShareLaTeX Server Pro
  370. // ######################
  371. if (parse(process.env.SHARELATEX_IS_SERVER_PRO) === true) {
  372. settings.bypassPercentageRollouts = true
  373. settings.apis.references = { url: 'http://localhost:3040' }
  374. }
  375. // Compiler
  376. // --------
  377. if (process.env.SANDBOXED_COMPILES === 'true') {
  378. settings.clsi = {
  379. dockerRunner: true,
  380. docker: {
  381. image: process.env.TEX_LIVE_DOCKER_IMAGE,
  382. env: {
  383. HOME: '/tmp',
  384. PATH:
  385. process.env.COMPILER_PATH ||
  386. '/usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  387. },
  388. user: 'www-data',
  389. },
  390. }
  391. if (settings.path == null) {
  392. settings.path = {}
  393. }
  394. settings.path.synctexBaseDir = () => '/compile'
  395. if (process.env.SANDBOXED_COMPILES_SIBLING_CONTAINERS === 'true') {
  396. console.log('Using sibling containers for sandboxed compiles')
  397. if (process.env.SANDBOXED_COMPILES_HOST_DIR) {
  398. settings.path.sandboxedCompilesHostDir =
  399. process.env.SANDBOXED_COMPILES_HOST_DIR
  400. } else {
  401. console.error(
  402. 'Sibling containers, but SANDBOXED_COMPILES_HOST_DIR not set'
  403. )
  404. }
  405. }
  406. }
  407. // Templates
  408. // ---------
  409. if (process.env.SHARELATEX_TEMPLATES_USER_ID) {
  410. settings.templates = {
  411. mountPointUrl: '/templates',
  412. user_id: process.env.SHARELATEX_TEMPLATES_USER_ID,
  413. }
  414. settings.templateLinks = parse(
  415. process.env.SHARELATEX_NEW_PROJECT_TEMPLATE_LINKS
  416. )
  417. }
  418. // /Learn
  419. // -------
  420. if (process.env.SHARELATEX_PROXY_LEARN != null) {
  421. settings.proxyLearn = parse(process.env.SHARELATEX_PROXY_LEARN)
  422. if (settings.proxyLearn) {
  423. settings.nav.header_extras = [
  424. {
  425. url: '/learn',
  426. text: 'documentation',
  427. },
  428. ].concat(settings.nav.header_extras || [])
  429. }
  430. }
  431. // /References
  432. // -----------
  433. if (process.env.SHARELATEX_ELASTICSEARCH_URL != null) {
  434. settings.references.elasticsearch = {
  435. host: process.env.SHARELATEX_ELASTICSEARCH_URL,
  436. }
  437. }
  438. // filestore
  439. switch (process.env.SHARELATEX_FILESTORE_BACKEND) {
  440. case 's3':
  441. settings.filestore = {
  442. backend: 's3',
  443. stores: {
  444. user_files: process.env.SHARELATEX_FILESTORE_USER_FILES_BUCKET_NAME,
  445. template_files:
  446. process.env.SHARELATEX_FILESTORE_TEMPLATE_FILES_BUCKET_NAME,
  447. },
  448. s3: {
  449. key:
  450. process.env.SHARELATEX_FILESTORE_S3_ACCESS_KEY_ID ||
  451. process.env.AWS_ACCESS_KEY_ID,
  452. secret:
  453. process.env.SHARELATEX_FILESTORE_S3_SECRET_ACCESS_KEY ||
  454. process.env.AWS_SECRET_ACCESS_KEY,
  455. endpoint: process.env.SHARELATEX_FILESTORE_S3_ENDPOINT,
  456. pathStyle: process.env.SHARELATEX_FILESTORE_S3_PATH_STYLE === 'true',
  457. region:
  458. process.env.SHARELATEX_FILESTORE_S3_REGION ||
  459. process.env.AWS_DEFAULT_REGION,
  460. },
  461. }
  462. break
  463. default:
  464. settings.filestore = {
  465. backend: 'fs',
  466. stores: {
  467. user_files: Path.join(DATA_DIR, 'user_files'),
  468. template_files: Path.join(DATA_DIR, 'template_files'),
  469. },
  470. }
  471. }
  472. // With lots of incoming and outgoing HTTP connections to different services,
  473. // sometimes long running, it is a good idea to increase the default number
  474. // of sockets that Node will hold open.
  475. const http = require('http')
  476. http.globalAgent.maxSockets = 300
  477. const https = require('https')
  478. https.globalAgent.maxSockets = 300
  479. module.exports = settings