⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 proxyserver.pm

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 PM
📖 第 1 页 / 共 2 页
字号:
An array ref with a list of clients. Clients are hash refs, the attributesI<accept> (0 for denying access and 1 for permitting) and I<mask>, a Perlregular expression for the clients IP number or its host name.=item I<configfile> (B<--configfile=file>)Config files are assumed to return a single hash ref that overrides thearguments of the new method. However, command line arguments in turn takeprecedence over the config file. See the L<"CONFIGURATION FILE"> sectionbelow for details on the config file.=item I<debug> (B<--debug>)Turn debugging mode on. Mainly this asserts that logging messages oflevel "debug" are created.=item I<facility> (B<--facility=mode>)(UNIX only) Facility to use for L<Sys::Syslog>. The default isB<daemon>.=item I<group> (B<--group=gid>)After doing a bind(), change the real and effective GID to the given.This is usefull, if you want your server to bind to a privileged port(<1024), but don't want the server to execute as root. See alsothe --user option.GID's can be passed as group names or numeric values.=item I<localaddr> (B<--localaddr=ip>)By default a daemon is listening to any IP number that a machinehas. This attribute allows to restrict the server to the givenIP number.=item I<localport> (B<--localport=port>)This attribute sets the port on which the daemon is listening. Itmust be given somehow, as there's no default.=item I<logfile> (B<--logfile=file>)Be default logging messages will be written to the syslog (Unix) orto the event log (Windows NT). On other operating systems you need tospecify a log file. The special value "STDERR" forces logging tostderr. See L<Net::Daemon::Log> for details.=item I<mode> (B<--mode=modename>)The server can run in three different modes, depending on the environment.If you are running Perl 5.005 and did compile it for threads, then theserver will create a new thread for each connection. The thread willexecute the server's Run() method and then terminate. This mode is thedefault, you can force it with "--mode=threads".If threads are not available, but you have a working fork(), then theserver will behave similar by creating a new process for each connection.This mode will be used automatically in the absence of threads or ifyou use the "--mode=fork" option.Finally there's a single-connection mode: If the server has accepted aconnection, he will enter the Run() method. No other connections areaccepted until the Run() method returns (if the client disconnects).This operation mode is usefull if you have neither threads nor fork(),for example on the Macintosh. For debugging purposes you can force thismode with "--mode=single".=item I<pidfile> (B<--pidfile=file>)(UNIX only) If this option is present, a PID file will be created at thegiven location. Default is to not create a pidfile.=item I<user> (B<--user=uid>)After doing a bind(), change the real and effective UID to the given.This is usefull, if you want your server to bind to a privileged port(<1024), but don't want the server to execute as root. See alsothe --group and the --chroot options.UID's can be passed as group names or numeric values.=item I<version> (B<--version>)Supresses startup of the server; instead the version string willbe printed and the program exits immediately.=back=head1 CONFIGURATION FILEThe configuration file is just that of I<RPC::PlServer> or I<Net::Daemon>with some additional attributes in the client list.The config file is a Perl script. At the top of the file you may includearbitraty Perl source, for example load drivers at the start (usefullto enhance performance), prepare a chroot environment and so on.The important thing is that you finally return a hash ref of optionname/value pairs. The possible options are listed above.All possibilities of Net::Daemon and RPC::PlServer apply, in particular=over 4=item Host and/or User dependent access control=item Host and/or User dependent encryption=item Changing UID and/or GID after binding to the port=item Running in a chroot() environment=backAdditionally the server offers you query restrictions. Suggest thefollowing client list:    'clients' => [	{ 'mask' => '^admin\.company\.com$',          'accept' => 1,          'users' => [ 'root', 'wwwrun' ],        },        {	  'mask' => '^admin\.company\.com$',          'accept' => 1,          'users' => [ 'root', 'wwwrun' ],          'sql' => {               'select' => 'SELECT * FROM foo',               'insert' => 'INSERT INTO foo VALUES (?, ?, ?)'               }        }then only the users root and wwwrun may connect from admin.company.com,executing arbitrary queries, but only wwwrun may connect from otherhosts and is restricted to    $sth->prepare("select");or    $sth->prepare("insert");which in fact are "SELECT * FROM foo" or "INSERT INTO foo VALUES (?, ?, ?)".=head1 Proxyserver Configuration file (bigger example)This section tells you how to restrict a DBI-Proxy: Not every user fromevery workstation shall be able to execute every query.There is a perl program "dbiproxy" which runs on a machine which is ableto connect to all the databases we wish to reach. All Perl-DBD-drivers mustbe installed on this machine. You can also reach databases for which drivers are not available on the machine where you run the programm querying the database, e.g. ask MS-Access-database from Linux.Create a configuration file "proxy_oracle.cfg" at the dbproxy-server:    {	# This shall run in a shell or a DOS-window 	# facility => 'daemon',	pidfile => 'your_dbiproxy.pid',	logfile => 1,	debug => 0,	mode => 'single',	localport => '12400',	# Access control, the first match in this list wins!	# So the order is important	clients => [		# hint to organize:		# the most specialized rules for single machines/users are 1st		# then the denying rules		# the the rules about whole networks		# rule: internal_webserver		# desc: to get statistical information		{			# this IP-address only is meant			mask => '^10\.95\.81\.243$',			# accept (not defer) connections like this			accept => 1,			# only users from this list 			# are allowed to log on			users => [ 'informationdesk' ],			# only this statistical query is allowed			# to get results for a web-query			sql => {				alive => 'select count(*) from dual',				statistic_area => 'select count(*) from e01admin.e01e203 where geb_bezei like ?',			}		},		# rule: internal_bad_guy_1		{			mask => '^10\.95\.81\.1$',			accept => 0,		},		# rule: employee_workplace		# desc: get detailled informations		{			# any IP-address is meant here			mask => '^10\.95\.81\.(\d+)$',			# accept (not defer) connections like this			accept => 1,			# only users from this list 			# are allowed to log on			users => [ 'informationdesk', 'lippmann' ],			# all these queries are allowed:			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 ?',			}		},		# rule: internal_bad_guy_2 		# This does NOT work, because rule "employee_workplace" hits		# with its ip-address-mask of the whole network		{			# don't accept connection from this ip-address			mask => '^10\.95\.81\.5$',			accept => 0,		}	]    }Start the proxyserver like this:	rem well-set Oracle_home needed for Oracle	set ORACLE_HOME=d:\oracle\ora81	dbiproxy --configfile proxy_oracle.cfg=head2 Testing the connection from a remote machineCall a programm "dbish" from your commandline. I take the machine from rule "internal_webserver"	dbish "dbi:Proxy:hostname=oracle.zdf;port=12400;dsn=dbi:Oracle:e01" informationdesk xxxThere will be a shell-prompt:	informationdesk@dbi...> alive	Current statement buffer (enter '/'...):	alive	informationdesk@dbi...> /	COUNT(*)	'1'	[1 rows of 1 fields returned]=head2 Testing the connection with a perl-scriptCreate a perl-script like this:	# file: oratest.pl	# call me like this: perl oratest.pl user password	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);	my $sql = "search_area";	printf "%s\n%s\n%s\n", "="x40, $sql, "="x40;	my $cur = $dbh->prepare($sql);	$cur->bind_param(1,'Pfarr%');	$cur->bind_param(2,'Bronnamberg%');	&show_result ($cur);	my $sql = "statistic_area";	printf "%s\n%s\n%s\n", "="x40, $sql, "="x40;	my $cur = $dbh->prepare($sql);	$cur->bind_param(1,'Pfarr%');	&show_result ($cur);	$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;	}The result	C:\>perl oratest.pl informationdesk xxx	========================================	search_city	========================================	Row is: 3322, 9050, Chemnitz	Row is: 3678, 9051, Chemnitz	Row is: 10447, 9051, Chemnitz	Row is: 12128, 9051, Chemnitz	Row is: 10954, 90513, Zirndorf	Row is: 5808, 90513, Zirndorf	Row is: 5715, 90513, Zirndorf	... and so on	========================================	search_area	========================================	Row is: 101, Bronnamberg	Row is: 400, Pfarramt Zirndorf	Row is: 400, Pfarramt Rosstal	Row is: 400, Pfarramt Oberasbach	Row is: 401, Pfarramt Zirndorf	Row is: 401, Pfarramt Rosstal	========================================	statistic_area	========================================	DBD::Proxy::st execute failed: Server returned error: Failed to execute method CallMethod: Unknown SQL query: statistic_area at E:/Perl/site/lib/DBI/ProxyServer.pm line 258.	Could not execute=head2 How the configuration worksThe most important section to control access to your dbi-proxy is "client=>"in the file "proxy_oracle.cfg":Controlling which person at which machine is allowed to access=over 4=item * "mask" is a perl regular expression against the plain ip-address of the machine which wishes to connect _or_ the reverse-lookup from a nameserver.=item * "accept" tells the dbiproxy-server wether ip-adresse like in "mask" are allowed to connect or not (0/1)=item * "users" is a reference to a list of usernames which must be matched, this is NOT a regular expression.=backControlling which SQL-statements are allowedYou can put every SQL-statement you like in simply ommiting "sql => ...", but the more important thing is to restrict the connection so that only allowed queries are possible.If you include an sql-section in your config-file like this:	sql => {		alive => 'select count(*) from dual',		statistic_area => 'select count(*) from e01admin.e01e203 where geb_bezei like ?',	}The user is allowed to put two queries against the dbi-proxy. The queries are _not_ "select count(*)...", the queries are "alive" and "statistic_area"! These keywords are replaced by the real query. So you can run a query for "alive":	my $sql = "alive";	my $cur = $dbh->prepare($sql);	...The flexibility is that you can put parameters in the where-part of the query so the query are not static. Simply replace a value in the where-part of the query through a question mark and bind it as a parameter to the query. 	my $sql = "statistic_area";	my $cur = $dbh->prepare($sql);	$cur->bind_param(1,'905%');	# A second parameter would be called like this:	# $cur->bind_param(2,'98%');The result is this query:	select count(*) from e01admin.e01e203 	where geb_bezei like '905%'Don't try to put parameters into the sql-query like this:	# Does not work like you think.	# Only the first word of the query is parsed,	# so it's changed to "statistic_area", the rest is omitted.	# You _have_ to work with $cur->bind_param.	my $sql = "statistic_area 905%";	my $cur = $dbh->prepare($sql);	...=head2 Problems=over 4=item * I don't know how to restrict users to special databases.=item * I don't know how to pass query-parameters via dbish=back=head1 AUTHOR    Copyright (c) 1997    Jochen Wiedmann                          Am Eisteich 9                          72555 Metzingen                          Germany                          Email: joe@ispsoft.de                          Phone: +49 7123 14881The DBI::ProxyServer module is free software; you can redistribute itand/or modify it under the same terms as Perl itself. In particularpermission is granted to Tim Bunce for distributing this as a part ofthe DBI.=head1 SEE ALSOL<dbiproxy>, L<DBD::Proxy>, L<DBI>, L<RPC::PlServer>,L<RPC::PlClient>, L<Net::Daemon>, L<Net::Daemon::Log>,L<Sys::Syslog>, L<Win32::EventLog>, L<syslog>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -