ACC SHELL
<?php
// Author: Jakub Macek, CZ; Copyright: Poski.com s.r.o.; Code is 100% my work. Do not copy.
// CURRENTLY NOT USED
class ACL
{
/*public static $container = array();
const TYPE_ALLOW_ALL = 1;
const TYPE_DENY_ALL = 2;
const TYPE_ALLOW = 3;
const TYPE_DENY = 4;
const TYPE_SCRIPT = 5;
const TYPE_FINAL = 128;
public $ouid = '';
public $orid = '';
public $oacl = array();
public $subject = '';
public $type = 0;
public $value = '';
public static function add($module, $action, $name = null, $options = array())
{
$temp = new acl(false);
$temp->ouid = $action;
$temp->orid = $module;
$temp->oacl = $options;
$temp->subject = $module . '/' . $action;
$temp->value = ($name ? $name : __($action, $module));
self::$container[$temp->subject] = $temp;
}
public function get($key, $value = null)
{
return (isset($this->oacl[$key]) ? $this->oacl[$key] : $value);
}
public function set($key, $value)
{
if ($key === null)
foreach ($value as $k => $v)
$this->set($k, $v);
else if (($value === null) && isset($this->oacl[$key]))
unset($this->oacl[$key]);
else if ($value !== null)
$this->oacl[$key] = $value;
else
$this->oacl[$key] = $value;
}
public function __construct($ouid = null, $orid = null, $oacl = array())
{
if ($ouid === false)
return;
$result = $this->apply($ouid, $orid, $oacl);
foreach (array('ouid', 'orid', 'oacl') as $k)
$this->$k = $result->$k;
}
public static function rule($subject, $type, $value)
{
$temp = new acl();
$temp->subject = $subject;
$temp->type = $type;
$temp->value = $value;
return $temp;
}
public function apply($ouid = null, $orid = null, $oacl = array())
{
$result = clone($this);
if (is_object($ouid))
{
if (!($ouid instanceof object))
error('not instance of object');
if ($orid === false)
foreach (array('ouid', 'orid', 'oacl') as $fid)
list($ouid->$fid, $result->$fid) = array($result->$fid, $ouid->$fid);
$oacl = array();
foreach ($ouid->oacl as $v)
$oacl[$v->subject] = array($v->type, $v->value);
$orid = $ouid->orid;
$ouid = $ouid->ouid;
}
if ($ouid !== null)
$result->ouid = $ouid;
if ($orid !== null)
$result->orid = $orid;
foreach ($oacl as $k => $v)
{
if (is_object($v))
$r = clone($v);
else
{
$r = new acl(false);
$r->subject = $k;
if (is_bool($v))
$r->type = $v ? acl::TYPE_ALLOW_ALL : acl::TYPE_DENY_ALL;
if (is_string($v))
{
$r->type = acl::TYPE_ALLOW;
$r->value = $v;
}
if (is_array($v))
{
$r->type = $v[0];
$r->value = $v[1];
}
}
$result->oacl[] = $r;
}
return $result;
}
public function select_type($value = null)
{
$result = array(
acl::TYPE_ALLOW_ALL => __('type-allow-all', 'acl'),
acl::TYPE_DENY_ALL => __('type-deny-all', 'acl'),
acl::TYPE_ALLOW => __('type-allow', 'acl'),
acl::TYPE_DENY => __('type-deny', 'acl'),
);
if (m('@users') && isAdministrator())
{
$result[acl::TYPE_FINAL] = __('type-final', 'acl');
$result[acl::TYPE_FINAL + acl::TYPE_ALLOW_ALL] = __('type-allow-all-final', 'acl');
$result[acl::TYPE_FINAL + acl::TYPE_DENY_ALL] = __('type-deny-all-final', 'acl');
$result[acl::TYPE_FINAL + acl::TYPE_ALLOW] = __('type-allow-final', 'acl');
$result[acl::TYPE_FINAL + acl::TYPE_DENY] = __('type-deny-final', 'acl');
}
return object::select($value, $result);
}
public function acl($invocation, $action)
{
return null;
}*/
public static function check($action = null, $object = null, $debug = false)
{
if ($action instanceof Invocation)
{
$invocation = $action;
$action = $invocation->action();
}
else
$invocation = null;
if (!m('@users'))
return false;
if (!USER)
return false;
if (($action === null) && ($object === null))
return true;
$rights = array(
'u:' . USER,
'r:everyone'
);
foreach (user()->roles_array as $group)
$rights[] = 'r:' . $group;
if ((USER == 'administrator') || (in_array('r:administrator', $rights)))
return true;
if ($object === null)
return false;
$temp = $object->acl($invocation, $action);
if ($temp !== null)
return $temp;
if ($object->ouid == USER)
return true;
if (in_array('r:' . $object->orid, $rights))
return true;
/*if (!$object->oacl || !is_array($object->oacl))
return false;
$ok = false;
foreach ($object->oacl as $k => $v)
if (in_array($v->subject, $rights))
{
$change = null;
$type = ($v->type & acl::TYPE_FINAL) ? ($v->type - acl::TYPE_FINAL) : $v->type;
if ($type == acl::TYPE_SCRIPT)
if (($temp = eval($v->value)) !== null)
$change = $temp;
if ($type == acl::TYPE_ALLOW_ALL)
$change = true;
if ($type == acl::TYPE_DENY_ALL)
$change = false;
else if ($action)
{
$a = preg_split('/[;,\s]/', $v->value);
if (($type == acl::TYPE_ALLOW) && in_array($action->id, $a))
$change = true;
if (($type == acl::TYPE_DENY) && in_array($action->id, $a))
$change = false;
}
if ($change !== null)
$ok = $change;
if (($change !== null) && $v->type & acl::TYPE_FINAL)
break;
}*/
return $ok;
}
}
?>
ACC SHELL 2018