main.me 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. main.me -- Main MakeMe file for GoAhead
  3. This file contains the rules for targets to build and default settings for configuration.
  4. The MakeMe utility (https://embedthis.com/me) may be used to build GoAhead instead of make.
  5. MakeMe provides for configured builds and generates projects files.
  6. Alternatively, build using the 'make' utility in which case this file is not used.
  7. */
  8. Me.load({
  9. makeme: '>=0.9.0',
  10. plugins: [ 'installs' ],
  11. blend: [
  12. 'src/*/*.me',
  13. 'test/test.me',
  14. 'paks/ssl/*.me',
  15. 'doc/doc.me',
  16. ],
  17. configure: {
  18. requires: [ 'osdep' ],
  19. discovers: [ 'ssl' ],
  20. },
  21. settings: {
  22. integrate: true,
  23. /*
  24. Installation prefix set
  25. */
  26. prefixes: 'install-prefixes',
  27. manifest: 'installs/manifest.me',
  28. certs: {
  29. gendh: true
  30. },
  31. compiler: {
  32. fortify: true
  33. },
  34. /*
  35. Set to true for a static link, or use 'configure --static'
  36. static: false,
  37. */
  38. goahead: {
  39. /*
  40. Log for request access logging
  41. */
  42. accessLog: false,
  43. /*
  44. User authentication
  45. */
  46. auth: true,
  47. /*
  48. Select the password store mechanism. Set to: pam, file, custom
  49. If using PAM, must also set authPam to true
  50. */
  51. authStore: 'file',
  52. /*
  53. Automatically login. Useful for debugging.
  54. */
  55. autoLogin: false,
  56. clientCache: [ 'css', 'gif', 'ico', 'jpg', 'js', 'png', ],
  57. clientCacheLifespan: 86400,
  58. /*
  59. Build with CGI support and directory for CGI programs.
  60. */
  61. cgi: true,
  62. /*
  63. Prefix for CGI environment variables
  64. */
  65. cgiVarPrefix: "CGI_"
  66. /*
  67. Build with support for digest authentication
  68. */
  69. digest: true,
  70. /*
  71. Directory containing web documents to serve
  72. */
  73. documents: 'web',
  74. /*
  75. Build with support for javascript web templates
  76. */
  77. javascript: true,
  78. /*
  79. Define legacy APIs for compatibility with old GoAhead web server applications
  80. */
  81. legacy: false,
  82. /*
  83. Sandbox limits and allocation sizes
  84. */
  85. limitBuffer: 1024, /* I/O Buffer size. Also chunk size. */
  86. limitFiles: 0, /* Maximum files/sockets. Set to zero for unlimited. Unix only */
  87. limitFilename: 256, /* Maximum filename size */
  88. limitHeader: 2048, /* Maximum HTTP single header size */
  89. limitHeaders: 4096, /* Maximum HTTP header size */
  90. limitNumHeaders: 64, /* Maximum number of headers */
  91. limitParseTimeout: 5, /* Maximum time to parse the request headers */
  92. limitPassword: 32, /* Maximum password size */
  93. limitPost: 16384, /* Maximum POST incoming body size */
  94. limitPut: 204800000, /* Maximum PUT body size ~ 200MB */
  95. limitSessionLife: 1800, /* Session lifespan in seconds (30 mins) */
  96. limitSessionCount: 512, /* Maximum number of sessions to support */
  97. limitString: 256, /* Default string size */
  98. limitTimeout: 60, /* Request inactivity timeout in seconds */
  99. limitUri: 2048, /* Maximum URI size */
  100. limitUpload: 204800000, /* Maximum upload size ~ 200MB */
  101. /*
  102. Addresses to listen on. This specifies the protocol, interface and port.
  103. */
  104. listen: ['http://*:80', 'https://*:443']
  105. /*
  106. Enable application logging and tracing
  107. */
  108. logging: true,
  109. logfile: 'stderr:0',
  110. tracing: true,
  111. /*
  112. Temporary directory to hold PUT files
  113. This must be on the same filesystem as the web documents directory.
  114. */
  115. putDir: '.',
  116. /*
  117. Authentication realm. Replace with your realm.
  118. */
  119. realm: 'example.com',
  120. /*
  121. Replace malloc with a non-fragmenting allocator
  122. */
  123. replaceMalloc: false,
  124. /*
  125. Enable stealth options. Disable OPTIONS and TRACE methods.
  126. */
  127. stealth: true,
  128. ssl: {
  129. authority: '', /* Root certificates for verifying client certificates */
  130. cache: 512, /* Set the session cache size (items) */
  131. certificate: 'self.crt', /* Server certificate file. A valid certificate must be obtained */
  132. ciphers: '', /* Override cipher suite for SSL. */
  133. key: 'self.key', /* Server SSL key. This is by default set to a test key. This must be regenerated */
  134. logLevel: 5 /* Starting logging level for SSL messages */
  135. handshakes: 1, /* Set maximum number of renegotiations (zero means infinite) */
  136. revoke: '', /* List of revoked client certificates */
  137. ticket: true, /* Enable session resumption via ticketing - client side session caching */
  138. timeout: 86400, /* Session and ticketing duration in seconds */
  139. verifyIssuer: false, /* Verify issuer of client certificate */
  140. verifyPeer: false, /* Verify client certificates */
  141. },
  142. /*
  143. Upload file support
  144. */
  145. upload: true,
  146. uploadDir: 'tmp',
  147. /*
  148. Enable X-Frame-Origin to prevent clickjacking. Set to empty to disable.
  149. Set to: DENY, SAMEORIGIN, ALLOW uri
  150. */
  151. xframeHeader: 'SAMEORIGIN',
  152. },
  153. mbedtls: {
  154. compact: true, /* Compact edition - Disable non-essential ciphers and features */
  155. },
  156. /*
  157. Build without a file system (from ROM)
  158. */
  159. rom: false,
  160. },
  161. usage: {
  162. 'goahead.accessLog': 'Enable request access log (true|false)',
  163. 'goahead.caFile': 'File of client certificates (path)',
  164. 'goahead.certificate': 'Server certificate for SSL (path)',
  165. 'goahead.ciphers': 'SSL cipher suite (string)',
  166. 'goahead.cgi': 'Enable the CGI handler (true|false)',
  167. 'goahead.cgiBin': 'Directory CGI programs (path)',
  168. 'goahead.clientCache': 'Extensions to cache in the client (Array)',
  169. 'goahead.clientCacheLifespan':'Lifespan in seconds to cache in the client',
  170. 'goahead.javascript': 'Enable the Javascript JST handler (true|false)',
  171. 'goahead.key': 'Server private key for SSL (path)',
  172. 'goahead.legacy': 'Enable the GoAhead 2.X legacy APIs (true|false)',
  173. 'goahead.limitBuffer': 'I/O Buffer size. Also chunk size.',
  174. 'goahead.limitFilename': 'Maximum filename size',
  175. 'goahead.limitHeader': 'Maximum HTTP single header size',
  176. 'goahead.limitHeaders': 'Maximum HTTP header size',
  177. 'goahead.limitNumHeaders': 'Maximum number of headers',
  178. 'goahead.limitPassword': 'Maximum password size',
  179. 'goahead.limitPost': 'Maximum POST (and other method) incoming body size',
  180. 'goahead.limitPut': 'Maximum PUT body size ~ 200MB',
  181. 'goahead.limitSessionLife': 'Session lifespan in seconds (30 mins)',
  182. 'goahead.limitSessionCount': 'Maximum number of sessions to support',
  183. 'goahead.limitString': 'Default string allocation size',
  184. 'goahead.limitTimeout': 'Request inactivity timeout in seconds',
  185. 'goahead.limitUri': 'Maximum URI size',
  186. 'goahead.limitUpload': 'Maximum upload size ~ 200MB',
  187. 'goahead.listen': 'Addresses to listen to (["http://IP:port", ...])',
  188. 'goahead.logfile': 'Default location and level for debug log (path:level)',
  189. 'goahead.logging': 'Enable application logging (true|false)',
  190. 'goahead.pam': 'Enable Unix Pluggable Auth Module (true|false)',
  191. 'goahead.putDir': 'Define the directory for file uploaded via HTTP PUT (path)',
  192. 'goahead.realm': 'Authentication realm (string)',
  193. 'goahead.revoke': 'List of revoked client certificates',
  194. 'goahead.replaceMalloc': 'Replace malloc with non-fragmenting allocator (true|false)',
  195. 'goahead.ssl.cache': 'Set the session cache size (items)',
  196. 'goahead.ssl.logLevel': 'Starting logging level for SSL messages',
  197. 'goahead.ssl.renegotiate': 'Enable/Disable SSL renegotiation (defaults to true)',
  198. 'goahead.ssl.ticket': 'Enable session resumption via ticketing - client side session caching',
  199. 'goahead.ssl.timeout': 'Session and ticketing duration in seconds',
  200. 'goahead.stealth': 'Run in stealth mode. Disable OPTIONS, TRACE (true|false)',
  201. 'goahead.tune': 'Optimize (size|speed|balanced)',
  202. 'goahead.upload': 'Enable file upload (true|false)',
  203. 'goahead.uploadDir': 'Define directory for uploaded files (path)',
  204. 'rom': 'Build without a file system (true|false)',
  205. },
  206. customize: [
  207. /*
  208. The optional custom.me file is loaded after main.me is fully processed. It can
  209. thus override any setting. Feel free to create and customize.
  210. */
  211. 'custom.me',
  212. ],
  213. scripts: {
  214. postconfig: `
  215. if (me.settings.goahead.authStore != 'pam') {
  216. me.settings.compiler.hasPam = false
  217. }
  218. `,
  219. },
  220. targets: {
  221. libgo: {
  222. type: 'lib',
  223. sources: [ 'src/*.c' ],
  224. headers: [ 'src/*.h' ],
  225. exclude: /goahead\.c/,
  226. depends: [ 'osdep', 'ssl' ],
  227. scripts: {
  228. prebuild: `
  229. if (me.settings.compiler.hasPam && me.settings.goahead.pam) {
  230. me.target.libraries.push('pam')
  231. }
  232. `
  233. },
  234. },
  235. goahead: {
  236. type: 'exe',
  237. sources: [ 'src/goahead.c' ],
  238. headers: [ 'src/*.h' ],
  239. depends: [ 'libgo', 'install-certs' ],
  240. scripts: {
  241. prebuild: `
  242. if (me.settings.compiler.hasPam) {
  243. me.target.libraries.push('pam')
  244. }
  245. cp(['${BIN}/self.key', '${BIN}/self.crt'], 'src')
  246. cp(['${BIN}/self.key', '${BIN}/self.crt'], 'test')
  247. `,
  248. },
  249. },
  250. /*
  251. Compiler for web pages into C code
  252. */
  253. gopass: {
  254. enable: 'me.settings.goahead.auth',
  255. type: 'exe',
  256. sources: [ 'src/utils/gopass.c' ],
  257. headers: [ 'src/*.h' ],
  258. depends: [ 'libgo' ],
  259. },
  260. /*
  261. Compiler for web pages into C code
  262. */
  263. webcomp: {
  264. enable: 'me.settings.rom',
  265. type: 'exe',
  266. sources: [ 'src/utils/webcomp.c' ],
  267. headers: [ 'src/*.h' ],
  268. depends: [ ],
  269. },
  270. run: {
  271. home: 'src',
  272. run: 'goahead -v',
  273. },
  274. rom: {
  275. action: `
  276. let path = Path('src/rom.c')
  277. trace('Create', path)
  278. path.write(Cmd.run('webcomp rom.files', {dir: 'src'}))
  279. `,
  280. },
  281. install: {
  282. home: '${TOP}',
  283. generate: ' ',
  284. depends: [ 'all', 'stop', 'installBinary', 'start' ],
  285. action: `
  286. trace('Info', me.settings.title + ' installed at ' + me.prefixes.vapp)
  287. trace('Info', 'Configuration directory ' + me.prefixes.etc)
  288. trace('Info', 'Documents directory ' + me.prefixes.web)
  289. trace('Info', 'Executables directory ' + me.prefixes.vapp.join('bin'))
  290. trace('Info', 'Use "man goahead" for usage')
  291. trace('Info', 'Run via "cd ' + me.prefixes.etc + ' ; sudo goahead -v ' + me.prefixes.web + '"')
  292. trace('Info', 'Browse to ' + me.settings.goahead.listen[0].replace('*', 'localhost').replace(':80', '/'))
  293. let pid = Cmd.ps('goahead')
  294. if (pid && pid.length > 0) {
  295. trace('Info', me.settings.title + ' PID: ' + pid[0].pid)
  296. }
  297. `,
  298. },
  299. projects: {
  300. action: `genProjects('')`,
  301. },
  302. publish: {
  303. action: `publish()`,
  304. },
  305. mine: {
  306. action: `genProjects('', 'mine', Config.OS + '-' + Config.CPU)`,
  307. },
  308. mgen: {
  309. action: `genProjects('-with mbedtls', 'mine', Config.OS + '-' + Config.CPU)`,
  310. }
  311. },
  312. })