1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 
<?php
    declare(strict_types=1);
    /**
     *  +------------------------------------------------------------+
     *  | apnscp                                                     |
     *  +------------------------------------------------------------+
     *  | Copyright (c) Apis Networks                                |
     *  +------------------------------------------------------------+
     *  | Licensed under Artistic License 2.0                        |
     *  +------------------------------------------------------------+
     *  | Author: Matt Saladna (msaladna@apisnetworks.com)           |
     *  +------------------------------------------------------------+
     */

    /**
     *  htaccess/htpasswd
     *
     * @package core
     */
    class Htpasswd_Module extends Module_Skeleton
    {
        const HTPASSWD_DIR = '/var/www/.htfiles';
        const DEF_REALM_NAME = 'Restricted Area';

        /**
         * {{{ void __construct(void)
         *
         * @ignore
         */
        public function __construct()
        {
            parent::__construct();
            $this->exportedFunctions = array(
                'is_protected'    => PRIVILEGE_SITE,
                'get_locations'   => PRIVILEGE_SITE,
                'delete_location' => PRIVILEGE_SITE,
                'edit_location'   => PRIVILEGE_SITE,
                'location_info'   => PRIVILEGE_SITE
            );
        }

        public function is_protected($host, $path = '/')
        {

        }

        public function protect_location(
            $host,
            $path = '/',
            $realm = self::DEF_REALM_NAME,
            $type = 'digest'
        ) {

        }

        public function get_locations($host)
        {

        }

        public function delete_location($host, $path)
        {

        }

        public function edit_location($host, $path, $opts)
        {

        }

        public function location_info($host, $path)
        {

        }

        public function user_exists($host, $user)
        {

        }

        public function add_user($host, $user, $passwd = null)
        {

        }

        public function delete_user($host, $user)
        {

        }

        public function get_users($host)
        {

        }

        public function get_groups($host)
        {

        }

        public function change_password($host, $user)
        {

        }

        public function create_group($host, $group, $users = array())
        {

        }

        public function user_in_group($host, $user, $group)
        {

        }

        public function remove_user_group($host, $user, $group)
        {

        }

        public function add_user_group($host, $user, $group)
        {

        }

        public function delete_group($host, $group)
        {

        }

        public function deauthorize_role($host, $role)
        {

        }

        public function authorize_role($host, $role)
        {

        }

        public function is_authorized($host, $role, $path = '/')
        {

        }

        /**
         * Load .htpasswd
         *
         * @param string $host host
         * @return string .htpasswd contents
         */
        private function _load_htpasswd($host)
        {
            if (!preg_match(Regex::HTTP_HOST)) {
                return error($host . ': invalid host');
            }
            $htpasswd = $this->domain_fs_path() . self::HTPASSWD_DIR . '/' . $host;
            if (!file_exists($htpasswd)) {
                return error(self::HTPASSWD_DIR . '/' . $host . ': htpasswd does not exist');
            }

            return file_get_contents($htpasswd);
        }

        private function _load_htaccess($host, $path = '/')
        {

        }
    }

?>