settings.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  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 allTexLiveDockerImageNames, allTexLiveDockerImages, 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. // track-changes:lock
  112. historyLock({ doc_id }) {
  113. return `HistoryLock:${doc_id}`
  114. },
  115. historyIndexLock({ project_id }) {
  116. return `HistoryIndexLock:${project_id}`
  117. },
  118. // track-changes:history
  119. uncompressedHistoryOps({ doc_id }) {
  120. return `UncompressedHistoryOps:${doc_id}`
  121. },
  122. docsWithHistoryOps({ project_id }) {
  123. return `DocsWithHistoryOps:${project_id}`
  124. },
  125. // realtime
  126. clientsInProject({ project_id }) {
  127. return `clients_in_project:${project_id}`
  128. },
  129. connectedUser({ project_id, client_id }) {
  130. return `connected_user:${project_id}:${client_id}`
  131. },
  132. },
  133. }),
  134. fairy: redisConfig,
  135. // track-changes and document-updater
  136. realtime: redisConfig,
  137. documentupdater: redisConfig,
  138. lock: redisConfig,
  139. history: redisConfig,
  140. websessions: redisConfig,
  141. api: redisConfig,
  142. pubsub: redisConfig,
  143. project_history: redisConfig,
  144. },
  145. // The compile server (the clsi) uses a SQL database to cache files and
  146. // meta-data. sqlite is the default, and the load is low enough that this will
  147. // be fine in production (we use sqlite at sharelatex.com).
  148. //
  149. // If you want to configure a different database, see the Sequelize documentation
  150. // for available options:
  151. //
  152. // https://github.com/sequelize/sequelize/wiki/API-Reference-Sequelize#example-usage
  153. //
  154. mysql: {
  155. clsi: {
  156. database: 'clsi',
  157. username: 'clsi',
  158. password: '',
  159. dialect: 'sqlite',
  160. storage: Path.join(DATA_DIR, 'db.sqlite'),
  161. },
  162. },
  163. // File storage
  164. // ------------
  165. // ShareLaTeX can store binary files like images either locally or in Amazon
  166. // S3. The default is locally:
  167. filestore: {
  168. backend: 'fs',
  169. stores: {
  170. user_files: Path.join(DATA_DIR, 'user_files'),
  171. template_files: Path.join(DATA_DIR, 'template_files'),
  172. },
  173. },
  174. // To use Amazon S3 as a storage backend, comment out the above config, and
  175. // uncomment the following, filling in your key, secret, and bucket name:
  176. //
  177. // filestore:
  178. // backend: "s3"
  179. // stores:
  180. // user_files: "BUCKET_NAME"
  181. // s3:
  182. // key: "AWS_KEY"
  183. // secret: "AWS_SECRET"
  184. //
  185. trackchanges: {
  186. continueOnError: true,
  187. },
  188. // Local disk caching
  189. // ------------------
  190. path: {
  191. // If we ever need to write something to disk (e.g. incoming requests
  192. // that need processing but may be too big for memory), then write
  193. // them to disk here:
  194. dumpFolder: Path.join(TMP_DIR, 'dumpFolder'),
  195. // Where to write uploads before they are processed
  196. uploadFolder: Path.join(TMP_DIR, 'uploads'),
  197. // Where to write the project to disk before running LaTeX on it
  198. compilesDir: Path.join(DATA_DIR, 'compiles'),
  199. // Where to cache downloaded URLs for the CLSI
  200. clsiCacheDir: Path.join(DATA_DIR, 'cache'),
  201. // Where to write the output files to disk after running LaTeX
  202. outputDir: Path.join(DATA_DIR, 'output'),
  203. },
  204. // Server Config
  205. // -------------
  206. // Where your instance of ShareLaTeX can be found publicly. This is used
  207. // when emails are sent out and in generated links:
  208. siteUrl: (siteUrl = process.env.SHARELATEX_SITE_URL || 'http://localhost'),
  209. // The name this is used to describe your ShareLaTeX Installation
  210. appName: process.env.SHARELATEX_APP_NAME || 'ShareLaTeX (Community Edition)',
  211. restrictInvitesToExistingAccounts:
  212. process.env.SHARELATEX_RESTRICT_INVITES_TO_EXISTING_ACCOUNTS === 'true',
  213. nav: {
  214. title:
  215. process.env.SHARELATEX_NAV_TITLE ||
  216. process.env.SHARELATEX_APP_NAME ||
  217. 'ShareLaTeX Community Edition',
  218. },
  219. // The email address which users will be directed to as the main point of
  220. // contact for this installation of ShareLaTeX.
  221. adminEmail: process.env.SHARELATEX_ADMIN_EMAIL || 'placeholder@example.com',
  222. // If provided, a sessionSecret is used to sign cookies so that they cannot be
  223. // spoofed. This is recommended.
  224. security: {
  225. sessionSecret:
  226. process.env.SHARELATEX_SESSION_SECRET || process.env.CRYPTO_RANDOM,
  227. },
  228. // These credentials are used for authenticating api requests
  229. // between services that may need to go over public channels
  230. httpAuthUsers,
  231. // Should javascript assets be served minified or not.
  232. useMinifiedJs: true,
  233. // Should static assets be sent with a header to tell the browser to cache
  234. // them. This should be false in development where changes are being made,
  235. // but should be set to true in production.
  236. cacheStaticAssets: true,
  237. // If you are running ShareLaTeX over https, set this to true to send the
  238. // cookie with a secure flag (recommended).
  239. secureCookie: process.env.SHARELATEX_SECURE_COOKIE != null,
  240. // If you are running ShareLaTeX behind a proxy (like Apache, Nginx, etc)
  241. // then set this to true to allow it to correctly detect the forwarded IP
  242. // address and http/https protocol information.
  243. behindProxy: process.env.SHARELATEX_BEHIND_PROXY || false,
  244. i18n: {
  245. subdomainLang: {
  246. www: {
  247. lngCode: process.env.SHARELATEX_SITE_LANGUAGE || 'en',
  248. url: siteUrl,
  249. },
  250. },
  251. defaultLng: process.env.SHARELATEX_SITE_LANGUAGE || 'en',
  252. },
  253. currentImageName: process.env.TEX_LIVE_DOCKER_IMAGE,
  254. apis: {
  255. web: {
  256. url: 'http://localhost:3000',
  257. user: httpAuthUser,
  258. pass: httpAuthPass,
  259. },
  260. project_history: {
  261. enabled: false,
  262. },
  263. },
  264. references: {},
  265. notifications: undefined,
  266. defaultFeatures: {
  267. collaborators: -1,
  268. dropbox: true,
  269. versioning: true,
  270. compileTimeout: parseIntOrFail(process.env.COMPILE_TIMEOUT || 180),
  271. compileGroup: 'standard',
  272. trackChanges: true,
  273. templates: true,
  274. references: true,
  275. },
  276. }
  277. // # OPTIONAL CONFIGURABLE SETTINGS
  278. if (process.env.SHARELATEX_LEFT_FOOTER != null) {
  279. try {
  280. settings.nav.left_footer = JSON.parse(process.env.SHARELATEX_LEFT_FOOTER)
  281. } catch (error) {
  282. e = error
  283. console.error('could not parse SHARELATEX_LEFT_FOOTER, not valid JSON')
  284. }
  285. }
  286. if (process.env.SHARELATEX_RIGHT_FOOTER != null) {
  287. settings.nav.right_footer = process.env.SHARELATEX_RIGHT_FOOTER
  288. try {
  289. settings.nav.right_footer = JSON.parse(process.env.SHARELATEX_RIGHT_FOOTER)
  290. } catch (error1) {
  291. e = error1
  292. console.error('could not parse SHARELATEX_RIGHT_FOOTER, not valid JSON')
  293. }
  294. }
  295. if (process.env.SHARELATEX_HEADER_IMAGE_URL != null) {
  296. settings.nav.custom_logo = process.env.SHARELATEX_HEADER_IMAGE_URL
  297. }
  298. if (process.env.SHARELATEX_HEADER_NAV_LINKS != null) {
  299. console.error(`\
  300. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  301. #
  302. # WARNING: SHARELATEX_HEADER_NAV_LINKS is no longer supported
  303. # See https://github.com/sharelatex/sharelatex/wiki/Configuring-Headers,-Footers-&-Logo
  304. #
  305. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\
  306. `)
  307. }
  308. if (process.env.SHARELATEX_HEADER_EXTRAS != null) {
  309. try {
  310. settings.nav.header_extras = JSON.parse(
  311. process.env.SHARELATEX_HEADER_EXTRAS
  312. )
  313. } catch (error2) {
  314. e = error2
  315. console.error('could not parse SHARELATEX_HEADER_EXTRAS, not valid JSON')
  316. }
  317. }
  318. // Sending Email
  319. // -------------
  320. //
  321. // You must configure a mail server to be able to send invite emails from
  322. // ShareLaTeX. The config settings are passed to nodemailer. See the nodemailer
  323. // documentation for available options:
  324. //
  325. // http://www.nodemailer.com/docs/transports
  326. if (process.env.SHARELATEX_EMAIL_FROM_ADDRESS != null) {
  327. settings.email = {
  328. fromAddress: process.env.SHARELATEX_EMAIL_FROM_ADDRESS,
  329. replyTo: process.env.SHARELATEX_EMAIL_REPLY_TO || '',
  330. driver: process.env.SHARELATEX_EMAIL_DRIVER,
  331. parameters: {
  332. // AWS Creds
  333. AWSAccessKeyID: process.env.SHARELATEX_EMAIL_AWS_SES_ACCESS_KEY_ID,
  334. AWSSecretKey: process.env.SHARELATEX_EMAIL_AWS_SES_SECRET_KEY,
  335. // SMTP Creds
  336. host: process.env.SHARELATEX_EMAIL_SMTP_HOST,
  337. port: process.env.SHARELATEX_EMAIL_SMTP_PORT,
  338. secure: parse(process.env.SHARELATEX_EMAIL_SMTP_SECURE),
  339. ignoreTLS: parse(process.env.SHARELATEX_EMAIL_SMTP_IGNORE_TLS),
  340. name: process.env.SHARELATEX_EMAIL_SMTP_NAME,
  341. logger: process.env.SHARELATEX_EMAIL_SMTP_LOGGER === 'true',
  342. },
  343. textEncoding: process.env.SHARELATEX_EMAIL_TEXT_ENCODING,
  344. template: {
  345. customFooter: process.env.SHARELATEX_CUSTOM_EMAIL_FOOTER,
  346. },
  347. }
  348. if (process.env.SHARELATEX_EMAIL_AWS_SES_REGION != null) {
  349. settings.email.parameters.region =
  350. process.env.SHARELATEX_EMAIL_AWS_SES_REGION
  351. }
  352. if (
  353. process.env.SHARELATEX_EMAIL_SMTP_USER != null ||
  354. process.env.SHARELATEX_EMAIL_SMTP_PASS != null
  355. ) {
  356. settings.email.parameters.auth = {
  357. user: process.env.SHARELATEX_EMAIL_SMTP_USER,
  358. pass: process.env.SHARELATEX_EMAIL_SMTP_PASS,
  359. }
  360. }
  361. if (process.env.SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH != null) {
  362. settings.email.parameters.tls = {
  363. rejectUnauthorized: parse(
  364. process.env.SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH
  365. ),
  366. }
  367. }
  368. }
  369. // i18n
  370. if (process.env.SHARELATEX_LANG_DOMAIN_MAPPING != null) {
  371. settings.i18n.subdomainLang = parse(
  372. process.env.SHARELATEX_LANG_DOMAIN_MAPPING
  373. )
  374. }
  375. // Password Settings
  376. // -----------
  377. // These restrict the passwords users can use when registering
  378. // opts are from http://antelle.github.io/passfield
  379. if (
  380. process.env.SHARELATEX_PASSWORD_VALIDATION_PATTERN ||
  381. process.env.SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH ||
  382. process.env.SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH
  383. ) {
  384. settings.passwordStrengthOptions = {
  385. pattern: process.env.SHARELATEX_PASSWORD_VALIDATION_PATTERN || 'aA$3',
  386. length: {
  387. min: process.env.SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH || 8,
  388. max: process.env.SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH || 150,
  389. },
  390. }
  391. }
  392. // ######################
  393. // ShareLaTeX Server Pro
  394. // ######################
  395. if (parse(process.env.SHARELATEX_IS_SERVER_PRO) === true) {
  396. settings.bypassPercentageRollouts = true
  397. settings.apis.references = { url: 'http://localhost:3040' }
  398. }
  399. // LDAP - SERVER PRO ONLY
  400. // ----------
  401. if (process.env.SHARELATEX_LDAP_HOST) {
  402. console.error(`\
  403. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  404. #
  405. # WARNING: The LDAP configuration format has changed in version 0.5.1
  406. # See https://github.com/sharelatex/sharelatex/wiki/Server-Pro:-LDAP-Config
  407. #
  408. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #\
  409. `)
  410. }
  411. if (process.env.SHARELATEX_LDAP_URL) {
  412. let _ldap_connect_timeout,
  413. _ldap_group_search_attribs,
  414. _ldap_search_attribs,
  415. _ldap_timeout
  416. settings.externalAuth = true
  417. settings.ldap = {
  418. emailAtt: process.env.SHARELATEX_LDAP_EMAIL_ATT,
  419. nameAtt: process.env.SHARELATEX_LDAP_NAME_ATT,
  420. lastNameAtt: process.env.SHARELATEX_LDAP_LAST_NAME_ATT,
  421. updateUserDetailsOnLogin:
  422. process.env.SHARELATEX_LDAP_UPDATE_USER_DETAILS_ON_LOGIN === 'true',
  423. placeholder: process.env.SHARELATEX_LDAP_PLACEHOLDER,
  424. server: {
  425. url: process.env.SHARELATEX_LDAP_URL,
  426. bindDn: process.env.SHARELATEX_LDAP_BIND_DN,
  427. bindCredentials: process.env.SHARELATEX_LDAP_BIND_CREDENTIALS,
  428. bindProperty: process.env.SHARELATEX_LDAP_BIND_PROPERTY,
  429. searchBase: process.env.SHARELATEX_LDAP_SEARCH_BASE,
  430. searchScope: process.env.SHARELATEX_LDAP_SEARCH_SCOPE,
  431. searchFilter: process.env.SHARELATEX_LDAP_SEARCH_FILTER,
  432. searchAttributes: (_ldap_search_attribs =
  433. process.env.SHARELATEX_LDAP_SEARCH_ATTRIBUTES)
  434. ? (() => {
  435. try {
  436. return JSON.parse(_ldap_search_attribs)
  437. } catch (error3) {
  438. e = error3
  439. return console.error(
  440. 'could not parse SHARELATEX_LDAP_SEARCH_ATTRIBUTES'
  441. )
  442. }
  443. })()
  444. : undefined,
  445. groupDnProperty: process.env.SHARELATEX_LDAP_GROUP_DN_PROPERTY,
  446. groupSearchBase: process.env.SHARELATEX_LDAP_GROUP_SEARCH_BASE,
  447. groupSearchScope: process.env.SHARELATEX_LDAP_GROUP_SEARCH_SCOPE,
  448. groupSearchFilter: process.env.SHARELATEX_LDAP_GROUP_SEARCH_FILTER,
  449. groupSearchAttributes: (_ldap_group_search_attribs =
  450. process.env.SHARELATEX_LDAP_GROUP_SEARCH_ATTRIBUTES)
  451. ? (() => {
  452. try {
  453. return JSON.parse(_ldap_group_search_attribs)
  454. } catch (error4) {
  455. e = error4
  456. return console.error(
  457. 'could not parse SHARELATEX_LDAP_GROUP_SEARCH_ATTRIBUTES'
  458. )
  459. }
  460. })()
  461. : undefined,
  462. cache: process.env.SHARELATEX_LDAP_CACHE === 'true',
  463. timeout: (_ldap_timeout = process.env.SHARELATEX_LDAP_TIMEOUT)
  464. ? (() => {
  465. try {
  466. return parseIntOrFail(_ldap_timeout)
  467. } catch (error5) {
  468. e = error5
  469. return console.error('Cannot parse SHARELATEX_LDAP_TIMEOUT')
  470. }
  471. })()
  472. : undefined,
  473. connectTimeout: (_ldap_connect_timeout =
  474. process.env.SHARELATEX_LDAP_CONNECT_TIMEOUT)
  475. ? (() => {
  476. try {
  477. return parseIntOrFail(_ldap_connect_timeout)
  478. } catch (error6) {
  479. e = error6
  480. return console.error(
  481. 'Cannot parse SHARELATEX_LDAP_CONNECT_TIMEOUT'
  482. )
  483. }
  484. })()
  485. : undefined,
  486. },
  487. }
  488. if (process.env.SHARELATEX_LDAP_TLS_OPTS_CA_PATH) {
  489. let ca, ca_paths
  490. try {
  491. ca = JSON.parse(process.env.SHARELATEX_LDAP_TLS_OPTS_CA_PATH)
  492. } catch (error7) {
  493. e = error7
  494. console.error(
  495. 'could not parse SHARELATEX_LDAP_TLS_OPTS_CA_PATH, invalid JSON'
  496. )
  497. }
  498. if (typeof ca === 'string') {
  499. ca_paths = [ca]
  500. } else if (
  501. typeof ca === 'object' &&
  502. (ca != null ? ca.length : undefined) != null
  503. ) {
  504. ca_paths = ca
  505. } else {
  506. console.error('problem parsing SHARELATEX_LDAP_TLS_OPTS_CA_PATH')
  507. }
  508. settings.ldap.server.tlsOptions = {
  509. rejectUnauthorized:
  510. process.env.SHARELATEX_LDAP_TLS_OPTS_REJECT_UNAUTH === 'true',
  511. ca: ca_paths, // e.g.'/etc/ldap/ca_certs.pem'
  512. }
  513. }
  514. }
  515. if (process.env.SHARELATEX_SAML_ENTRYPOINT) {
  516. // NOTE: see https://github.com/node-saml/passport-saml/blob/master/README.md for docs of `server` options
  517. let _saml_additionalAuthorizeParams,
  518. _saml_additionalLogoutParams,
  519. _saml_additionalParams,
  520. _saml_expiration,
  521. _saml_skew
  522. settings.externalAuth = true
  523. settings.saml = {
  524. updateUserDetailsOnLogin:
  525. process.env.SHARELATEX_SAML_UPDATE_USER_DETAILS_ON_LOGIN === 'true',
  526. identityServiceName: process.env.SHARELATEX_SAML_IDENTITY_SERVICE_NAME,
  527. emailField:
  528. process.env.SHARELATEX_SAML_EMAIL_FIELD ||
  529. process.env.SHARELATEX_SAML_EMAIL_FIELD_NAME,
  530. firstNameField: process.env.SHARELATEX_SAML_FIRST_NAME_FIELD,
  531. lastNameField: process.env.SHARELATEX_SAML_LAST_NAME_FIELD,
  532. server: {
  533. // strings
  534. entryPoint: process.env.SHARELATEX_SAML_ENTRYPOINT,
  535. callbackUrl: process.env.SHARELATEX_SAML_CALLBACK_URL,
  536. issuer: process.env.SHARELATEX_SAML_ISSUER,
  537. decryptionPvk: process.env.SHARELATEX_SAML_DECRYPTION_PVK,
  538. decryptionCert: process.env.SHARELATEX_SAML_DECRYPTION_CERT,
  539. signatureAlgorithm: process.env.SHARELATEX_SAML_SIGNATURE_ALGORITHM,
  540. identifierFormat: process.env.SHARELATEX_SAML_IDENTIFIER_FORMAT,
  541. attributeConsumingServiceIndex:
  542. process.env.SHARELATEX_SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX,
  543. authnContext: process.env.SHARELATEX_SAML_AUTHN_CONTEXT,
  544. authnRequestBinding: process.env.SHARELATEX_SAML_AUTHN_REQUEST_BINDING,
  545. validateInResponseTo: process.env.SHARELATEX_SAML_VALIDATE_IN_RESPONSE_TO,
  546. cacheProvider: process.env.SHARELATEX_SAML_CACHE_PROVIDER,
  547. logoutUrl: process.env.SHARELATEX_SAML_LOGOUT_URL,
  548. logoutCallbackUrl: process.env.SHARELATEX_SAML_LOGOUT_CALLBACK_URL,
  549. disableRequestedAuthnContext:
  550. process.env.SHARELATEX_SAML_DISABLE_REQUESTED_AUTHN_CONTEXT === 'true',
  551. forceAuthn: process.env.SHARELATEX_SAML_FORCE_AUTHN === 'true',
  552. skipRequestCompression:
  553. process.env.SHARELATEX_SAML_SKIP_REQUEST_COMPRESSION === 'true',
  554. acceptedClockSkewMs: (_saml_skew =
  555. process.env.SHARELATEX_SAML_ACCEPTED_CLOCK_SKEW_MS)
  556. ? (() => {
  557. try {
  558. return parseIntOrFail(_saml_skew)
  559. } catch (error8) {
  560. e = error8
  561. return console.error(
  562. 'Cannot parse SHARELATEX_SAML_ACCEPTED_CLOCK_SKEW_MS'
  563. )
  564. }
  565. })()
  566. : undefined,
  567. requestIdExpirationPeriodMs: (_saml_expiration =
  568. process.env.SHARELATEX_SAML_REQUEST_ID_EXPIRATION_PERIOD_MS)
  569. ? (() => {
  570. try {
  571. return parseIntOrFail(_saml_expiration)
  572. } catch (error9) {
  573. e = error9
  574. return console.error(
  575. 'Cannot parse SHARELATEX_SAML_REQUEST_ID_EXPIRATION_PERIOD_MS'
  576. )
  577. }
  578. })()
  579. : undefined,
  580. additionalParams: (_saml_additionalParams =
  581. process.env.SHARELATEX_SAML_ADDITIONAL_PARAMS)
  582. ? (() => {
  583. try {
  584. return JSON.parse(_saml_additionalParams)
  585. } catch (error10) {
  586. e = error10
  587. return console.error(
  588. 'Cannot parse SHARELATEX_SAML_ADDITIONAL_PARAMS'
  589. )
  590. }
  591. })()
  592. : undefined,
  593. additionalAuthorizeParams: (_saml_additionalAuthorizeParams =
  594. process.env.SHARELATEX_SAML_ADDITIONAL_AUTHORIZE_PARAMS)
  595. ? (() => {
  596. try {
  597. return JSON.parse(_saml_additionalAuthorizeParams)
  598. } catch (error11) {
  599. e = error11
  600. return console.error(
  601. 'Cannot parse SHARELATEX_SAML_ADDITIONAL_AUTHORIZE_PARAMS'
  602. )
  603. }
  604. })()
  605. : undefined,
  606. additionalLogoutParams: (_saml_additionalLogoutParams =
  607. process.env.SHARELATEX_SAML_ADDITIONAL_LOGOUT_PARAMS)
  608. ? (() => {
  609. try {
  610. return JSON.parse(_saml_additionalLogoutParams)
  611. } catch (error12) {
  612. e = error12
  613. return console.error(
  614. 'Cannot parse SHARELATEX_SAML_ADDITIONAL_LOGOUT_PARAMS'
  615. )
  616. }
  617. })()
  618. : undefined,
  619. },
  620. }
  621. // SHARELATEX_SAML_CERT cannot be empty
  622. // https://github.com/node-saml/passport-saml/commit/f6b1c885c0717f1083c664345556b535f217c102
  623. if (process.env.SHARELATEX_SAML_CERT) {
  624. settings.saml.server.cert = process.env.SHARELATEX_SAML_CERT
  625. settings.saml.server.privateCert = process.env.SHARELATEX_SAML_PRIVATE_CERT
  626. }
  627. }
  628. // Compiler
  629. // --------
  630. if (process.env.SANDBOXED_COMPILES === 'true') {
  631. settings.clsi = {
  632. dockerRunner: true,
  633. docker: {
  634. image: process.env.TEX_LIVE_DOCKER_IMAGE,
  635. env: {
  636. HOME: '/tmp',
  637. PATH:
  638. process.env.COMPILER_PATH ||
  639. '/usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
  640. },
  641. user: 'www-data',
  642. },
  643. }
  644. if (settings.path == null) {
  645. settings.path = {}
  646. }
  647. settings.path.synctexBaseDir = () => '/compile'
  648. if (process.env.SANDBOXED_COMPILES_SIBLING_CONTAINERS === 'true') {
  649. console.log('Using sibling containers for sandboxed compiles')
  650. if (process.env.SANDBOXED_COMPILES_HOST_DIR) {
  651. settings.path.sandboxedCompilesHostDir =
  652. process.env.SANDBOXED_COMPILES_HOST_DIR
  653. } else {
  654. console.error(
  655. 'Sibling containers, but SANDBOXED_COMPILES_HOST_DIR not set'
  656. )
  657. }
  658. }
  659. }
  660. // Templates
  661. // ---------
  662. if (process.env.SHARELATEX_TEMPLATES_USER_ID) {
  663. settings.templates = {
  664. mountPointUrl: '/templates',
  665. user_id: process.env.SHARELATEX_TEMPLATES_USER_ID,
  666. }
  667. settings.templateLinks = parse(
  668. process.env.SHARELATEX_NEW_PROJECT_TEMPLATE_LINKS
  669. )
  670. }
  671. // /Learn
  672. // -------
  673. if (process.env.SHARELATEX_PROXY_LEARN != null) {
  674. settings.proxyLearn = parse(process.env.SHARELATEX_PROXY_LEARN)
  675. }
  676. // /References
  677. // -----------
  678. if (process.env.SHARELATEX_ELASTICSEARCH_URL != null) {
  679. settings.references.elasticsearch = {
  680. host: process.env.SHARELATEX_ELASTICSEARCH_URL,
  681. }
  682. }
  683. // TeX Live Images
  684. // -----------
  685. if (process.env.ALL_TEX_LIVE_DOCKER_IMAGES != null) {
  686. allTexLiveDockerImages = process.env.ALL_TEX_LIVE_DOCKER_IMAGES.split(',')
  687. }
  688. if (process.env.ALL_TEX_LIVE_DOCKER_IMAGE_NAMES != null) {
  689. allTexLiveDockerImageNames =
  690. process.env.ALL_TEX_LIVE_DOCKER_IMAGE_NAMES.split(',')
  691. }
  692. if (allTexLiveDockerImages != null) {
  693. settings.allowedImageNames = []
  694. for (let index = 0; index < allTexLiveDockerImages.length; index++) {
  695. const fullImageName = allTexLiveDockerImages[index]
  696. const imageName = Path.basename(fullImageName)
  697. const imageDesc =
  698. allTexLiveDockerImageNames != null
  699. ? allTexLiveDockerImageNames[index]
  700. : imageName
  701. settings.allowedImageNames.push({ imageName, imageDesc })
  702. }
  703. }
  704. // With lots of incoming and outgoing HTTP connections to different services,
  705. // sometimes long running, it is a good idea to increase the default number
  706. // of sockets that Node will hold open.
  707. const http = require('http')
  708. http.globalAgent.maxSockets = 300
  709. const https = require('https')
  710. https.globalAgent.maxSockets = 300
  711. module.exports = settings