############################################################################### # # ユーザ管理を行うアクションハンドラ # ############################################################################### package plugin::admin::AdminUserHandler; use strict; #============================================================================== # コンストラクタ #============================================================================== sub new { my $class = shift; my $self = {}; return bless $self,$class; } #============================================================================== # アクションハンドラメソッド #============================================================================== sub do_action { my $self = shift; my $wiki = shift; my $cgi = $wiki->get_CGI; $wiki->set_title("ユーザ管理"); if($cgi->param("delete") ne ""){ return $self->delete_user($wiki); } elsif($cgi->param("regist") ne ""){ return $self->user_form($wiki,{}); } elsif($cgi->param("update") ne ""){ my $users = &Util::load_config_hash($wiki,$wiki->config('userdat_file')); my $id = $cgi->param("update"); my ($pass,$type) = split(/\t/,$users->{$id}); return $self->user_form($wiki,{id=>$id,pass=>$pass,type=>$type}); } elsif($cgi->param("saveuser") ne ""){ return $self->save_user($wiki); } elsif($cgi->param("changepass") ne ""){ return $self->change_pass($wiki); } else { return $self->user_list($wiki); } } #============================================================================== # ユーザ一覧 #============================================================================== sub user_list { my $self = shift; my $wiki = shift; my $users = &Util::load_config_hash($wiki,$wiki->config('userdat_file')); my $buf .= "

ユーザ一覧

\n". "\n". "\n"; foreach my $id (sort(keys(%$users))){ my ($pass,$type) = split(/\t/,$users->{$id}); $buf .= "\n"; $buf .= " \n"; if($type==0){ $buf .= " \n"; } else { $buf .= " \n"; } $buf .= " \n"; $buf .= "\n"; } $buf .= "
ID種別操作
".&Util::escapeHTML($id)."管理者一般config('script_name')."?action=ADMINUSER&update=".&Util::url_encode($id)."\">変更 ". "config('script_name')."?action=ADMINUSER&delete=".&Util::url_encode($id)."\">削除
\n"; $buf .= "
config('script_name')."\" method=\"POST\">\n". " \n". " \n". "
\n"; return $buf; } #============================================================================== # ユーザ追加・更新フォーム #============================================================================== sub user_form { my $self = shift; my $wiki = shift; my $data = shift; my $buf = "
config('script_name')."\" method=\"POST\">\n"; if(defined($data->{id})){ $buf .= "

ユーザの変更

"; } else { $buf .= "

ユーザの追加

"; } $buf .= "

ID

\n"; if(defined($data->{id})){ $buf .= "

".&Util::escapeHTML($data->{id})."(変更はできません)

\n"; $buf .= "{id})."\">\n"; } else { $buf .= "

\n"; } if(!defined($data->{id})){ $buf .= "

パスワード

\n"; $buf .= "

\n"; } $buf .= "

種別

\n"; $buf .= "

\n"; $buf .= "{type}!=1){ $buf .= " checked"; } $buf .= ">\n"; $buf .= "{type}==1){ $buf .= " checked"; } $buf .= ">\n"; $buf .= "

\n"; if(defined($data->{id})){ $buf .= "\n"; } else { $buf .= "\n"; } $buf .= "\n"; $buf .= "
\n"; if(defined($data->{id})){ $buf .= "
config('script_name')."\" method=\"POST\">\n"; $buf .= "

パスワードの変更

\n"; $buf .= "

新しいパスワード

\n"; $buf .= "

\n"; $buf .= " \n"; $buf .= " \n"; $buf .= " {id})."\">\n"; $buf .= "
\n"; } $buf .= "[config('script_name')."?action=ADMINUSER\">戻る]\n"; return $buf; } #============================================================================== # ユーザ情報の保存 #============================================================================== sub save_user { my $self = shift; my $wiki = shift; my $cgi = $wiki->get_CGI; my $id = $cgi->param("id"); my $pass = $cgi->param("pass"); my $type = $cgi->param("type"); my $users = &Util::load_config_hash($wiki,$wiki->config('userdat_file')); if(!defined($users->{$id})){ if($id eq "" || $pass eq "" || $type eq ""){ return $wiki->error("ID、パスワード、ユーザ種別を指定してください。"); } } else { if($id eq "" || $type eq ""){ return $wiki->error("ID、ユーザ種別を指定してください。"); } } if(defined($users->{$id})){ ($pass) = split(/\t/,$users->{$id}); $users->{$id} = "$pass\t$type"; } else { $users->{$id} = &Util::md5($pass,$id)."\t$type"; } &Util::save_config_hash($wiki,$wiki->config('userdat_file'),$users); $wiki->redirectURL($wiki->config('script_name')."?action=ADMINUSER"); #return "

ユーザ情報を保存しました。

". # "[config('script_name')."?action=ADMINUSER\">戻る]\n"; } #============================================================================== # パスワードの変更 #============================================================================== sub change_pass { my $self = shift; my $wiki = shift; my $cgi = $wiki->get_CGI(); my $id = $cgi->param("id"); my $pass = $cgi->param("pass"); my $users = &Util::load_config_hash($wiki,$wiki->config('userdat_file')); my ($p,$type) = split(/\t/,$users->{$id}); $users->{$id} = &Util::md5($pass,$id)."\t$type"; &Util::save_config_hash($wiki,$wiki->config('userdat_file'),$users); $wiki->redirectURL($wiki->config('script_name')."?action=ADMINUSER"); #return "

パスワードを変更しました。

". # "[config('script_name')."?action=ADMINUSER\">戻る]\n"; } #============================================================================== # ユーザの削除 #============================================================================== sub delete_user { my $self = shift; my $wiki = shift; my $cgi = $wiki->get_CGI; my $id = $cgi->param("delete"); my $users = &Util::load_config_hash($wiki,$wiki->config('userdat_file')); my $saveusers = {}; foreach(sort(keys(%$users))){ if($_ ne $id){ $saveusers->{$_} = $users->{$_}; } } &Util::save_config_hash($wiki,$wiki->config('userdat_file'),$saveusers); $wiki->redirectURL($wiki->config('script_name')."?action=ADMINUSER"); #return "

ユーザを削除しました。

". # "[config('script_name')."?action=ADMINUSER\">戻る]\n"; } 1;