/Core/Frameworks/Baikal/Model/Config/System.php

https://github.com/paulflorianhoberg/Baikal · PHP · 244 lines · 172 code · 28 blank · 44 comment · 1 complexity · bbb669acddef2696153d47efab0e297d MD5 · raw file

  1. <?php
  2. #################################################################
  3. # Copyright notice
  4. #
  5. # (c) 2012 Jérôme Schneider <mail@jeromeschneider.fr>
  6. # All rights reserved
  7. #
  8. # http://baikal.codr.fr
  9. #
  10. # This script is part of the Baïkal Server project. The Baïkal
  11. # Server project is free software; you can redistribute it
  12. # and/or modify it under the terms of the GNU General Public
  13. # License as published by the Free Software Foundation; either
  14. # version 2 of the License, or (at your option) any later version.
  15. #
  16. # The GNU General Public License can be found at
  17. # http://www.gnu.org/copyleft/gpl.html.
  18. #
  19. # This script is distributed in the hope that it will be useful,
  20. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. # GNU General Public License for more details.
  23. #
  24. # This copyright notice MUST APPEAR in all copies of the script!
  25. #################################################################
  26. namespace Baikal\Model\Config;
  27. class System extends \Baikal\Model\Config {
  28. protected $aConstants = array(
  29. "BAIKAL_PATH_SABREDAV" => array(
  30. "type" => "litteral",
  31. "comment" => "PATH to SabreDAV",
  32. ),
  33. "BAIKAL_AUTH_REALM" => array(
  34. "type" => "string",
  35. "comment" => "If you change this value, you'll have to re-generate passwords for all your users",
  36. ),
  37. "BAIKAL_CARD_BASEURI" => array(
  38. "type" => "litteral",
  39. "comment" => 'Should begin and end with a "/"',
  40. ),
  41. "BAIKAL_CAL_BASEURI" => array(
  42. "type" => "litteral",
  43. "comment" => 'Should begin and end with a "/"',
  44. ),
  45. "PROJECT_SQLITE_FILE" => array(
  46. "type" => "litteral",
  47. "comment" => "Define path to Baïkal Database SQLite file",
  48. ),
  49. "PROJECT_DB_MYSQL" => array(
  50. "type" => "boolean",
  51. "comment" => "MySQL > Use MySQL instead of SQLite ?",
  52. ),
  53. "PROJECT_DB_MYSQL_HOST" => array(
  54. "type" => "string",
  55. "comment" => "MySQL > Host, including ':portnumber' if port is not the default one (3306)",
  56. ),
  57. "PROJECT_DB_MYSQL_DBNAME" => array(
  58. "type" => "string",
  59. "comment" => "MySQL > Database name",
  60. ),
  61. "PROJECT_DB_MYSQL_USERNAME" => array(
  62. "type" => "string",
  63. "comment" => "MySQL > Username",
  64. ),
  65. "PROJECT_DB_MYSQL_PASSWORD" => array(
  66. "type" => "string",
  67. "comment" => "MySQL > Password",
  68. ),
  69. "BAIKAL_ENCRYPTION_KEY" => array(
  70. "type" => "string",
  71. "comment" => "A random 32 bytes key that will be used to encrypt data",
  72. ),
  73. "BAIKAL_CONFIGURED_VERSION" => array(
  74. "type" => "string",
  75. "comment" => "The currently configured Baïkal version",
  76. ),
  77. );
  78. # Default values
  79. protected $aData = array(
  80. "BAIKAL_PATH_SABREDAV" => 'PROJECT_PATH_FRAMEWORKS . "SabreDAV/lib/Sabre/"',
  81. "BAIKAL_AUTH_REALM" => "BaikalDAV",
  82. "BAIKAL_CARD_BASEURI" => 'PROJECT_BASEURI . "card.php/"',
  83. "BAIKAL_CAL_BASEURI" => 'PROJECT_BASEURI . "cal.php/"',
  84. "PROJECT_SQLITE_FILE" => 'PROJECT_PATH_SPECIFIC . "db/db.sqlite"',
  85. "PROJECT_DB_MYSQL" => FALSE,
  86. "PROJECT_DB_MYSQL_HOST" => "",
  87. "PROJECT_DB_MYSQL_DBNAME" => "",
  88. "PROJECT_DB_MYSQL_USERNAME" => "",
  89. "PROJECT_DB_MYSQL_PASSWORD" => "",
  90. "BAIKAL_ENCRYPTION_KEY" => "",
  91. "BAIKAL_CONFIGURED_VERSION" => "",
  92. );
  93. public function formMorphologyForThisModelInstance() {
  94. $oMorpho = new \Formal\Form\Morphology();
  95. $oMorpho->add(new \Formal\Element\Text(array(
  96. "prop" => "BAIKAL_CAL_BASEURI",
  97. "label" => "CalDAV base URI",
  98. "validation" => "required",
  99. "help" => "The absolute web path to cal.php",
  100. "popover" => array(
  101. "title" => "CalDAV base URI",
  102. "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>",
  103. )
  104. )));
  105. $oMorpho->add(new \Formal\Element\Text(array(
  106. "prop" => "BAIKAL_CARD_BASEURI",
  107. "label" => "CardDAV base URI",
  108. "validation" => "required",
  109. "help" => "The absolute web path to card.php",
  110. "popover" => array(
  111. "title" => "CardDAV base URI",
  112. "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>"
  113. )
  114. )));
  115. $oMorpho->add(new \Formal\Element\Text(array(
  116. "prop" => "BAIKAL_AUTH_REALM",
  117. "label" => "Auth realm",
  118. "validation" => "required",
  119. "help" => "Token used in authentication process.<br />If you change this, you'll have to reset all your users passwords.<br />You'll also loose access to this admin interface.",
  120. "popover" => array(
  121. "title" => "Auth realm",
  122. "content" => "If you change this, you'll loose your access to this interface.<br />In other words: <strong>you should not change this, unless YKWYD.</strong>"
  123. )
  124. )));
  125. $oMorpho->add(new \Formal\Element\Text(array(
  126. "prop" => "BAIKAL_PATH_SABREDAV",
  127. "label" => "Path to SabreDAV",
  128. "validation" => "required",
  129. "inputclass" => "input-xxlarge",
  130. "help" => "The absolute server path to SabreDAV API",
  131. "popover" => array(
  132. "title" => "Path to SabreDAV",
  133. "content" => "If Baïkal is hosted in a subfolder, this path should reflect it.<br /><strong>Whatever happens, it should begin and end with a slash.</strong>",
  134. "position" => "top"
  135. )
  136. )));
  137. $oMorpho->add(new \Formal\Element\Text(array(
  138. "prop" => "PROJECT_SQLITE_FILE",
  139. "label" => "SQLite file path",
  140. "validation" => "required",
  141. "inputclass" => "input-xxlarge",
  142. "help" => "The absolute server path to the SQLite file",
  143. )));
  144. $oMorpho->add(new \Formal\Element\Checkbox(array(
  145. "prop" => "PROJECT_DB_MYSQL",
  146. "label" => "Use MySQL",
  147. "help" => "If checked, Baïkal will use MySQL instead of SQLite.",
  148. "refreshonchange" => TRUE,
  149. )));
  150. $oMorpho->add(new \Formal\Element\Text(array(
  151. "prop" => "PROJECT_DB_MYSQL_HOST",
  152. "label" => "MySQL host",
  153. "help" => "Host ip or name, including ':portnumber' if port is not the default one (3306)"
  154. )));
  155. $oMorpho->add(new \Formal\Element\Text(array(
  156. "prop" => "PROJECT_DB_MYSQL_DBNAME",
  157. "label" => "MySQL database name",
  158. )));
  159. $oMorpho->add(new \Formal\Element\Text(array(
  160. "prop" => "PROJECT_DB_MYSQL_USERNAME",
  161. "label" => "MySQL username",
  162. )));
  163. $oMorpho->add(new \Formal\Element\Password(array(
  164. "prop" => "PROJECT_DB_MYSQL_PASSWORD",
  165. "label" => "MySQL password",
  166. )));
  167. return $oMorpho;
  168. }
  169. public function label() {
  170. return "Baïkal Settings";
  171. }
  172. protected static function getDefaultConfig() {
  173. $sBaikalVersion = BAIKAL_VERSION;
  174. $sCode =<<<CODE
  175. ##############################################################################
  176. # System configuration
  177. # Should not be changed, unless YNWYD
  178. #
  179. # RULES
  180. # 0. All folder pathes *must* be suffixed by "/"
  181. # 1. All URIs *must* be suffixed by "/" if pointing to a folder
  182. #
  183. # PATH to SabreDAV
  184. define("BAIKAL_PATH_SABREDAV", PROJECT_PATH_FRAMEWORKS . "SabreDAV/lib/Sabre/");
  185. # If you change this value, you'll have to re-generate passwords for all your users
  186. define("BAIKAL_AUTH_REALM", "BaikalDAV");
  187. # Should begin and end with a "/"
  188. define("BAIKAL_CARD_BASEURI", PROJECT_BASEURI . "card.php/");
  189. # Should begin and end with a "/"
  190. define("BAIKAL_CAL_BASEURI", PROJECT_BASEURI . "cal.php/");
  191. # Define path to Baïkal Database SQLite file
  192. define("PROJECT_SQLITE_FILE", PROJECT_PATH_SPECIFIC . "db/db.sqlite");
  193. # MySQL > Use MySQL instead of SQLite ?
  194. define("PROJECT_DB_MYSQL", FALSE);
  195. # MySQL > Host, including ':portnumber' if port is not the default one (3306)
  196. define("PROJECT_DB_MYSQL_HOST", "");
  197. # MySQL > Database name
  198. define("PROJECT_DB_MYSQL_DBNAME", "");
  199. # MySQL > Username
  200. define("PROJECT_DB_MYSQL_USERNAME", "");
  201. # MySQL > Password
  202. define("PROJECT_DB_MYSQL_PASSWORD", "");
  203. # A random 32 bytes key that will be used to encrypt data
  204. define("BAIKAL_ENCRYPTION_KEY", "");
  205. # The currently configured Baïkal version
  206. define("BAIKAL_CONFIGURED_VERSION", "{$sBaikalVersion}");
  207. CODE;
  208. $sCode = trim($sCode);
  209. return $sCode;
  210. }
  211. }