DokuWikiSetup.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace Hestia\WebApp\Installers\DokuWiki;
  3. use Hestia\System\Util;
  4. use \Hestia\WebApp\Installers\BaseSetup as BaseSetup;
  5. class DokuWikiSetup extends BaseSetup {
  6. protected $appInfo = [
  7. 'name' => 'DokuWiki',
  8. 'group' => 'wiki',
  9. 'enabled' => true,
  10. 'version' => 'stable_2020-07-29',
  11. 'thumbnail' => 'dokuwiki-logo.svg'
  12. ];
  13. protected $appname = 'dokuwiki';
  14. protected $extractsubdir = "/tmp-dokuwiki";
  15. protected $config = [
  16. 'form' => [
  17. 'wiki_name' => 'text',
  18. 'superuser' => 'text',
  19. 'real_name' => 'text',
  20. 'email' => 'text',
  21. 'password' => 'password',
  22. 'initial_ACL_policy' => [
  23. 'type' => 'select',
  24. 'options' => [
  25. '0: Open Wiki (read, write, upload for everyone)', // 0
  26. '1: Public Wiki (read for everyone, write and upload for registered users)', // 1
  27. '2: Closed Wiki (read, write, upload for registered users only)' // 3
  28. ],
  29. ],
  30. 'content_license' => [
  31. 'type' => 'select',
  32. 'options' => [
  33. 'cc-zero: CC0 1.0 Universal',
  34. 'publicdomain: Public Domain',
  35. 'cc-by: CC Attribution 4.0 International',
  36. 'cc-by-sa: CC Attribution-Share Alike 4.0 International',
  37. 'gnufdl: GNU Free Documentation License 1.3',
  38. 'cc-by-nc: CC Attribution-Noncommercial 4.0 International',
  39. 'cc-by-nc-sa: CC Attribution-Noncommercial-Share Alike 4.0 International',
  40. '0: Do not show any license information',
  41. ]
  42. ],
  43. ],
  44. 'resources' => [
  45. 'archive' => [ 'src' => 'https://github.com/splitbrain/dokuwiki/archive/refs/tags/release_stable_2020-07-29.zip' ],
  46. ],
  47. 'server' => [
  48. 'nginx' => [
  49. 'template' => 'default'
  50. ],
  51. 'php' => [
  52. 'supported' => [ '7.3','7.4' ],
  53. ]
  54. ],
  55. ];
  56. public function install(array $options = null, &$status=null)
  57. {
  58. parent::install($options);
  59. parent::setup($options);
  60. //check if ssl is enabled
  61. $this->appcontext->run('v-list-web-domain', [$this->appcontext->user(), $this->domain, 'json'], $status);
  62. $sslEnabled = ($status->json[$this->domain]['SSL'] == 'no' ? 0 : 1);
  63. $webDomain = ($sslEnabled ? "https://" : "http://") . $this->domain . "/";
  64. $this->appcontext->runUser('v-copy-fs-directory',[
  65. $this->getDocRoot($this->extractsubdir . "/dokuwiki-release_stable_2020-07-29/."),
  66. $this->getDocRoot()], $status);
  67. // enable htaccess
  68. $this->appcontext->runUser('v-move-fs-file', [$this->getDocRoot(".htaccess.dist"), $this->getDocRoot(".htaccess")], $status);
  69. $installUrl = $webDomain . "install.php";
  70. $cmd = "curl --request POST "
  71. . ($sslEnabled ? "" : "--insecure " )
  72. . "--url $installUrl "
  73. . "--header 'Content-Type: application/x-www-form-urlencoded' "
  74. . "--data l=en "
  75. . "--data 'd[title]=" . rawurlencode($options['wiki_name']) . "' "
  76. . "--data 'd[acl]=on' "
  77. . "--data 'd[superuser]=" . rawurlencode($options['superuser']) . "' "
  78. . "--data 'd[fullname]=" . rawurlencode($options['real_name']) . "' "
  79. . "--data 'd[email]=" . rawurlencode($options['email']) . "' "
  80. . "--data 'd[password]=" . rawurlencode($options['password']) . "' "
  81. . "--data 'd[confirm]=" . rawurlencode($options['password']) . "' "
  82. . "--data 'd[policy]=" . substr(rawurlencode($options['initial_ACL_policy']), 0, 1) . "' "
  83. . "--data 'd[license]=" . explode(":", rawurlencode($options['content_license'])[0]) . "' "
  84. . "--data submit=";
  85. exec($cmd, $output, $return_var);
  86. if($return_var > 0){
  87. throw new \Exception(implode( PHP_EOL, $output));
  88. }
  89. // remove temp folder
  90. $this->appcontext->runUser('v-delete-fs-file', [$this->getDocRoot("install.php")], $status);
  91. $this->cleanup();
  92. return ($status->code === 0);
  93. }
  94. }