settings.coffee 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. Path = require('path')
  2. # These credentials are used for authenticating api requests
  3. # between services that may need to go over public channels
  4. httpAuthUser = "sharelatex"
  5. httpAuthPass = process.env["WEB_API_PASSWORD"]
  6. httpAuthUsers = {}
  7. httpAuthUsers[httpAuthUser] = httpAuthPass
  8. parse = (option)->
  9. if option?
  10. try
  11. opt = JSON.parse(option)
  12. return opt
  13. catch err
  14. throw new Error("problem parsing #{option}, invalid JSON")
  15. parseIntOrFail = (value)->
  16. parsedValue = parseInt(value, 10)
  17. if isNaN(parsedValue)
  18. throw new Error("'#{value}' is an invalid integer")
  19. return parsedValue
  20. DATA_DIR = '/var/lib/sharelatex/data'
  21. TMP_DIR = '/var/lib/sharelatex/tmp'
  22. settings =
  23. clsi:
  24. optimiseInDocker: process.env['OPTIMISE_PDF'] == 'true'
  25. brandPrefix: ""
  26. allowAnonymousReadAndWriteSharing:
  27. process.env['SHARELATEX_ALLOW_ANONYMOUS_READ_AND_WRITE_SHARING'] == 'true'
  28. # Databases
  29. # ---------
  30. # ShareLaTeX's main persistent data store is MongoDB (http://www.mongodb.org/)
  31. # Documentation about the URL connection string format can be found at:
  32. #
  33. # http://docs.mongodb.org/manual/reference/connection-string/
  34. #
  35. # The following works out of the box with Mongo's default settings:
  36. mongo:
  37. url : process.env["SHARELATEX_MONGO_URL"] or 'mongodb://dockerhost/sharelatex'
  38. # Redis is used in ShareLaTeX for high volume queries, like real-time
  39. # editing, and session management.
  40. #
  41. # The following config will work with Redis's default settings:
  42. redis:
  43. web: redisConfig =
  44. host: process.env["SHARELATEX_REDIS_HOST"] or "dockerhost"
  45. port: process.env["SHARELATEX_REDIS_PORT"] or "6379"
  46. password: process.env["SHARELATEX_REDIS_PASS"] or undefined
  47. key_schema:
  48. # document-updater
  49. blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
  50. docLines: ({doc_id}) -> "doclines:#{doc_id}"
  51. docOps: ({doc_id}) -> "DocOps:#{doc_id}"
  52. docVersion: ({doc_id}) -> "DocVersion:#{doc_id}"
  53. docHash: ({doc_id}) -> "DocHash:#{doc_id}"
  54. projectKey: ({doc_id}) -> "ProjectId:#{doc_id}"
  55. docsInProject: ({project_id}) -> "DocsIn:#{project_id}"
  56. ranges: ({doc_id}) -> "Ranges:#{doc_id}"
  57. # document-updater:realtime
  58. pendingUpdates: ({doc_id}) -> "PendingUpdates:#{doc_id}"
  59. # document-updater:history
  60. uncompressedHistoryOps: ({doc_id}) -> "UncompressedHistoryOps:#{doc_id}"
  61. docsWithHistoryOps: ({project_id}) -> "DocsWithHistoryOps:#{project_id}"
  62. # document-updater:lock
  63. blockingKey: ({doc_id}) -> "Blocking:#{doc_id}"
  64. # track-changes:lock
  65. historyLock: ({doc_id}) -> "HistoryLock:#{doc_id}"
  66. historyIndexLock: ({project_id}) -> "HistoryIndexLock:#{project_id}"
  67. # track-changes:history
  68. uncompressedHistoryOps: ({doc_id}) -> "UncompressedHistoryOps:#{doc_id}"
  69. docsWithHistoryOps: ({project_id}) -> "DocsWithHistoryOps:#{project_id}"
  70. # realtime
  71. clientsInProject: ({project_id}) -> "clients_in_project:#{project_id}"
  72. connectedUser: ({project_id, client_id})-> "connected_user:#{project_id}:#{client_id}"
  73. fairy: redisConfig
  74. # track-changes and document-updater
  75. realtime: redisConfig
  76. documentupdater: redisConfig
  77. lock: redisConfig
  78. history: redisConfig
  79. websessions: redisConfig
  80. api: redisConfig
  81. pubsub: redisConfig
  82. project_history: redisConfig
  83. # The compile server (the clsi) uses a SQL database to cache files and
  84. # meta-data. sqlite is the default, and the load is low enough that this will
  85. # be fine in production (we use sqlite at sharelatex.com).
  86. #
  87. # If you want to configure a different database, see the Sequelize documentation
  88. # for available options:
  89. #
  90. # https://github.com/sequelize/sequelize/wiki/API-Reference-Sequelize#example-usage
  91. #
  92. mysql:
  93. clsi:
  94. database: "clsi"
  95. username: "clsi"
  96. password: ""
  97. dialect: "sqlite"
  98. storage: Path.join(DATA_DIR, "db.sqlite")
  99. # File storage
  100. # ------------
  101. # ShareLaTeX can store binary files like images either locally or in Amazon
  102. # S3. The default is locally:
  103. filestore:
  104. backend: "fs"
  105. stores:
  106. user_files: Path.join(DATA_DIR, "user_files")
  107. template_files: Path.join(DATA_DIR, "template_files")
  108. # To use Amazon S3 as a storage backend, comment out the above config, and
  109. # uncomment the following, filling in your key, secret, and bucket name:
  110. #
  111. # filestore:
  112. # backend: "s3"
  113. # stores:
  114. # user_files: "BUCKET_NAME"
  115. # s3:
  116. # key: "AWS_KEY"
  117. # secret: "AWS_SECRET"
  118. #
  119. trackchanges:
  120. continueOnError: true
  121. # Local disk caching
  122. # ------------------
  123. path:
  124. # If we ever need to write something to disk (e.g. incoming requests
  125. # that need processing but may be too big for memory), then write
  126. # them to disk here:
  127. dumpFolder: Path.join(TMP_DIR, "dumpFolder")
  128. # Where to write uploads before they are processed
  129. uploadFolder: Path.join(TMP_DIR, "uploads")
  130. # Where to write the project to disk before running LaTeX on it
  131. compilesDir: Path.join(DATA_DIR, "compiles")
  132. # Where to cache downloaded URLs for the CLSI
  133. clsiCacheDir: Path.join(DATA_DIR, "cache")
  134. # Where to write the output files to disk after running LaTeX
  135. outputDir: Path.join(DATA_DIR, "output")
  136. # Server Config
  137. # -------------
  138. # Where your instance of ShareLaTeX can be found publicly. This is used
  139. # when emails are sent out and in generated links:
  140. siteUrl: siteUrl = process.env["SHARELATEX_SITE_URL"] or 'http://localhost'
  141. # The name this is used to describe your ShareLaTeX Installation
  142. appName: process.env["SHARELATEX_APP_NAME"] or "ShareLaTeX (Community Edition)"
  143. restrictInvitesToExistingAccounts: process.env["SHARELATEX_RESTRICT_INVITES_TO_EXISTING_ACCOUNTS"] == 'true'
  144. nav:
  145. title: process.env["SHARELATEX_NAV_TITLE"] or process.env["SHARELATEX_APP_NAME"] or "ShareLaTeX Community Edition"
  146. # The email address which users will be directed to as the main point of
  147. # contact for this installation of ShareLaTeX.
  148. adminEmail: process.env["SHARELATEX_ADMIN_EMAIL"] or "placeholder@example.com"
  149. # If provided, a sessionSecret is used to sign cookies so that they cannot be
  150. # spoofed. This is recommended.
  151. security:
  152. sessionSecret: process.env["SHARELATEX_SESSION_SECRET"] or process.env["CRYPTO_RANDOM"]
  153. # These credentials are used for authenticating api requests
  154. # between services that may need to go over public channels
  155. httpAuthUsers: httpAuthUsers
  156. # Should javascript assets be served minified or not.
  157. useMinifiedJs: true
  158. # Should static assets be sent with a header to tell the browser to cache
  159. # them. This should be false in development where changes are being made,
  160. # but should be set to true in production.
  161. cacheStaticAssets: true
  162. # If you are running ShareLaTeX over https, set this to true to send the
  163. # cookie with a secure flag (recommended).
  164. secureCookie: process.env["SHARELATEX_SECURE_COOKIE"]?
  165. # If you are running ShareLaTeX behind a proxy (like Apache, Nginx, etc)
  166. # then set this to true to allow it to correctly detect the forwarded IP
  167. # address and http/https protocol information.
  168. behindProxy: process.env["SHARELATEX_BEHIND_PROXY"] or false
  169. i18n:
  170. subdomainLang:
  171. www: {lngCode:process.env["SHARELATEX_SITE_LANGUAGE"] or "en", url: siteUrl}
  172. defaultLng: process.env["SHARELATEX_SITE_LANGUAGE"] or "en"
  173. currentImageName: process.env["TEX_LIVE_DOCKER_IMAGE"]
  174. apis:
  175. web:
  176. url: "http://localhost:3000"
  177. user: httpAuthUser
  178. pass: httpAuthPass
  179. project_history:
  180. enabled: false
  181. references:{}
  182. notifications:undefined
  183. defaultFeatures:
  184. collaborators: -1
  185. dropbox: true
  186. versioning: true
  187. compileTimeout: parseIntOrFail(process.env["COMPILE_TIMEOUT"] or 180)
  188. compileGroup: "standard"
  189. trackChanges: true
  190. templates: true
  191. references: true
  192. ## OPTIONAL CONFIGURABLE SETTINGS
  193. if process.env["SHARELATEX_LEFT_FOOTER"]?
  194. try
  195. settings.nav.left_footer = JSON.parse(process.env["SHARELATEX_LEFT_FOOTER"])
  196. catch e
  197. console.error("could not parse SHARELATEX_LEFT_FOOTER, not valid JSON")
  198. if process.env["SHARELATEX_RIGHT_FOOTER"]?
  199. settings.nav.right_footer = process.env["SHARELATEX_RIGHT_FOOTER"]
  200. try
  201. settings.nav.right_footer = JSON.parse(process.env["SHARELATEX_RIGHT_FOOTER"])
  202. catch e
  203. console.error("could not parse SHARELATEX_RIGHT_FOOTER, not valid JSON")
  204. if process.env["SHARELATEX_HEADER_IMAGE_URL"]?
  205. settings.nav.custom_logo = process.env["SHARELATEX_HEADER_IMAGE_URL"]
  206. if process.env["SHARELATEX_HEADER_NAV_LINKS"]?
  207. console.error """
  208. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  209. #
  210. # WARNING: SHARELATEX_HEADER_NAV_LINKS is no longer supported
  211. # See https://github.com/sharelatex/sharelatex/wiki/Configuring-Headers,-Footers-&-Logo
  212. #
  213. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  214. """
  215. if process.env["SHARELATEX_HEADER_EXTRAS"]?
  216. try
  217. settings.nav.header_extras = JSON.parse(process.env["SHARELATEX_HEADER_EXTRAS"])
  218. catch e
  219. console.error("could not parse SHARELATEX_HEADER_EXTRAS, not valid JSON")
  220. # Sending Email
  221. # -------------
  222. #
  223. # You must configure a mail server to be able to send invite emails from
  224. # ShareLaTeX. The config settings are passed to nodemailer. See the nodemailer
  225. # documentation for available options:
  226. #
  227. # http://www.nodemailer.com/docs/transports
  228. if process.env["SHARELATEX_EMAIL_FROM_ADDRESS"]?
  229. settings.email =
  230. fromAddress: process.env["SHARELATEX_EMAIL_FROM_ADDRESS"]
  231. replyTo: process.env["SHARELATEX_EMAIL_REPLY_TO"] or ""
  232. driver: process.env["SHARELATEX_EMAIL_DRIVER"]
  233. parameters:
  234. #AWS Creds
  235. AWSAccessKeyID: process.env["SHARELATEX_EMAIL_AWS_SES_ACCESS_KEY_ID"]
  236. AWSSecretKey: process.env["SHARELATEX_EMAIL_AWS_SES_SECRET_KEY"]
  237. #SMTP Creds
  238. host: process.env["SHARELATEX_EMAIL_SMTP_HOST"]
  239. port: process.env["SHARELATEX_EMAIL_SMTP_PORT"],
  240. secure: parse(process.env["SHARELATEX_EMAIL_SMTP_SECURE"])
  241. ignoreTLS: parse(process.env["SHARELATEX_EMAIL_SMTP_IGNORE_TLS"])
  242. name: process.env["SHARELATEX_EMAIL_SMTP_NAME"]
  243. logger: process.env["SHARELATEX_EMAIL_SMTP_LOGGER"] == 'true'
  244. textEncoding: process.env["SHARELATEX_EMAIL_TEXT_ENCODING"]
  245. template:
  246. customFooter: process.env["SHARELATEX_CUSTOM_EMAIL_FOOTER"]
  247. if process.env["SHARELATEX_EMAIL_AWS_SES_REGION"]?
  248. settings.email.parameters.region = process.env["SHARELATEX_EMAIL_AWS_SES_REGION"]
  249. if process.env["SHARELATEX_EMAIL_SMTP_USER"]? or process.env["SHARELATEX_EMAIL_SMTP_PASS"]?
  250. settings.email.parameters.auth =
  251. user: process.env["SHARELATEX_EMAIL_SMTP_USER"]
  252. pass: process.env["SHARELATEX_EMAIL_SMTP_PASS"]
  253. if process.env["SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH"]?
  254. settings.email.parameters.tls =
  255. rejectUnauthorized: parse(process.env["SHARELATEX_EMAIL_SMTP_TLS_REJECT_UNAUTH"])
  256. # i18n
  257. if process.env["SHARELATEX_LANG_DOMAIN_MAPPING"]?
  258. settings.i18n.subdomainLang = parse(process.env["SHARELATEX_LANG_DOMAIN_MAPPING"])
  259. # Password Settings
  260. # -----------
  261. # These restrict the passwords users can use when registering
  262. # opts are from http://antelle.github.io/passfield
  263. if process.env["SHARELATEX_PASSWORD_VALIDATION_PATTERN"] or process.env["SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH"] or process.env["SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH"]
  264. settings.passwordStrengthOptions =
  265. pattern: process.env["SHARELATEX_PASSWORD_VALIDATION_PATTERN"] or "aA$3"
  266. length: {min:process.env["SHARELATEX_PASSWORD_VALIDATION_MIN_LENGTH"] or 8, max: process.env["SHARELATEX_PASSWORD_VALIDATION_MAX_LENGTH"] or 150}
  267. #######################
  268. # ShareLaTeX Server Pro
  269. #######################
  270. if parse(process.env["SHARELATEX_IS_SERVER_PRO"]) == true
  271. settings.bypassPercentageRollouts = true
  272. settings.apis.references =
  273. url: "http://localhost:3040"
  274. # LDAP - SERVER PRO ONLY
  275. # ----------
  276. if process.env["SHARELATEX_LDAP_HOST"]
  277. console.error """
  278. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  279. #
  280. # WARNING: The LDAP configuration format has changed in version 0.5.1
  281. # See https://github.com/sharelatex/sharelatex/wiki/Server-Pro:-LDAP-Config
  282. #
  283. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  284. """
  285. if process.env["SHARELATEX_LDAP_URL"]
  286. settings.externalAuth = true
  287. settings.ldap =
  288. emailAtt: process.env["SHARELATEX_LDAP_EMAIL_ATT"]
  289. nameAtt: process.env["SHARELATEX_LDAP_NAME_ATT"]
  290. lastNameAtt: process.env["SHARELATEX_LDAP_LAST_NAME_ATT"]
  291. updateUserDetailsOnLogin: process.env["SHARELATEX_LDAP_UPDATE_USER_DETAILS_ON_LOGIN"] == 'true'
  292. placeholder: process.env["SHARELATEX_LDAP_PLACEHOLDER"]
  293. server:
  294. url: process.env["SHARELATEX_LDAP_URL"]
  295. bindDn: process.env["SHARELATEX_LDAP_BIND_DN"]
  296. bindCredentials: process.env["SHARELATEX_LDAP_BIND_CREDENTIALS"]
  297. bindProperty: process.env["SHARELATEX_LDAP_BIND_PROPERTY"]
  298. searchBase: process.env["SHARELATEX_LDAP_SEARCH_BASE"]
  299. searchScope: process.env["SHARELATEX_LDAP_SEARCH_SCOPE"]
  300. searchFilter: process.env["SHARELATEX_LDAP_SEARCH_FILTER"]
  301. searchAttributes: (
  302. if _ldap_search_attribs = process.env["SHARELATEX_LDAP_SEARCH_ATTRIBUTES"]
  303. try
  304. JSON.parse(_ldap_search_attribs)
  305. catch e
  306. console.error "could not parse SHARELATEX_LDAP_SEARCH_ATTRIBUTES"
  307. else
  308. undefined
  309. )
  310. groupDnProperty: process.env["SHARELATEX_LDAP_GROUP_DN_PROPERTY"]
  311. groupSearchBase: process.env["SHARELATEX_LDAP_GROUP_SEARCH_BASE"]
  312. groupSearchScope: process.env["SHARELATEX_LDAP_GROUP_SEARCH_SCOPE"]
  313. groupSearchFilter: process.env["SHARELATEX_LDAP_GROUP_SEARCH_FILTER"]
  314. groupSearchAttributes: (
  315. if _ldap_group_search_attribs = process.env["SHARELATEX_LDAP_GROUP_SEARCH_ATTRIBUTES"]
  316. try
  317. JSON.parse(_ldap_group_search_attribs)
  318. catch e
  319. console.error "could not parse SHARELATEX_LDAP_GROUP_SEARCH_ATTRIBUTES"
  320. else
  321. undefined
  322. )
  323. cache: process.env["SHARELATEX_LDAP_CACHE"] == 'true'
  324. timeout: (
  325. if _ldap_timeout = process.env["SHARELATEX_LDAP_TIMEOUT"]
  326. try
  327. parseIntOrFail(_ldap_timeout)
  328. catch e
  329. console.error "Cannot parse SHARELATEX_LDAP_TIMEOUT"
  330. else
  331. undefined
  332. )
  333. connectTimeout: (
  334. if _ldap_connect_timeout = process.env["SHARELATEX_LDAP_CONNECT_TIMEOUT"]
  335. try
  336. parseIntOrFail(_ldap_connect_timeout)
  337. catch e
  338. console.error "Cannot parse SHARELATEX_LDAP_CONNECT_TIMEOUT"
  339. else
  340. undefined
  341. )
  342. if process.env["SHARELATEX_LDAP_TLS_OPTS_CA_PATH"]
  343. try
  344. ca = JSON.parse(process.env["SHARELATEX_LDAP_TLS_OPTS_CA_PATH"])
  345. catch e
  346. console.error "could not parse SHARELATEX_LDAP_TLS_OPTS_CA_PATH, invalid JSON"
  347. if typeof(ca) == 'string'
  348. ca_paths = [ca]
  349. else if typeof(ca) == 'object' && ca?.length?
  350. ca_paths = ca
  351. else
  352. console.error "problem parsing SHARELATEX_LDAP_TLS_OPTS_CA_PATH"
  353. settings.ldap.server.tlsOptions =
  354. rejectUnauthorized: process.env["SHARELATEX_LDAP_TLS_OPTS_REJECT_UNAUTH"] == "true"
  355. ca:ca_paths # e.g.'/etc/ldap/ca_certs.pem'
  356. if process.env["SHARELATEX_SAML_ENTRYPOINT"]
  357. # NOTE: see https://github.com/node-saml/passport-saml/blob/master/README.md for docs of `server` options
  358. settings.externalAuth = true
  359. settings.saml =
  360. updateUserDetailsOnLogin: process.env["SHARELATEX_SAML_UPDATE_USER_DETAILS_ON_LOGIN"] == 'true'
  361. identityServiceName: process.env["SHARELATEX_SAML_IDENTITY_SERVICE_NAME"]
  362. emailField: process.env["SHARELATEX_SAML_EMAIL_FIELD"] || process.env["SHARELATEX_SAML_EMAIL_FIELD_NAME"]
  363. firstNameField: process.env["SHARELATEX_SAML_FIRST_NAME_FIELD"]
  364. lastNameField: process.env["SHARELATEX_SAML_LAST_NAME_FIELD"]
  365. server:
  366. # strings
  367. entryPoint: process.env["SHARELATEX_SAML_ENTRYPOINT"]
  368. callbackUrl: process.env["SHARELATEX_SAML_CALLBACK_URL"]
  369. issuer: process.env["SHARELATEX_SAML_ISSUER"]
  370. decryptionPvk: process.env["SHARELATEX_SAML_DECRYPTION_PVK"]
  371. decryptionCert: process.env["SHARELATEX_SAML_DECRYPTION_CERT"]
  372. signatureAlgorithm: process.env["SHARELATEX_SAML_SIGNATURE_ALGORITHM"]
  373. identifierFormat: process.env["SHARELATEX_SAML_IDENTIFIER_FORMAT"]
  374. attributeConsumingServiceIndex: process.env["SHARELATEX_SAML_ATTRIBUTE_CONSUMING_SERVICE_INDEX"]
  375. authnContext: process.env["SHARELATEX_SAML_AUTHN_CONTEXT"]
  376. authnRequestBinding: process.env["SHARELATEX_SAML_AUTHN_REQUEST_BINDING"]
  377. validateInResponseTo: process.env["SHARELATEX_SAML_VALIDATE_IN_RESPONSE_TO"]
  378. cacheProvider: process.env["SHARELATEX_SAML_CACHE_PROVIDER"]
  379. logoutUrl: process.env["SHARELATEX_SAML_LOGOUT_URL"]
  380. logoutCallbackUrl: process.env["SHARELATEX_SAML_LOGOUT_CALLBACK_URL"]
  381. disableRequestedAuthnContext: process.env["SHARELATEX_SAML_DISABLE_REQUESTED_AUTHN_CONTEXT"] == 'true'
  382. forceAuthn: process.env["SHARELATEX_SAML_FORCE_AUTHN"] == 'true'
  383. skipRequestCompression: process.env["SHARELATEX_SAML_SKIP_REQUEST_COMPRESSION"] == 'true'
  384. acceptedClockSkewMs: (
  385. if _saml_skew = process.env["SHARELATEX_SAML_ACCEPTED_CLOCK_SKEW_MS"]
  386. try
  387. parseIntOrFail(_saml_skew)
  388. catch e
  389. console.error "Cannot parse SHARELATEX_SAML_ACCEPTED_CLOCK_SKEW_MS"
  390. else
  391. undefined
  392. )
  393. requestIdExpirationPeriodMs: (
  394. if _saml_expiration = process.env["SHARELATEX_SAML_REQUEST_ID_EXPIRATION_PERIOD_MS"]
  395. try
  396. parseIntOrFail(_saml_expiration)
  397. catch e
  398. console.error "Cannot parse SHARELATEX_SAML_REQUEST_ID_EXPIRATION_PERIOD_MS"
  399. else
  400. undefined
  401. )
  402. additionalParams: (
  403. if _saml_additionalParams = process.env["SHARELATEX_SAML_ADDITIONAL_PARAMS"]
  404. try
  405. JSON.parse(_saml_additionalParams)
  406. catch e
  407. console.error "Cannot parse SHARELATEX_SAML_ADDITIONAL_PARAMS"
  408. else
  409. undefined
  410. )
  411. additionalAuthorizeParams: (
  412. if _saml_additionalAuthorizeParams = process.env["SHARELATEX_SAML_ADDITIONAL_AUTHORIZE_PARAMS"]
  413. try
  414. JSON.parse(_saml_additionalAuthorizeParams )
  415. catch e
  416. console.error "Cannot parse SHARELATEX_SAML_ADDITIONAL_AUTHORIZE_PARAMS"
  417. else
  418. undefined
  419. )
  420. additionalLogoutParams: (
  421. if _saml_additionalLogoutParams = process.env["SHARELATEX_SAML_ADDITIONAL_LOGOUT_PARAMS"]
  422. try
  423. JSON.parse(_saml_additionalLogoutParams )
  424. catch e
  425. console.error "Cannot parse SHARELATEX_SAML_ADDITIONAL_LOGOUT_PARAMS"
  426. else
  427. undefined
  428. )
  429. # SHARELATEX_SAML_CERT cannot be empty
  430. # https://github.com/node-saml/passport-saml/commit/f6b1c885c0717f1083c664345556b535f217c102
  431. if process.env["SHARELATEX_SAML_CERT"]
  432. settings.saml.server.cert = process.env["SHARELATEX_SAML_CERT"]
  433. settings.saml.server.privateCert = process.env["SHARELATEX_SAML_PRIVATE_CERT"]
  434. # Compiler
  435. # --------
  436. if process.env["SANDBOXED_COMPILES"] == "true"
  437. settings.clsi =
  438. dockerRunner: true
  439. docker:
  440. image: process.env["TEX_LIVE_DOCKER_IMAGE"]
  441. env:
  442. HOME: "/tmp"
  443. PATH: process.env["COMPILER_PATH"] or "/usr/local/texlive/2015/bin/x86_64-linux:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
  444. user: "www-data"
  445. if !settings.path?
  446. settings.path = {}
  447. settings.path.synctexBaseDir = () -> "/compile"
  448. if process.env['SANDBOXED_COMPILES_SIBLING_CONTAINERS'] == 'true'
  449. console.log("Using sibling containers for sandboxed compiles")
  450. if process.env['SANDBOXED_COMPILES_HOST_DIR']
  451. settings.path.sandboxedCompilesHostDir = process.env['SANDBOXED_COMPILES_HOST_DIR']
  452. else
  453. console.error('Sibling containers, but SANDBOXED_COMPILES_HOST_DIR not set')
  454. # Templates
  455. # ---------
  456. if process.env["SHARELATEX_TEMPLATES_USER_ID"]
  457. settings.templates =
  458. mountPointUrl: "/templates"
  459. user_id: process.env["SHARELATEX_TEMPLATES_USER_ID"]
  460. settings.templateLinks = parse(process.env["SHARELATEX_NEW_PROJECT_TEMPLATE_LINKS"])
  461. # /Learn
  462. # -------
  463. if process.env["SHARELATEX_PROXY_LEARN"]?
  464. settings.proxyLearn = parse(process.env["SHARELATEX_PROXY_LEARN"])
  465. # /References
  466. # -----------
  467. if process.env["SHARELATEX_ELASTICSEARCH_URL"]?
  468. settings.references.elasticsearch =
  469. host: process.env["SHARELATEX_ELASTICSEARCH_URL"]
  470. # TeX Live Images
  471. # -----------
  472. if process.env["ALL_TEX_LIVE_DOCKER_IMAGES"]?
  473. allTexLiveDockerImages = process.env["ALL_TEX_LIVE_DOCKER_IMAGES"].split(',')
  474. if process.env["ALL_TEX_LIVE_DOCKER_IMAGE_NAMES"]?
  475. allTexLiveDockerImageNames = process.env["ALL_TEX_LIVE_DOCKER_IMAGE_NAMES"].split(',')
  476. if allTexLiveDockerImages?
  477. settings.allowedImageNames = []
  478. for fullImageName, index in allTexLiveDockerImages
  479. imageName = Path.basename(fullImageName)
  480. imageDesc = if allTexLiveDockerImageNames? then allTexLiveDockerImageNames[index] else imageName
  481. settings.allowedImageNames.push({ imageName, imageDesc })
  482. # With lots of incoming and outgoing HTTP connections to different services,
  483. # sometimes long running, it is a good idea to increase the default number
  484. # of sockets that Node will hold open.
  485. http = require('http')
  486. http.globalAgent.maxSockets = 300
  487. https = require('https')
  488. https.globalAgent.maxSockets = 300
  489. module.exports = settings