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 /** @var SubscriptionFactory */ 59 protected $subscriptionFactory; 60 61 public function __get($property) { 62 $models = array('userFactory', 'threadFactory', 'labelFactory', 'thread_commentFactory', 'taskFactory', 'task_programFactory', 'task_commentFactory', 'authentication_tokenFactory', 'subscriptionFactory'); 63 if (in_array($property, $models) || 64 in_array($property, array('sqlite', 'db', 'acl', 'dw_auth', 'user_nick', 'action', 'conf'))) { 65 return $this->$property; 66 } 67 } 68 69 public function factory($table) { 70 $prop = $table . 'Factory'; 71 72 return $this->$prop; 73 } 74 75 protected function update_level($level) { 76 if ($level > $this->level) { 77 $this->level = $level; 78 } 79 } 80 81 public function get_level() { 82 return $this->level; 83 } 84 85 public function __construct($dw_auth, $user_nick, $action, $skip_acl=false) { 86 $this->dw_auth = $dw_auth; 87 $this->user_nick = $user_nick; 88 $this->action = $action; 89 $this->conf = $action->getGlobalConf(); 90 91 $this->db_helper = plugin_load('helper', 'bez_db'); 92 93 $this->sqlite = $this->db_helper->getDB(); 94 $this->db = $this->sqlite->getAdapter()->getDb(); 95 $this->db->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); 96 $busy_timeout = 1000 * (int)$this->action->getConf('busy_timeout'); 97 $this->db->exec("PRAGMA busy_timeout = $busy_timeout"); 98 99 $this->userFactory = new UserFactory($this); 100 101 $this->threadFactory = new ThreadFactory($this); 102 103 $this->labelFactory = new LabelFactory($this); 104 105 $this->thread_commentFactory = new Thread_commentFactory($this); 106 107 $this->taskFactory = new TaskFactory($this); 108 109 $this->task_programFactory = new Task_programFactory($this); 110 111 $this->task_commentFactory = new Task_commentFactory($this); 112 113 $this->authentication_tokenFactory = new Authentication_tokenFactory($this); 114 115 $this->subscriptionFactory = new SubscriptionFactory($this); 116 117 if ($skip_acl) { 118 $this->update_level(BEZ_AUTH_ADMIN); 119 } else { 120 $userd = $this->dw_auth->getUserData($this->user_nick); 121 if ($userd !== false && is_array($userd['grps'])) { 122 $grps = $userd['grps']; 123 if (in_array('admin', $grps ) || in_array('bez_admin', $grps )) { 124 $this->update_level(BEZ_AUTH_ADMIN); 125 } elseif (in_array('bez_leader', $grps )) { 126 $this->update_level(BEZ_AUTH_LEADER); 127 } else { 128 $this->update_level(BEZ_AUTH_USER); 129 } 130 } elseif (isset($_GET['t'])) { 131 $page_id = $this->action->id(); 132 133 $user_tok = trim($_GET['t']); 134 if ($this->authentication_tokenFactory->get_token($page_id) == $user_tok) { 135 $this->update_level(BEZ_AUTH_VIEWER); 136 } 137 } 138 } 139 } 140} 141