ホームページ >バックエンド開発 >PHPチュートリアル >PHP を使用して効率的で安全な FTP サーバーを実装する (2)

PHP を使用して効率的で安全な FTP サーバーを実装する (2)

WBOY
WBOYオリジナル
2016-06-13 12:28:09895ブラウズ

PHP を使って効率的で安全な FTP サーバーを実装する (2)

前回の記事からの続きです。

1. ユーザークラス CUser を実装します。

ユーザーはテキスト形式で保存され、ユーザー配列は json でエンコードされます。

<span style="color: #000000;">用户文件格式: </span>* <span style="color: #0000ff;">array</span><span style="color: #000000;">( </span>*         'user1' => <span style="color: #0000ff;">array</span><span style="color: #000000;">( </span>*             'pass'=>'', *             'group'=>'', *             'home'=>'/home/ftp/', <span style="color: #008000;">//</span><span style="color: #008000;">ftp主目录</span> *             'active'=><span style="color: #0000ff;">true</span>, *             'expired=>'2015-12-12'<span style="color: #000000;">, *             </span>'description'=>''<span style="color: #000000;">, *             </span>'email' => ''<span style="color: #000000;">, *             </span>'folder'<span style="color: #000000;">=>array( *                     //可以列出主目录下的文件和目录,但不能创建和删除,也不能进入主目录下的目录 *                     //前1-5位是文件权限,6-9是文件夹权限,10是否继承(inherit) *                     array(</span>'path'=>'/home/ftp/','access'=>'RWANDLCNDI'<span style="color: #000000;">), *                     //可以列出/home/ftp/a/下的文件和目录,可以创建和删除,可以进入/home/ftp/a/下的子目录,可以创建和删除。 *                     array(</span>'path'=>'/home/ftp/a/','access'=>'RWAND-----'<span style="color: #000000;">), *             ), *             </span>'ip'<span style="color: #000000;">=>array( *                 </span>'allow'<span style="color: #000000;">=>array(ip1,ip2,...),//支持*通配符: 192.168.0.* *                 </span>'deny'<span style="color: #000000;">=>array(ip1,ip2,...) *             ) *         )  * ) *  * 组文件格式: * array( *         </span>'group1'<span style="color: #000000;">=>array( *             </span>'home'=>'/home/ftp/dept1/'<span style="color: #000000;">, *             </span>'folder'<span style="color: #000000;">=>array( *  *             ), *             </span>'ip'<span style="color: #000000;">=>array( *                 </span>'allow'<span style="color: #000000;">=>array(ip1,ip2,...), *                 </span>'deny'<span style="color: #000000;">=>array(ip1,ip2,...) *            ) *         ) * )</span>

フォルダーとファイルのアクセス許可の説明:

 * 文件权限  * R读 : 允许用户读取(即下载)文件。该权限不允许用户列出目录内容,执行该操作需要列表权限。  * W写: 允许用户写入(即上传)文件。该权限不允许用户修改现有的文件,执行该操作需要追加权限。 * A追加: 允许用户向现有文件中追加数据。该权限通常用于使用户能够对部分上传的文件进行续传。  * N重命名: 允许用户重命名现有的文件。 * D删除: 允许用户删除文件。  *  * 目录权限  * L列表: 允许用户列出目录中包含的文件。 * C创建: 允许用户在目录中新建子目录。  * N重命名: 允许用户在目录中重命名现有子目录。 * D删除: 允许用户在目录中删除现有子目录。注意: 如果目录包含文件,用户要删除目录还需要具有删除文件权限。 *  * 子目录权限 * I继承: 允许所有子目录继承其父目录具有的相同权限。继承权限适用于大多数情况,但是如果访问必须受限于子文件夹,例如实施强制访问控制(Mandatory Access Control)时,则取消继承并为文件夹逐一授予权限。 * 

実装コードは以下の通り:

<span style="color: #0000ff;">クラス</span><span style="color: #000000;"> User{ </span><span style="color: #0000ff;">const</span> I = 1;    <span style="color: #008000;">//</span><span style="color: #008000;">継承</span> <span style="color: #0000ff;">const</span> FD = 2;    <span style="color: #008000;">//</span><span style="color: #008000;"> フォルダー削除</span> <span style="color: #0000ff;">const</span> FN = 4;    <span style="color: #008000;">//</span><span style="color: #008000;"> フォルダーの名前変更</span> <span style="color: #0000ff;">const</span> FC = 8;    <span style="color: #008000;">//</span><span style="color: #008000;"> フォルダー作成</span> <span style="color: #0000ff;">const</span> FL = 16;    <span style="color: #008000;">//</span><span style="color: #008000;"> フォルダーリスト</span> <span style="color: #0000ff;">const</span> D = 32;    <span style="color: #008000;">//</span><span style="color: #008000;"> ファイル削除</span> <span style="color: #0000ff;">const</span> N = 64;    <span style="color: #008000;">//</span><span style="color: #008000;"> ファイル名変更</span> <span style="color: #0000ff;">const</span> A = 128;    <span style="color: #008000;">//</span><span style="color: #008000;"> ファイル追加</span> <span style="color: #0000ff;">const</span> W = 256;    <span style="color: #008000;">//</span><span style="color: #008000;"> ファイル書き込み (アップロード)</span> <span style="color: #0000ff;">const</span> R = 512;    <span style="color: #008000;">//</span><span style="color: #008000;"> ファイルの読み取り (ダウンロード) </span> <span style="color: #0000ff;">private</span> <span style="color: #800080;">$hash_salt</span> = ''<span style="color: #000000;">;        </span><span style="color: #0000ff;">プライベート</span> <span style="color: #800080;">$user_file</span><span style="color: #000000;">;        </span><span style="color: #0000ff;">プライベート</span> <span style="color: #800080;">$group_file</span><span style="color: #000000;">;        </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$users</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();        </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$groups</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">();        </span><span style="color: #0000ff;">プライベート</span> <span style="color: #800080;">$file_hash</span> = ''<span style="color: #000000;">;         </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> __construct(){ </span><span style="color: #800080;">$this</span>->user_file = BASE_PATH.'/conf/users'<span style="color: #000000;">;        </span><span style="color: #800080;">$this</span>->group_file = BASE_PATH.'/conf/groups'<span style="color: #000000;">;        </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">reload();    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 戻り权制限表达式 * @param int $access * @return string </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span> AC(<span style="color: #800080;">$access</span><span style="color: #000000;">){ </span><span style="color: #800080;">$str</span> = ''<span style="color: #000000;">;        </span><span style="color: #800080;">$char</span> = <span style="color: #0000ff;">配列</span>('R','W','A','N','D','L','C','N ','D','I'<span style="color: #000000;">);        </span><span style="color: #0000ff;">for</span>(<span style="color: #800080;">$i</span> = 0; <span style="color: #800080;">$i</span> $i <span style="color: #000000;">){ </span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$access</span> & <span style="color: #008080;">pow</span>(2,9-<span style="color: #800080;">$i</span>))<span style="color: #800080;">$str</span>.= <span style="color: #800080;">$char</span>[<span style="color: #800080;">$i</span>];<span style="color: #0000ff;">else</span> <span style="color: #800080;">$str</span>.= '-'<span style="color: #000000;">;        }</span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$str</span><span style="color: #000000;">;    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 追加ダウンロード用户データ </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> reload( ){ </span><span style="color: #800080;">$user_file_hash</span> = <span style="color: #008080;">md5_file</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">user_file);        </span><span style="color: #800080;">$group_file_hash</span> = <span style="color: #008080;">md5_file</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">group_file);                </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>->file_hash != <span style="color: #008080;">md5</span>(<span style="color: #800080;">$user_file_hash</span>.<span style="color: #800080;">$group_file_hash</span> <span style="color: #000000;">)){ </span><span style="color: #0000ff;">if</span>((<span style="color: #800080;">$user</span> = <span style="color: #008080;">file_get_contents</span>(<span style="color: #800080;">$this</span>->user_file)) ! == <span style="color: #0000ff;">false</span><span style="color: #000000;">){ </span><span style="color: #800080;">$this</span>->users = json_decode(<span style="color: #800080;">$user</span>,<span style="color: #0000ff;">true</span>);                <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$this<span style="color: #800080;">-></span>users){ <span style="color: #000000;"></span>//<span style="color: #008000;"></span>folder排序<span style="color: #008000;"> </span> foreach<span style="color: #0000ff;"> (</span>$this<span style="color: #800080;">->users </span>as<span style="color: #0000ff;"> </span>$user<span style="color: #800080;">=></span>$profile<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$profile<span style="color: #800080;">['フォルダ'</span>])){ <span style="color: #000000;"></span>$this<span style="color: #800080;">-> users[</span>$user<span style="color: #800080;">]['folder'] = </span>$this<span style="color: #800080;">->sortFolder(</span>$profile<span style="color: #800080;">['folder'</span>]);                        } } } } <span style="color: #000000;"></span>if<span style="color: #0000ff;">((</span>$group<span style="color: #800080;"> = </span>file_get_contents<span style="color: #008080;">(</span>$this<span style="color: #800080;">->group_file)) !== </span>false<span style="color: #0000ff;"></span>){ <span style="color: #000000;"></span>$this<span style="color: #800080;">->groups = json_decode(</span>$group<span style="color: #800080;">,</span>true<span style="color: #0000ff;"></span>) ;                <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$this<span style="color: #800080;">-></span>グループ){ <span style="color: #000000;"></span>//<span style="color: #008000;"></span>フォルダ排序<span style="color: #008000;"> </span> foreach<span style="color: #0000ff;"> (</span>$this<span style="color: #800080;">->グループ </span>as<span style="color: #0000ff;"> </span>$group<span style="color: #800080;">=></span>$profile<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$profile<span style="color: #800080;">['フォルダ'</span>])){ <span style="color: #000000;"></span>$this<span style="color: #800080;">-> groups[</span>$group<span style="color: #800080;">]['folder'] = </span>$this<span style="color: #800080;">->sortFolder(</span>$profile<span style="color: #800080;">['folder'</span>]);                        <span style="color: #000000;"></span>$this<span style="color: #800080;">->file_hash = </span>md5<span style="color: #008080;">(</span>$user_file_hash<span style="color: #800080;">.</span>$group_file_hash<span style="color: #800080;"></span>);                    } }<span style="color: #008000;">/*</span><span style="color: #008000;">* * フォルダーの並べ替え* @return array </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span> sortFolder (<span style="color: #800080;">$folder</span><span style="color: #000000;">){ </span><span style="color: #008080;">uasort</span>(<span style="color: #800080;">$folder</span>, <span style="color: #0000ff;">function</span>(<span style="color: #800080;">$a</span> ,<span style="color: #800080;">$b</span><span style="color: #000000;">){ </span><span style="color: #0000ff;">return</span> <span style="color: #008080;">strnatcmp</span>(<span style="color: #800080;">$a</span>['path'], <span style="color: #800080;">$ b</span>['パス'<span style="color: #000000;">]); }); </span><span style="color: #800080;">$result</span> = <span style="color: #0000ff;">配列</span><span style="color: #000000;">(); (</span>$folder<span style="color: #0000ff;"> </span>as<span style="color: #800080;"> </span>$v<span style="color: #0000ff;"></span>){ <span style="color: #800080;"></span>$result<span style="color: #000000;">[] = </span>$v <span style="color: #800080;"></span>; } <span style="color: #800080;"></span>return<span style="color: #000000;"> </span>$result<span style="color: #0000ff;"></span> } <span style="color: #800080;"></span>/*<span style="color: #000000;"></span>* * ユーザーデータの保存 <span style="color: #008000;"></span>*/<span style="color: #008000;"> </span>public<span style="color: #008000;"> </span>function<span style="color: #0000ff;"></span> save(){ <span style="color: #0000ff;"></span>file_put_contents<span style="color: #000000;">(</span>$this<span style="color: #008080;">- >user_file, json_encode(</span>$this<span style="color: #800080;">->users),</span>LOCK_EX); <span style="color: #800080;"></span>file_put_contents<span style="color: #000000;">(</span>$this<span style="color: #008080;">-> group_file, json_encode(</span>$this<span style="color: #800080;">->groups),</span>LOCK_EX); } <span style="color: #800080;"></span>/*<span style="color: #000000;"></span>* * ユーザーを追加* @param string $user * @param string $pass * @param string $home * @param string $expired * @param boolean $active * @param string $group * @param string $description * @param string $email * @return boolean <span style="color: #008000;"></span>* /<span style="color: #008000;"> </span>public<span style="color: #008000;"> </span>function<span style="color: #0000ff;"> addUser(</span>$user<span style="color: #0000ff;">,</span>$pass<span style="color: #800080;">,</span>$home<span style="color: #800080;">,</span> $期限切れ<span style="color: #800080;">、</span>$active<span style="color: #800080;">=</span>true<span style="color: #800080;">、</span>$group<span style="color: #0000ff;">=''、</span>$description<span style="color: #800080;">=''、</span> $email<span style="color: #800080;"> = ''</span>){ <span style="color: #800080;"></span>$user<span style="color: #000000;"> = </span>strto lower<span style="color: #800080;">(</span>$user<span style="color: #008080;"></span>); 🎜>if<span style="color: #800080;">(</span>isset<span style="color: #000000;">(</span>$this<span style="color: #0000ff;">->users[</span>$user<span style="color: #0000ff;">]) || </span>空<span style="color: #800080;">( </span>$user<span style="color: #800080;"></span>)){ <span style="color: #0000ff;"></span>return<span style="color: #800080;"> </span>false<span style="color: #000000;"></span> } <span style="color: #0000ff;"></span>$this<span style="color: #0000ff;">->; </span>$user<span style="color: #000000;">] = </span>array<span style="color: #800080;"></span>( <span style="color: #800080;">'pass' => </span>md5<span style="color: #0000ff;">(</span>$user<span style="color: #000000;">.</span> $this<span style="color: #008080;">->hash_salt.</span>$pass<span style="color: #800080;">)、'home' => >、'active' => </span>$active<span style="color: #800080;">、'group' => >$グループ</span>, '説明' => <span style="color: #800080;">$説明</span>, 'メール' => <span style="color: #800080;">$メール</span>,<span style="color: #800080;"> ); 🎜> </span>本当<span style="color: #800080;"></span> }<span style="color: #008000;">/*</span><span style="color: #008000;">* * 設置用户资料 * @param string $user * @param array $profile * @return boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public </span> <span style="color: #0000ff;">function</span> setUserProfile(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$profile</span><span style="color: #000000;">){ </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strtower </span>(<span style="color: #800080;">$user</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$profile</span>) && <span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->users[ <span style="color: #800080;">$user</span><span style="color: #000000;">])){ </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$profile</span>['pass'<span style="color: #000000;">] )){ </span><span style="color: #800080;">$profile</span>['pass'] = <span style="color: #008080;">md5</span>(<span style="color: #800080;">$user</span>.<span style="color: #800080;">$this</span>->hash_salt. <span style="color: #800080;">$profile</span>['pass'<span style="color: #000000;">]);            } </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$profile</span>['active'<span style="color: #000000;">])){ </span><span style="color: #0000ff;">if</span>( !<span style="color: #008080;">is_bool</span>(<span style="color: #800080;">$profile</span>['active'<span style="color: #000000;">])){ </span><span style="color: #800080;">$profile</span>['active'] = <span style="color: #800080;">$profile </span>['アクティブ'] == 'true' ? <span style="color: #0000ff;">true</span> : <span style="color: #0000ff;">false</span><span style="color: #000000;">;                </span><span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>] = <span style="color: #008080;">array_merge</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]、<span style="color: #800080;">$profile</span><span style="color: #000000;">);            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;        </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 获取用户资料 * @param string $user * @return multitype:|boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> getUserProfile(<span style="color: #800080;">$user</span><span style="color: #000000;">){ </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$user</span>);        <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$this<span style="color: #800080;">->users[</span>$user<span style="color: #800080;"></span>])){ <span style="color: #000000;"> </span>return<span style="color: #0000ff;"> </span>$this<span style="color: #800080;">->users[</span>$user<span style="color: #800080;"></span>];        <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>false<span style="color: #0000ff;"></span>;    }<span style="color: #008000;">/*</span><span style="color: #008000;">* * 删除用户 * @param string $user * @return boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function </span> delUser(<span style="color: #800080;">$user</span><span style="color: #000000;">){ </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$user</span><span style="color: #000000;">) ;        </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span><span style="color: #000000;">])){ </span> <span style="color: #0000ff;">設定解除</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span><span style="color: #000000;">]);            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;        </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 取用户列表 * @return 配列 </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> getUserList(){ </span><span style="color: #800080;">$list</span> = <span style="color: #0000ff;">配列</span><span style="color: #000000;">();        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>-><span style="color: #000000;">users){ </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$this</span>-> users <span style="color: #0000ff;">as</span> <span style="color: #800080;">$user</span>=><span style="color: #800080;">$profile</span><span style="color: #000000;">){ </span><span style="color: #800080;">$list</span>[] = <span style="color: #800080;">$ユーザー</span><span style="color: #000000;">;            </span><span style="color: #008080;">ソート</span>(<span style="color: #800080;">$list</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$list</span><span style="color: #000000;">;    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 追加组 * @param string $group * @param string $home * @return boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public </span> <span style="color: #0000ff;">function</span> addGroup(<span style="color: #800080;">$group</span>,<span style="color: #800080;">$home</span><span style="color: #000000;">){ </span><span style="color: #800080;">$group</span> = <span style="color: #008080;">strtower </span>(<span style="color: #800080;">$group</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->groups[<span style="color: #800080;">$group</span><span style="color: #000000;">])){ </span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;        } </span><span style="color: #800080;">$this</span>->groups[<span style="color: #800080;">$group</span>] = <span style="color: #0000ff;">array</span><span style="color: #000000;">( </span>'home' => <span style="color: #800080;"> $home</span><span style="color: #000000;"> );        </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;    }</span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 配置構成 * @param string $group * @param array $profile * @return boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public </span> <span style="color: #0000ff;">function</span> setGroupProfile(<span style="color: #800080;">$group</span>,<span style="color: #800080;">$profile</span><span style="color: #000000;">){ </span><span style="color: #800080;">$group</span> = <span style="color: #008080;">strtower </span>(<span style="color: #800080;">$group</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">is_array</span>(<span style="color: #800080;">$profile</span>) && <span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->groups[ <span style="color: #800080;">$group</span><span style="color: #000000;">])){ </span><span style="color: #800080;">$this</span>->groups[<span style="color: #800080;">$group</span>] = <span style="color: #008080;">array_merge</span>(<span style="color: #800080;">$this</span>->グループ[<span style="color: #800080;">$グループ</span>]、<span style="color: #800080;">$profile</span><span style="color: #000000;">);            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;        </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 获取组资料 * @param string $group * @return multitype:|boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> getGroupProfile(<span style="color: #800080;">$group</span><span style="color: #000000;">){ </span><span style="color: #800080;">$group</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$group</span>);        <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$this<span style="color: #800080;">->groups[</span>$group<span style="color: #800080;"></span>])){ <span style="color: #000000;"> </span>return<span style="color: #0000ff;"> </span>$this<span style="color: #800080;">->groups[</span>$group<span style="color: #800080;"></span>];        <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>false<span style="color: #0000ff;"></span>;    } <span style="color: #000000;"></span>/*<span style="color: #008000;"></span>* * 删除组 * @param string $group * @return boolean <span style="color: #008000;"></span>*/<span style="color: #008000;"> </span>public<span style="color: #0000ff;"> </span> function<span style="color: #0000ff;"> delGroup(</span>$group<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>$group<span style="color: #800080;"> = </span>strto lower<span style="color: #008080;">(</span>$group<span style="color: #800080;"></span> );        <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$this<span style="color: #800080;">->groups[</span>$group<span style="color: #800080;"></span>])){ <span style="color: #000000;"> </span>設定解除<span style="color: #0000ff;">(</span>$this<span style="color: #800080;">->グループ[</span>$group<span style="color: #800080;"></span>]);            <span style="color: #000000;"></span>foreach<span style="color: #0000ff;"> (</span>$this<span style="color: #800080;">->users </span>as<span style="color: #0000ff;"> </span>$user<span style="color: #800080;"> => </span>$profile<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$profile<span style="color: #800080;">['グループ'] == </span>$group<span style="color: #800080;"></span>) <span style="color: #000000;"></span>$this <span style="color: #800080;">->users[</span>$user<span style="color: #800080;">]['グループ'] = ''</span>;            <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>true<span style="color: #0000ff;"></span>;        <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>false<span style="color: #0000ff;"></span>;    }<span style="color: #008000;">/*</span><span style="color: #008000;">* * グループリストの取得* @return array </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> getGroupList(){ </span><span style="color: #800080;">$list</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(); </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>- ><span style="color: #000000;">groups){ </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$this</span>->groups <span style="color: #0000ff;">as</span> <span style="color: #800080;">$group</span>=><span style="color: #800080;">$profile</span><span style="color: #000000;">){ </span><span style="color: #800080;">$list</span>[] = <span style="color: #800080;">$group</span><span style="color: #000000;"> } } </span><span style="color: #008080;">sort</span>; (<span style="color: #800080;">$list</span><span style="color: #000000;">); </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$list</span><span style="color: #000000;"> } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * グループユーザーリストを取得* @param string $group * @return array </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> getUserListOfGroup(<span style="color: #800080;">$group) </span><span style="color: #000000;">){ </span><span style="color: #800080;">$list</span> = <span style="color: #0000ff;">array</span><span style="color: #000000;">(); </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset (</span>$this<span style="color: #800080;">->groups[</span>$group<span style="color: #800080;">]) && </span>$this<span style="color: #800080;">-></span>users){ <span style="color: #000000;"></span>foreach <span style="color: #0000ff;"> (</span>$this<span style="color: #800080;">->ユーザー </span>as<span style="color: #0000ff;"> </span>$user<span style="color: #800080;">=></span>$profile<span style="color: #800080;"></span>){ <span style="color: #000000;"> </span>if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$profile<span style="color: #800080;">['グループ']) && </span>$profile<span style="color: #800080;">['グループ'] == </span>$ group <span style="color: #800080;"></span>){ <span style="color: #000000;"></span>$list<span style="color: #800080;">[] = </span>$user<span style="color: #800080;"></span> } } } <span style="color: #000000;"></span>sort<span style="color: #008080;">(</span>$list<span style="color: #800080;"></span>); <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$list<span style="color: #800080;"></span>;<span style="color: #008000;">/*</span><span style="color: #008000;">* * 用户验证 * @param string $user * @param string $pass * @param string $ip * @return boolean </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> checkUser(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$pass</span>,<span style="color: #800080;">$ip</span> = ''<span style="color: #000000;">) { </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">reload();        </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$user</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span><span style="color: #000000;">])){ </span> <span style="color: #0000ff;">if</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['active'] && <span style="color: #008080;">時間</span>() b022b75b2d0e31fed90b25a6edc3c352users[<span style="color: #800080;">$user</span>]['期限切れ'<span style="color: #000000;">]) </span>&& <span style="color: #800080;">$this</span>- >users[<span style="color: #800080;">$user</span>]['pass'] == <span style="color: #008080;">md5</span>(<span style="color: #800080;">$user</span>.<span style="color: #800080;">$this</span>->hash_salt. <span style="color: #800080;">$pass</span><span style="color: #000000;">)){ </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">空</span>(<span style="color: #800080;">$ip</span><span style="color: #000000;">)){ </span> <span style="color: #0000ff;">return</span> <span style="color: #0000ff;">true</span><span style="color: #000000;">;                }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #008000;">//</span><span style="color: #008000;">ip验证</span> <span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>- >checkIP(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$ip</span><span style="color: #000000;">);                } }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;            </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">false</span><span style="color: #000000;">;    }</span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 基本認証 * @param string $base64 </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> checkUserBasicAuth (<span style="color: #800080;">$base64</span><span style="color: #000000;">){ </span><span style="color: #800080;">$base64</span> = <span style="color: #008080;">trim</span>(<span style="color: #008080;">str_replace</span>('Basic ', '', <span style="color: #800080;">$base64</span><span style="color: #000000;">));        </span><span style="color: #800080;">$str</span> = <span style="color: #008080;">base64_decode</span>(<span style="color: #800080;">$base64</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$str</span> !== <span style="color: #0000ff;">false</span><span style="color: #000000;">){ </span><span style="color: #0000ff;">list</span>(<span style="color: #800080;">$user </span>,<span style="color: #800080;">$pass</span>) = <span style="color: #008080;">explode</span>(':', <span style="color: #800080;">$str</span>,2<span style="color: #000000;">);            </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">reload();            </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$user</span><span style="color: #000000;">);            </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span><span style="color: #000000;">])){ </span> <span style="color: #800080;">$group</span> = <span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['グループ'<span style="color: #000000;">];                </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$group</span> == 'admin' && <span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['active '] && <span style="color: #008080;">time</span>() ec0b9a49a9628e15fc874a9a9e3861b9users[<span style="color: #800080;">$user</span>]['group'<span style="color: #000000;">] </span><span style="color: #008000;">//</span><span style="color: #008000;">グループはマッチングを許可します</span> <span style="color: #0000ff;"> </span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->groups[<span style="color: #800080;">$group</span>]['ip']['allow'<span style="color: #000000;">])){ </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$this</span>->groups[<span style="color: #800080;">$group</span>]['ip']['allow'] <span style="color: #0000ff;">as</span> <span style="color: #800080;">$addr</span><span style="color: #000000;">){ </span><span style="color: #800080;">$pattern</span> = '/'.<span style="color: #008080;">str_replace</span>('*','d ',<span style="color: #008080;">str_replace</span>('.', '.', <span style="color: #800080;">$addr</span>)).'/'<span style="color: #000000;"> </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">preg_match</span>($pattern<span style="color: #800080;">, </span>$ip<span style="color: #800080;">) && !</span>empty<span style="color: #0000ff;">(</span>$addr<span style="color: #800080;"></span>)){ <span style="color: #000000;"></span>$pass<span style="color: #800080;"> = </span>true<span style="color: #0000ff;"></span>; <span style="color: #000000;"></span>break<span style="color: #0000ff;"></span>; } } } <span style="color: #000000;"></span>//<span style="color: #008000;"></span>許可される場合、一致を拒否します🎜> <span style="color: #008000;">if</span>(<span style="color: #0000ff;">$pass</span><span style="color: #800080;">){ </span><span style="color: #000000;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #0000ff;">$this</span> ->groups[<span style="color: #800080;">$group</span>]['ip']['deny'<span style="color: #800080;">])){ </span><span style="color: #000000;">foreach</span> (<span style="color: #0000ff;">$this</span>- >groups[<span style="color: #800080;">$group</span>]['ip']['deny'] <span style="color: #800080;">as</span> <span style="color: #0000ff;">$addr</span><span style="color: #800080;">){ </span><span style="color: #000000;">$ pattern</span> = '/'.<span style="color: #800080;">str_replace</span>('*','d ',<span style="color: #008080;">str_replace</span>('.', '.', <span style="color: #008080;">$addr</span>) ).'/'<span style="color: #800080;">; </span><span style="color: #000000;">if</span>(<span style="color: #0000ff;">preg_match</span>(<span style="color: #008080;">$pattern</span>, <span style="color: #800080;">$ip</span>) && ! <span style="color: #800080;">empty</span>(<span style="color: #0000ff;">$addr</span><span style="color: #800080;">)){ </span><span style="color: #000000;">$pass</span> = <span style="color: #800080;">false</span><span style="color: #0000ff;">; </span><span style="color: #000000;">; </span><span style="color: #0000ff;">; } } } }</span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['ip']['allow' <span style="color: #000000;">])){ </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['ip']['allow'] <span style="color: #0000ff;">as</span> <span style="color: #800080;">$addr</span><span style="color: #000000;">){ </span><span style="color: #800080;">$pattern</span> = '/'.<span style="color: #008080;">str_replace</span>('*','d ',<span style="color: #008080;">str_replace</span>('.', '.', <span style="color: #800080;">$addr</span>)).'/'<span style="color: #000000;">;                </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">preg_match</span>(<span style="color: #800080;">$pattern</span>, <span style="color: #800080;">$ip</span>) && !<span style="color: #0000ff;">空</span>(<span style="color: #800080;"> $addr</span><span style="color: #000000;">)){ </span><span style="color: #800080;">$pass</span> = <span style="color: #0000ff;">true</span><span style="color: #000000;">;                    </span><span style="color: #0000ff;">ブレイク</span><span style="color: #000000;">;                } } } </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$pass</span><span style="color: #000000;">){ </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$) this</span>->users[<span style="color: #800080;">$user</span>]['ip']['deny'<span style="color: #000000;">])){ </span><span style="color: #0000ff;">foreach</span> (<span style="color: #800080;">$this </span>->users[<span style="color: #800080;">$user</span>]['ip']['deny'] <span style="color: #0000ff;">as</span> <span style="color: #800080;">$addr</span><span style="color: #000000;">){ </span> <span style="color: #800080;">$pattern</span> = '/'.<span style="color: #008080;">str_replace</span>('*','d ',<span style="color: #008080;">str_replace</span>('.', '.', <span style="color: #800080;">$addr) </span>)).'/'<span style="color: #000000;">;                    </span><span style="color: #0000ff;">if</span>(<span style="color: #008080;">preg_match</span>(<span style="color: #800080;">$pattern</span>, <span style="color: #800080;">$ip</span>) && !<span style="color: #0000ff;">空</span>(<span style="color: #800080;"> $addr</span><span style="color: #000000;">)){ </span><span style="color: #800080;">$pass</span> = <span style="color: #0000ff;">false</span><span style="color: #000000;">;                        </span><span style="color: #0000ff;">ブレイク</span><span style="color: #000000;">;                    } } } } </span><span style="color: #0000ff;">echo</span> <span style="color: #008080;">date</span>('Y-m-d H:i:s')." [debug]tIP ACCESS:".' '.(<span style="color: #800080;">$pass</span>?'true':'false')."n"<span style="color: #000000;">;        </span><span style="color: #0000ff;">リターン</span> <span style="color: #800080;">$pass</span><span style="color: #000000;">;    } </span><span style="color: #008000;">/*</span><span style="color: #008000;">* * 获取用户主目录 * @param string $user * @return string </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> getHomeDir(<span style="color: #800080;">$user</span><span style="color: #000000;">){ </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$user</span><span style="color: #000000;">);        </span><span style="color: #800080;">$group</span> = <span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['グループ'<span style="color: #000000;">];        </span><span style="color: #800080;">$dir</span> = ''<span style="color: #000000;">;        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$group</span><span style="color: #000000;">){ </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">isset</span>(<span style="color: #800080;">$this->groups[</span>$group<span style="color: #800080;">]['home']))</span>$dir<span style="color: #800080;"> = </span>$this<span style="color: #800080;">->groups[</span>$group<span style="color: #800080;">]['ホーム'</span>];        }<span style="color: #800080;">$dir</span> = !<span style="color: #0000ff;">空</span>(<span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['home'])? <span style="color: #800080;">$this</span>->users[<span style="color: #800080;">$user</span>]['home']:<span style="color: #800080;">$dir</span><span style="color: #000000;">;        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$dir</span><span style="color: #000000;">;    } </span><span style="color: #008000;">//</span><span style="color: #008000;">文件权限界判断</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> isReadable(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$ path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getPathAccess(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$path</span>);        <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$result<span style="color: #800080;">['isExactMatch'</span>]){ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access '][0] == 'R'</span>;        }<span style="color: #000000;"></span>else<span style="color: #0000ff;"></span>{ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access'][0] == 'R' && </span> $result<span style="color: #800080;">['access'][9] == '私'</span>;        <span style="color: #000000;"></span>public<span style="color: #0000ff;"> </span>function<span style="color: #0000ff;"> isWritable(</span>$user<span style="color: #800080;">,</span>$path<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>$ result<span style="color: #800080;"> = </span>$this<span style="color: #800080;">->getPathAccess(</span>$user<span style="color: #800080;">, </span>$path<span style="color: #800080;"></span>);                <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$result<span style="color: #800080;">['isExactMatch'</span>]){ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access '][1] == 'W'</span>;        }<span style="color: #000000;"></span>else<span style="color: #0000ff;"></span>{ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access'][1] == 'W' && </span> $result<span style="color: #800080;">['access'][9] == '私'</span>;        <span style="color: #000000;"></span>public<span style="color: #0000ff;"> </span>function<span style="color: #0000ff;"> isAppendable(</span>$user<span style="color: #800080;">,</span>$path<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>$ result<span style="color: #800080;"> = </span>$this<span style="color: #800080;">->getPathAccess(</span>$user<span style="color: #800080;">, </span>$path<span style="color: #800080;"></span>);        <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$result<span style="color: #800080;">['isExactMatch'</span>]){ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access '][2] == 'A'</span>;        }<span style="color: #000000;"></span>else<span style="color: #0000ff;"></span>{ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access'][2] == 'A' && </span> $result<span style="color: #800080;">['access'][9] == '私'</span>;        <span style="color: #000000;"></span>public<span style="color: #0000ff;"> </span>function<span style="color: #0000ff;"> isRenamable(</span>$user<span style="color: #800080;">,</span>$path<span style="color: #800080;"></span>){ <span style="color: #000000;"></span>$ result<span style="color: #800080;"> = </span>$this<span style="color: #800080;">->getPathAccess(</span>$user<span style="color: #800080;">, </span>$path<span style="color: #800080;"></span>);        <span style="color: #000000;"></span>if<span style="color: #0000ff;">(</span>$result<span style="color: #800080;">['isExactMatch'</span>]){ <span style="color: #000000;"></span>return<span style="color: #0000ff;"> </span>$result<span style="color: #800080;">['access '][3] == 'N'</span>;        }<span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access'][3] == 'N' && <span style="color: #800080;">$ result</span>['access'][9] == 'I'<span style="color: #000000;">;        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> isDeletable(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$ result</span> = <span style="color: #800080;">$this</span>->getPathAccess(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$path</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$result</span>['isExactMatch'<span style="color: #000000;">]){ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access '][4] == 'D'<span style="color: #000000;">;        }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access'][4] == 'D' && <span style="color: #800080;"> $result</span>['access'][9] == '私'<span style="color: #000000;">;        } } </span><span style="color: #008000;">//</span><span style="color: #008000;">目录权限界判断</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> isFolderListable(<span style="color: #800080;">$user</span>,<span style="color: #800080;"> $path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getPathAccess(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$path</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$result</span>['isExactMatch'<span style="color: #000000;">]){ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access '][5] == 'L'<span style="color: #000000;">;        }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access'][5] == 'L' && <span style="color: #800080;"> $result</span>['access'][9] == '私'<span style="color: #000000;">;        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> isFolderCreatable(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$ result</span> = <span style="color: #800080;">$this</span>->getPathAccess(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$path</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$result</span>['isExactMatch'<span style="color: #000000;">]){ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access '][6] == 'C'<span style="color: #000000;">;        }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access'][6] == 'C' && <span style="color: #800080;"> $result</span>['access'][9] == '私'<span style="color: #000000;">;        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> isFolderRenamable(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$ result</span> = <span style="color: #800080;">$this</span>->getPathAccess(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$path</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$result</span>['isExactMatch'<span style="color: #000000;">]){ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access '][7] == 'N'<span style="color: #000000;">;        }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access'][7] == 'N' && <span style="color: #800080;"> $result</span>['access'][9] == '私'<span style="color: #000000;">;        } }</span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> isFolderDeletable(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$result</span> = <span style="color: #800080;">$this</span>->getPathAccess(<span style="color: #800080;">$user</span>, <span style="color: #800080;">$path</span><span style="color: #000000;">);        </span><span style="color: #0000ff;">if</span>(<span style="color: #800080;">$result</span>['isExactMatch'<span style="color: #000000;">]){ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access '][8] == 'D'<span style="color: #000000;">;        }</span><span style="color: #0000ff;">else</span><span style="color: #000000;">{ </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$result</span>['access'][8] == 'D' && <span style="color: #800080;"> $result</span>['access'][9] == '私'<span style="color: #000000;">;        } }</span><span style="color: #008000;">/*</span><span style="color: #008000;">* * ディレクトリのアクセス許可を取得* @param string $user * @param string $path * @return array * 最長パスのマッチングを実行* * Return: * array( * ' access '=>現在の権限*,'isExactMatch'=>完全一致かどうか* *); * 完全一致の場合は、継承を無視します。親ディレクトリ、*許可ビット テーブル: * - -- --- --- --- --- --- --- --- --- * 3 | | 5 | 6 | 8 | 9 |N |D |N | | * -------- ---------- ------- </span><span style="color: #008000;">*/</span> <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> getPathAccess(<span style="color: #800080;">$user</span>,<span style="color: #800080;">$path</span><span style="color: #000000;">){ </span><span style="color: #800080;">$this</span>-&gt ;<span style="color: #000000;">reload(); </span><span style="color: #800080;">$user</span> = <span style="color: #008080;">strto lower</span>(<span style="color: #800080;">$user</span><span style="color: #000000;">); 🎜> = </span>$this <span style="color: #800080;">->users[</span>$user<span style="color: #800080;">]['group'</span>]; <span style="color: #800080;"></span>//<span style="color: #000000;"></span>ファイルを削除name<span style="color: #008000;"> </span>$ path<span style="color: #008000;"> = </span>str_replace<span style="color: #800080;">(</span>substr<span style="color: #008080;">(</span>strrchr<span style="color: #008080;">(</span>$path<span style="color: #008080;">, '/') ,1),'',</span>$path<span style="color: #800080;"></span>); <span style="color: #800080;"></span>$access<span style="color: #000000;"> = self::AC(0</span>); isExactMatch<span style="color: #800080;"> = </span> false<span style="color: #000000;"></span> <span style="color: #800080;"></span>if<span style="color: #0000ff;">(</span>$group<span style="color: #000000;"></span>){ <span style="color: #0000ff;"></span>if<span style="color: #800080;">; (</span>isset<span style="color: #000000;"> (</span>$this<span style="color: #0000ff;">->groups[</span>$group<span style="color: #0000ff;">]['folder'</span>])){ <span style="color: #800080;"></span>foreach<span style="color: #800080;"> (</span>$this <span style="color: #000000;">->groups[</span>$group<span style="color: #0000ff;">]['folder'] </span>as<span style="color: #800080;"> </span>$f<span style="color: #800080;"></span>){ <span style="color: #0000ff;"></span>// <span style="color: #800080;"></span>中国語処理<span style="color: #000000;"> </span>$t_path<span style="color: #008000;"> = </span>iconv<span style="color: #008000;">('UTF-8','GB18030',</span>$ f<span style="color: #800080;">['パス' </span>]); <span style="color: #008080;"></span>if<span style="color: #800080;">(</span>strpos<span style="color: #000000;">(</span>$path<span style="color: #0000ff;">, </span>$t_path<span style="color: #008080;">) ) === 0</span> ){ <span style="color: #800080;"></span>$access<span style="color: #800080;"> = </span>$f<span style="color: #000000;">['access'</span>] <span style="color: #800080;"></span>$isExactMatch<span style="color: #800080;"> = (</span>$path<span style="color: #000000;"> == </span>$t_path<span style="color: #800080;">?</span>true<span style="color: #800080;">:</span>false<span style="color: #800080;"></span>); } } } } >if<span style="color: #0000ff;">(</span>isset<span style="color: #0000ff;">(</span>$this<span style="color: #000000;">->users[</span>$user<span style="color: #0000ff;">]['フォルダ'</span>])){ <span style="color: #0000ff;"> </span>foreach<span style="color: #800080;"> ( </span>$this<span style="color: #800080;">->users[</span>$user<span style="color: #000000;">]['folder'] </span>as<span style="color: #0000ff;"> </span>$f<span style="color: #800080;"> </span>){ <span style="color: #800080;"> </span>//<span style="color: #0000ff;"></span>中国語処理<span style="color: #800080;"> </span>$t_path<span style="color: #000000;"></span>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。