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