#!/usr/bin/ruby -Ku require 'rubygems' require 'net/ldap' require 'cgi' $host = "" $port = "389" $domain = "" def ldap_login(name, pass) flg = false if pass != "" then #オブジェクト生成 net_ldap = Net::LDAP.new( :host => $host, :port => $port, :auth => { :method => :simple, :username => "#{name}@#{$domain}", :password => pass } ) #認証 flg = net_ldap.bind end return flg end $cgi = CGI.new() $_POST = {} if $cgi.request_method == "POST" then $cgi.params.each {|key, val| $_POST[key] = val.to_s case key when "host" $host = val.to_s when "port" $port = val.to_s when "domain" $domain = val.to_s end } end msg = "ユーザー名とパスワードを入力してください。" if $_POST.has_key?('user') then msg = ldap_login($_POST["user"], $_POST["pass"]) ? "ログイン成功!" : "ログイン失敗!!" end html = < AD認証テスト やり直し

AD認証テスト

初期設定

HOST
PORT
DOMAIN

#{msg}

USER
PASS
 
EOF print $cgi.header() print html