From 04b4897dd86d862957d95a5d6090af7a026dd82c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 18:55:30 -0700 Subject: First attempt to turn access control into an object class. The access control manipulation is getting too complex and this will help keep it manageable and reduce a lot of code duplication. --- include/AccessList.php | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 include/AccessList.php (limited to 'include/AccessList.php') diff --git a/include/AccessList.php b/include/AccessList.php new file mode 100644 index 000000000..82d55c0e6 --- /dev/null +++ b/include/AccessList.php @@ -0,0 +1,72 @@ +allow_cid = $channel['channel_allow_cid']; + $this->allow_gid = $channel['channel_allow_gid']; + $this->deny_cid = $channel['channel_deny_cid']; + $this->deny_gid = $channel['channel_deny_gid']; + } + else { + $this->allow_cid = ''; + $this->allow_gid = ''; + $this->deny_cid = ''; + $this->deny_gid = ''; + } + + $this->explicit = false; + } + + function get_explicit() { + return $this->explicit; + } + + function set($arr,$explicit = true) { + $this->allow_cid = $arr['allow_cid']; + $this->allow_gid = $arr['allow_gid']; + $this->deny_cid = $arr['deny_cid']; + $this->deny_gid = $arr['deny_gid']; + + $this->explicit = $explicit; + } + + function get() { + return array( + 'allow_cid' => $this->allow_cid, + 'allow_gid' => $this->allow_gid, + 'deny_cid' => $this->deny_cid, + 'deny_gid' => $this->deny_gid, + ); + } + + function set_from_array($arr,$explicit = true) { + $this->allow_cid = perms2str((is_array($arr['contact_allow'])) + ? $arr['contact_allow'] : explode(',',$arr['contact_allow'])); + $this->allow_gid = perms2str((is_array($arr['group_allow'])) + ? $arr['group_allow'] : explode(',',$arr['group_allow'])); + $this->deny_cid = perms2str((is_array($arr['contact_deny'])) + ? $arr['contact_deny'] : explode(',',$arr['contact_deny'])); + $this->deny_gid = perms2str((is_array($arr['group_deny'])) + ? $arr['group_deny'] : explode(',',$arr['group_deny'])); + + $this->explicit = $explicit; + } + + function is_private() { + return (($this->allow_cid || $this->allow_gid || $this->deny_cid || $this->deny_gid) ? true : false); + } + +} + -- cgit v1.2.3 From 3fbb955cf23c5f92ba96086841ac6a2c510d4870 Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 21:22:59 -0700 Subject: start conversion to AccessList object --- include/AccessList.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include/AccessList.php') diff --git a/include/AccessList.php b/include/AccessList.php index 82d55c0e6..d4653de6a 100644 --- a/include/AccessList.php +++ b/include/AccessList.php @@ -10,8 +10,7 @@ class AccessList { private $explicit; - - function _construct($channel) { + function __construct($channel) { if($channel) { $this->allow_cid = $channel['channel_allow_cid']; -- cgit v1.2.3 From ca0bc2bb7bc2b9e7d81a356a394d47bcb688004c Mon Sep 17 00:00:00 2001 From: redmatrix Date: Thu, 27 Aug 2015 22:20:30 -0700 Subject: more work on AccessList integration --- include/AccessList.php | 62 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'include/AccessList.php') diff --git a/include/AccessList.php b/include/AccessList.php index d4653de6a..46e66d33d 100644 --- a/include/AccessList.php +++ b/include/AccessList.php @@ -8,7 +8,9 @@ class AccessList { private $deny_cid; private $deny_gid; - private $explicit; + /* indicates if we are using the default constructor values or values that have been set explicitly. */ + + private $explicit; function __construct($channel) { @@ -69,3 +71,61 @@ class AccessList { } +/** + * @brief Used to wrap ACL elements in angle brackets for storage. + * + * @param[in,out] array &$item + */ +function sanitise_acl(&$item) { + if (strlen($item)) + $item = '<' . notags(trim($item)) . '>'; + else + unset($item); +} + +/** + * @brief Convert an ACL array to a storable string. + * + * @param array $p + * @return array + */ +function perms2str($p) { + $ret = ''; + + if (is_array($p)) + $tmp = $p; + else + $tmp = explode(',', $p); + + if (is_array($tmp)) { + array_walk($tmp, 'sanitise_acl'); + $ret = implode('', $tmp); + } + + return $ret; +} + + +/** + * @brief Turn user/group ACLs stored as angle bracketed text into arrays. + * + * turn string array of angle-bracketed elements into string array + * e.g. "<123xyz><246qyo>" => array(123xyz,246qyo,sxo33e); + * + * @param string $s + * @return array + */ +function expand_acl($s) { + $ret = array(); + + if(strlen($s)) { + $t = str_replace('<','',$s); + $a = explode('>',$t); + foreach($a as $aa) { + if($aa) + $ret[] = $aa; + } + } + + return $ret; +} -- cgit v1.2.3