1<?php 2 3namespace dokuwiki\plugin\bez\mdl; 4 5require_once DOKU_PLUGIN . 'bez/vendor/phpmailer/phpmailer/src/Exception.php'; 6require_once DOKU_PLUGIN . 'bez/vendor/phpmailer/phpmailer/src/PHPMailer.php'; 7require_once DOKU_PLUGIN . 'bez/vendor/phpmailer/phpmailer/src/SMTP.php'; 8 9//ACL level defines 10define('BEZ_AUTH_NONE', 0); 11define('BEZ_AUTH_VIEWER', 2); 12define('BEZ_AUTH_USER', 5); 13define('BEZ_AUTH_LEADER', 10); 14define('BEZ_AUTH_ADMIN', 20); 15 16define('BEZ_PERMISSION_UNKNOWN', -1); 17define('BEZ_PERMISSION_NONE', 0); 18define('BEZ_PERMISSION_VIEW', 1); 19define('BEZ_PERMISSION_CHANGE', 2); 20define('BEZ_PERMISSION_DELETE', 3); 21 22 23class Model { 24 /** @var \helper_plugin_sqlite */ 25 protected $sqlite; 26 27 /** @var \SQLite3 */ 28 protected $db; 29 30 protected $level = BEZ_AUTH_NONE; 31 32 protected $dw_auth, $user_nick, $action, $conf; 33 34 /** @var ThreadFactory */ 35 protected $threadFactory; 36 37 /** @var UserFactory */ 38 protected $userFactory; 39 40 /** @var LabelFactory */ 41 protected $labelFactory; 42 43 /** @var Thread_commentFactory */ 44 protected $thread_commentFactory; 45 46 /** @var TaskFactory */ 47 protected $taskFactory; 48 49 /** @var Task_programFactory */ 50 protected $task_programFactory; 51 52 /** @var Task_commentFactory */ 53 protected $task_commentFactory; 54 55 /** @var Authentication_tokenFactory */ 56 protected $authentication_tokenFactory; 57 58 public function __get($property) { 59 $models = array('userFactory', 'threadFactory', 'labelFactory', 'thread_commentFactory', 'taskFactory', 'task_programFactory', 'task_commentFactory', 'authentication_tokenFactory'); 60 if (in_array($property, $models) || 61 in_array($property, array('sqlite', 'db', 'acl', 'dw_auth', 'user_nick', 'action', 'conf'))) { 62 return $this->$property; 63 } 64 } 65 66 public function factory($table) { 67 $prop = $table . 'Factory'; 68 69 return $this->$prop; 70 } 71 72 protected function update_level($level) { 73 if ($level > $this->level) { 74 $this->level = $level; 75 } 76 } 77 78 public function get_level() { 79 return $this->level; 80 } 81 82 public function __construct($dw_auth, $user_nick, $action, $skip_acl=false) { 83 $this->dw_auth = $dw_auth; 84 $this->user_nick = $user_nick; 85 $this->action = $action; 86 $this->conf = $action->getGlobalConf(); 87 88 $this->db_helper = plugin_load('helper', 'bez_db'); 89 90 $this->sqlite = $this->db_helper->getDB(); 91 $this->db = $this->sqlite->getAdapter()->getDb(); 92 $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); 93 $busy_timeout = 1000 * (int)$this->action->getConf('busy_timeout'); 94 $this->db->exec("PRAGMA busy_timeout = $busy_timeout"); 95 96 $this->userFactory = new UserFactory($this); 97 98 $this->threadFactory = new ThreadFactory($this); 99 100 $this->labelFactory = new LabelFactory($this); 101 102 $this->thread_commentFactory = new Thread_commentFactory($this); 103 104 $this->taskFactory = new TaskFactory($this); 105 106 $this->task_programFactory = new Task_programFactory($this); 107 108 $this->task_commentFactory = new Task_commentFactory($this); 109 110 $this->authentication_tokenFactory = new Authentication_tokenFactory($this); 111 112 if ($skip_acl) { 113 $this->update_level(BEZ_AUTH_ADMIN); 114 } else { 115 $userd = $this->dw_auth->getUserData($this->user_nick); 116 if ($userd !== false && is_array($userd['grps'])) { 117 $grps = $userd['grps']; 118 if (in_array('admin', $grps ) || in_array('bez_admin', $grps )) { 119 $this->update_level(BEZ_AUTH_ADMIN); 120 } elseif (in_array('bez_leader', $grps )) { 121 $this->update_level(BEZ_AUTH_LEADER); 122 } else { 123 $this->update_level(BEZ_AUTH_USER); 124 } 125 } elseif (isset($_GET['t'])) { 126 $page_id = $this->action->id(); 127 128 $user_tok = trim($_GET['t']); 129 if ($this->authentication_tokenFactory->get_token($page_id) == $user_tok) { 130 $this->update_level(BEZ_AUTH_VIEWER); 131 } 132 } 133 } 134 } 135} 136