assets.ml 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. (*
  2. * _ _ ____ _
  3. * _| || |_/ ___| ___ _ __ _ __ ___ | |
  4. * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
  5. * |_ _|___) | __/ |_) | |_) | (_) |_|
  6. * |_||_| |____/ \___| .__/| .__/ \___/(_)
  7. * |_| |_|
  8. *
  9. * Personal Social Web.
  10. *
  11. * Copyright (C) The #Seppo contributors. All rights reserved.
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *)
  26. let ( let* ) = Result.bind
  27. let ( >>= ) = Result.bind
  28. open Astring
  29. (** Assets packed into the binary and to be unpacked and used as they are *)
  30. module Const = struct
  31. let delete_restore_marker = "delete-me-to-restore-missing"
  32. let mutabl =
  33. [
  34. Cfg.Urlcleaner.fn;
  35. ]
  36. let f_cdb (Mcdb.Cdb v) = v
  37. let all =
  38. [
  39. ".htaccess";
  40. (*
  41. ".well-known/nodeinfo/.htaccess"; (* dot dir missing *)
  42. ".well-known/nodeinfo/README.txt"; (* dot dir missing *)
  43. ".well-known/nodeinfo/index.json"; (* dot dir missing *)
  44. Webfinger.Server.target; (* dot dir missing *)
  45. *)
  46. "README.txt";
  47. "activitypub/blocked/0.jsa";
  48. "activitypub/blocked/0.xml";
  49. Ap.Following.Blocked.Atom.target ;
  50. Ap.Following.Blocked.Json.target ;
  51. "activitypub/liked/0.jsa";
  52. "activitypub/liked/0.xml";
  53. "activitypub/liked/index.jsa";
  54. "activitypub/liked/index.xml";
  55. "activitypub/outbox/0.jsa";
  56. "activitypub/outbox/0.xml";
  57. "activitypub/outbox/index.jsa";
  58. "activitypub/outbox/index.xml";
  59. "activitypub/subscribed_to/0.jsa";
  60. "activitypub/subscribed_to/0.xml";
  61. Ap.Following.Subscribed_to.Atom.target ;
  62. Ap.Following.Subscribed_to.Json.target ;
  63. "activitypub/subscribers/0.jsa";
  64. "activitypub/subscribers/0.xml";
  65. Ap.Followers.Atom.target;
  66. Ap.Followers.Json.target;
  67. "activitypub/index.html";
  68. "activitypub/README.txt";
  69. "app/.htaccess";
  70. "app/README.txt";
  71. "app/etc/ban.s";
  72. "app/etc/profile.s";
  73. "app/i-must-be-403.svg";
  74. "app/var/README.txt";
  75. Ap.Note.ibc_dir ^ "cur/README.txt";
  76. Ap.Note.ibc_dir ^ "new/README.txt";
  77. Ap.Note.ibc_dir ^ "tmp/README.txt";
  78. Tag.cdb |> f_cdb;
  79. Ap.Followers.cdb |> f_cdb;
  80. Ap.Following.cdb |> f_cdb;
  81. "app/var/db/o/d/README.txt";
  82. "app/var/db/o/m/README.txt";
  83. "app/var/db/o/p/README.txt";
  84. "app/var/db/o/t/README.txt";
  85. Storage.fn_id_cdb |> f_cdb;
  86. Storage.fn_url_cdb |> f_cdb;
  87. "app/var/log/seppo.log.0";
  88. "app/var/log/seppo.log";
  89. Ban.fn;
  90. "app/var/run/README.txt";
  91. "app/var/spool/job/cur/README.txt";
  92. "app/var/spool/job/err/README.txt";
  93. "app/var/spool/job/new/README.txt";
  94. "app/var/spool/job/run/README.txt";
  95. "app/var/spool/job/tmp/README.txt";
  96. "app/var/spool/job/wait/README.txt";
  97. "contrib/etc/apache2/sites-available/050-seppo.conf";
  98. "contrib/etc/lighttpd/conf-available/50-seppo.conf";
  99. "contrib/harden.sh";
  100. "contrib/README.txt";
  101. delete_restore_marker;
  102. "favicon.ico";
  103. "index.html";
  104. "me-avatar.jpg";
  105. "me-banner.jpg";
  106. (* "nodeinfo/2.1.json"; *)
  107. "o/d/README.txt";
  108. "o/p/index.xml";
  109. "o/t/index.json";
  110. "robots.txt";
  111. "seppo.pub.pem";
  112. "themes/current/404.html";
  113. "themes/current/actor.css";
  114. "themes/current/actor.js";
  115. "themes/current/actor.xsl";
  116. "themes/current/awesomplete.css";
  117. "themes/current/awesomplete.js";
  118. "themes/current/backoffice.js";
  119. "themes/current/backoffice.xsl";
  120. "themes/current/blocked.xsl";
  121. "themes/current/changepasswordform.xsl";
  122. "themes/current/configform.xsl";
  123. "themes/current/do=tools.xsl";
  124. "themes/current/feed-icon.svg";
  125. "themes/current/linkform.js";
  126. "themes/current/linkform.xsl";
  127. "themes/current/loginform.xsl";
  128. "themes/current/people.xsl";
  129. "themes/current/posts.css";
  130. "themes/current/posts.js";
  131. "themes/current/posts.xsl";
  132. "themes/current/README.txt";
  133. "themes/current/replies.css";
  134. "themes/current/replies.xsl";
  135. "themes/current/style.css";
  136. (* "themes/current/subscribed_to.js"; *)
  137. "themes/current/subscribed_to.xsl";
  138. (* "themes/current/subscribers.css"; *)
  139. "themes/current/subscribers.js";
  140. "themes/current/subscribers.xsl";
  141. "themes/current/tick.mp3";
  142. "themes/current/timeline.xsl";
  143. "themes/current/util.xsl";
  144. "themes/current/valid-atom.svg";
  145. ]
  146. @ mutabl
  147. (** evtl. restore packed files from inside the binary. *)
  148. let restore_if_nonex perm candidates =
  149. (* how to deal with IO erros? Let them fly! *)
  150. if not (File.exists delete_restore_marker)
  151. then candidates |> List.filter_map (File.restore_static ~perm)
  152. else []
  153. end
  154. (** Generated assets with local dependencies *)
  155. module Gen = struct
  156. let make x =
  157. Result.bind
  158. Webfinger.Server.(make target)
  159. (fun _ -> Ok x)
  160. (* ready to be used in the handler. *)
  161. let make_cgi x =
  162. match make x with
  163. | Error msg ->
  164. Logr.err (fun m -> m "%s %s" E.e1003 msg);
  165. Http.s500
  166. | Ok _ as o -> o
  167. end