# man > DBI::ProxyServer

---
type: CommandReference
command: DBI::ProxyServer
mode: perldoc
section: "3pm"
source: perldoc
---

## Quick Reference

- `dbiproxy --configfile=proxy.cfg` — start the proxy server with a config file
- `dbiproxy --localport=12400 --mode=single` — start server on port 12400 in single mode
- `dbiproxy --version` — print version string and exit
- `DBI->connect("dbi:Proxy:hostname=host;port=12400;dsn=dbi:Oracle:e01", $user, $pass)` — connect from client
- `$dbh->prepare("query_name")` — prepare a restricted query defined in config
- `$cur->bind_param(1, 'value')` — bind parameter to placeholder
- `$cur->execute()` — execute the restricted query
- `dbish "dbi:Proxy:hostname=host;port=12400;dsn=dbi:Oracle:e01" user pass` — test connection with DBI::Shell

## Name

DBI::ProxyServer — a server for the DBD::Proxy driver

## Synopsis

perl
use DBI::ProxyServer;
DBI::ProxyServer::main(@ARGV);
## Options

Options are parsed by Getopt::Long and can be passed via command line or config file. Inherits all options from RPC::PlServer and Net::Daemon.

- `--chroot=dir` — (UNIX) change root directory after bind() for security
- `--clients` — array ref of client hash refs with `accept` (0/1) and `mask` (regex for IP/host)
- `--configfile=file` — config file returning a hash ref; command line overrides config
- `--debug` — enable debug logging
- `--facility=mode` — (UNIX) syslog facility (default: daemon)
- `--group=gid` — (UNIX) change group ID after bind()
- `--localaddr=ip` — listen only on given IP address
- `--localport=port` — port to listen on (required)
- `--logfile=file` — log file (default: syslog on UNIX, event log on Windows); use "STDERR" for stderr
- `--mode=modename` — operation mode: `threads` (default if threads available), `fork`, or `single`
- `--pidfile=file` — (UNIX) create PID file at given path
- `--user=uid` — (UNIX) change user ID after bind()
- `--version` — print version and exit

## Examples

### Configuration file (proxy_oracle.cfg)

perl
{
    pidfile => 'your_dbiproxy.pid',
    logfile => 1,
    debug => 0,
    mode => 'single',
    localport => '12400',
    clients => [
        # Allow specific IP with restricted queries
        {
            mask => '^10\.95\.81\.243$',
            accept => 1,
            users => [ 'informationdesk' ],
            sql => {
                alive => 'select count(*) from dual',
                statistic_area => 'select count(*) from e01admin.e01e203 where geb_bezei like ?',
            }
        },
        # Deny specific IP
        {
            mask => '^10\.95\.81\.1$',
            accept => 0,
        },
        # Allow network range with more queries
        {
            mask => '^10\.95\.81\.(\d+)$',
            accept => 1,
            users => [ 'informationdesk', 'lippmann' ],
            sql => {
                search_city => 'select ort_nr, plz, ort from e01admin.e01e200 where plz like ?',
                search_area => 'select gebiettyp, geb_bezei from e01admin.e01e203 where geb_bezei like ? or geb_bezei like ?',
            }
        },
    ]
}
### Start the proxy server

shell
dbiproxy --configfile proxy_oracle.cfg
### Test with dbish

shell
dbish "dbi:Proxy:hostname=oracle.zdf;port=12400;dsn=dbi:Oracle:e01" informationdesk xxx
### Perl client script

perl
use strict;
use DBI;

my $user = shift || die "Usage: $0 user password";
my $pass = shift || die "Usage: $0 user password";
my $config = {
    dsn_at_proxy => "dbi:Oracle:e01",
    proxy => "hostname=oechsle.zdf;port=12400",
};
my $dsn = sprintf "dbi:Proxy:%s;dsn=%s",
    $config->{proxy},
    $config->{dsn_at_proxy};

my $dbh = DBI->connect( $dsn, $user, $pass )
    || die "connect did not work: $DBI::errstr";

my $sql = "search_city";
printf "%s\n%s\n%s\n", "="x40, $sql, "="x40;
my $cur = $dbh->prepare($sql);
$cur->bind_param(1,'905%');
&show_result ($cur);

# ... more queries ...

$dbh->disconnect;
exit;

sub show_result {
    my $cur = shift;
    unless ($cur->execute()) {
        print "Could not execute\n";
        return;
    }
    my $rownum = 0;
    while (my @row = $cur->fetchrow_array()) {
        printf "Row is: %s\n", join(", ",@row);
        if ($rownum++ > 5) {
            print "... and so on\n";
            last;
        }
    }
    $cur->finish;
}
## See Also

- [dbiproxy](https://metacpan.org/pod/dbiproxy)
- [DBD::Proxy](https://metacpan.org/pod/DBD::Proxy)
- [DBI](https://metacpan.org/pod/DBI)
- [RPC::PlServer](https://metacpan.org/pod/RPC::PlServer)
- [RPC::PlClient](https://metacpan.org/pod/RPC::PlClient)
- [Net::Daemon](https://metacpan.org/pod/Net::Daemon)
- [Net::Daemon::Log](https://metacpan.org/pod/Net::Daemon::Log)
- [Sys::Syslog](https://metacpan.org/pod/Sys::Syslog)
- [Win32::EventLog](https://metacpan.org/pod/Win32::EventLog)

## Security Warning

RPC::PlServer used underneath is not secure due to serializing and deserializing data with Storable. Use the proxy driver only in trusted environments.