#!/usr/local/bin/perl # # $Id: ldap.cgi,v 1.6 2007/02/04 20:25:10 syzdek Exp $ # # CGI System Tools # Copyright (C) 2007 David M. Syzdek # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # advanced-fs.cgi - CGI shell script for exploring a system # # +-=-=-=-=-=-+ # | | # | Headers | # | | # +-=-=-=-=-=-+ use 5.008; use Net::LDAP; use strict; our $PROGRAM_NAME = 'ldap.cgi'; our $VERSION = '0.01'; our $DESCRIPTION = 'simple LDAP browser'; our $AUTHOR = 'David Syzdek "syzdek@gmail.com"'; # +-=-=-=-=-=-=-=+ # | | # | Prototypes | # | | # +-=-=-=-=-=-=-=+ sub form_settings(%); # displays config settings sub form_parse($); # parses form data sub main(@); # main statement # +-=-=-=-=-=-=-+ # | | # | Functions | # | | # +-=-=-=-=-=-=-+ # parses form data sub form_parse($) { # grabs passed args my $query_string = shift; # declares local vars my $buff; my $pair; my $name; my $value; my @pairs; my %data; # parses linked data if ($ENV{'QUERY_STRING'}) { $buff = $ENV{'QUERY_STRING'}; @pairs = split(/&/, $buff); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($value =~ /^([\.\w]+)$/) { $data{$name} = $1; }; }; }; # clears fields $data{'proto'} = ''; $data{'host'} = ''; $data{'port'} = ''; # detaints data if ($data{'ldapurl'}) { #if ($data{'ldapurl'} =~ /^([\w]+):\/\/([-\w\.]*)(:[\d]+){0,1}\//) #([-\w\.,= ]*)?([-\w,]*)?([\w]+)/) #{ if ($data{'ldapurl'} =~ /^([\w]+):\/\//) { $data{'proto'} = $1; $data{'host'} = $2; $data{'port'} = $3; $data{'basedn'} = $4; $data{'attrs'} = $4; $data{'scope'} = $5; }; } else { $data{'ldapurl'} = 'ldap://localhost/ou=People,o=foo,o=org?uid,cn,gn,sn?one?(uid=jdoe)?'; $data{'proto'} = 'ldap'; $data{'host'} = 'localhost'; $data{'port'} = '389'; $data{'basedn'} = 'ou=People,o=foo,o=org'; $data{'attrs'} = 'uid,gn,sn,cn'; $data{'scope'} = 'one'; }; # ends function return(%data); }; # displays config settings sub form_settings(%) { # grabs passed args my %data = @_; # declares local vars # prints form printf("
\n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n", $data{'ldapurl'}); printf(" \n"); printf("
LDAP URL:  
\n"); printf("
\n"); printf("
\n"); printf(" \n"); printf(" \n"); printf(" \n"); printf(" \n"); printf("
\n"); printf("
\n");
printf("protocol: %s\n", $data{'proto'});
printf("host: %s\n", $data{'host'});
printf("port: %s\n", $data{'port'});
printf("basedn: %s\n", $data{'basedn'});
printf("attrs: %s\n", $data{'attrs'});
printf("scope: %s\n", $data{'scope'});
printf("             
\n"); printf("
\n"); printf("
\n"); # ends function return(0); }; # +-=-=-=-=-=-=-=-=-+ # | | # | Main Section | # | | # +-=-=-=-=-=-=-=-=-+ sub main(@) { # grabs passed args my @argv = @_; # declares local vars my %data; # display headers printf("Content-type: text/html\n\n"); # parses settings %data = form_parse($ENV{'QUERY_STRING'}); # prints settings form printf("
\n"); printf("
\n"); # ends function return(0); }; exit(main(@ARGV)); # end of script