"Fossies" - the Fresh Open Source Software Archive

Member "ampache-5.0.0/src/Module/Authorization/Access.php" (31 Aug 2021, 3625 Bytes) of package /linux/www/ampache-5.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Access.php" see the Fossies "Dox" file reference documentation.

    1 <?php
    2 /*
    3  * vim:set softtabstop=4 shiftwidth=4 expandtab:
    4  *
    5  * LICENSE: GNU Affero General Public License, version 3 (AGPL-3.0-or-later)
    6  * Copyright 2001 - 2020 Ampache.org
    7  *
    8  * This program is free software: you can redistribute it and/or modify
    9  * it under the terms of the GNU Affero General Public License as published by
   10  * the Free Software Foundation, either version 3 of the License, or
   11  * (at your option) any later version.
   12  *
   13  * This program is distributed in the hope that it will be useful,
   14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16  * GNU Affero General Public License for more details.
   17  *
   18  * You should have received a copy of the GNU Affero General Public License
   19  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
   20  *
   21  */
   22 
   23 declare(strict_types=0);
   24 
   25 namespace Ampache\Module\Authorization;
   26 
   27 use Ampache\Module\Authorization\Check\FunctionCheckerInterface;
   28 use Ampache\Module\Authorization\Check\PrivilegeCheckerInterface;
   29 use Ampache\Module\System\Dba;
   30 
   31 /**
   32  * Access Class
   33  *
   34  * This class handles the access list mojo for Ampache, it is meant to restrict
   35  * access based on IP and maybe something else in the future.
   36  *
   37  */
   38 class Access
   39 {
   40     // Variables from DB
   41     /**
   42      * @var integer $id
   43      */
   44     public $id;
   45 
   46     /**
   47      * @var string $name
   48      */
   49     public $name;
   50 
   51     /**
   52      * @var string $start
   53      */
   54     public $start;
   55 
   56     /**
   57      * @var string $end
   58      */
   59     public $end;
   60 
   61     /**
   62      * @var integer $level
   63      */
   64     public $level;
   65 
   66     /**
   67      * @var integer $user
   68      */
   69     public $user;
   70 
   71     /**
   72      * @var string $type
   73      */
   74     public $type;
   75 
   76     /**
   77      * @var boolean $enabled
   78      *
   79      * @deprecated seems not to be in use
   80      */
   81     public $enabled;
   82 
   83     /**
   84      * constructor
   85      *
   86      * Takes an ID of the access_id dealie :)
   87      * @param integer|null $access_id
   88      */
   89     public function __construct($access_id)
   90     {
   91         /* Assign id for use in get_info() */
   92         $this->id = (int)$access_id;
   93 
   94         $info = $this->has_info();
   95         foreach ($info as $key => $value) {
   96             $this->$key = $value;
   97         }
   98 
   99         return true;
  100     }
  101 
  102     /**
  103      * has_info
  104      *
  105      * Gets the vars for $this out of the database.
  106      * @return array
  107      */
  108     private function has_info()
  109     {
  110         $sql        = 'SELECT * FROM `access_list` WHERE `id` = ?';
  111         $db_results = Dba::read($sql, array($this->id));
  112 
  113         return Dba::fetch_assoc($db_results);
  114     }
  115 
  116     /**
  117      * check_function
  118      *
  119      * This checks if specific functionality is enabled.
  120      * @param string $type
  121      * @return boolean
  122      *
  123      * @deprecated See FunctionChecker::check
  124      */
  125     public static function check_function($type)
  126     {
  127         global $dic;
  128 
  129         return $dic->get(FunctionCheckerInterface::class)->check(
  130             (string) $type
  131         );
  132     }
  133 
  134     /**
  135      * check
  136      *
  137      * This is the global 'has_access' function. it can check for any 'type'
  138      * of object.
  139      *
  140      * Everything uses the global 0,5,25,50,75,100 stuff. GLOBALS['user'] is
  141      * always used.
  142      * @param string $type
  143      * @param integer $level
  144      * @param integer|null $user_id
  145      * @return boolean
  146      *
  147      * @deprecated See PrivilegeChecker::check
  148      */
  149     public static function check($type, $level, $user_id = null)
  150     {
  151         global $dic;
  152 
  153         return $dic->get(PrivilegeCheckerInterface::class)->check(
  154             (string) $type,
  155             (int) $level,
  156             $user_id
  157         );
  158     }
  159 }