summaryrefslogtreecommitdiffstats
path: root/client_wizard
diff options
context:
space:
mode:
Diffstat (limited to 'client_wizard')
-rw-r--r--client_wizard/.perl_checker1
-rwxr-xr-xclient_wizard/Bind_client.pm191
-rw-r--r--client_wizard/Makefile8
-rwxr-xr-xclient_wizard/scripts/test_client.sh93
4 files changed, 293 insertions, 0 deletions
diff --git a/client_wizard/.perl_checker b/client_wizard/.perl_checker
new file mode 100644
index 00000000..725f44b4
--- /dev/null
+++ b/client_wizard/.perl_checker
@@ -0,0 +1 @@
+Basedir .. \ No newline at end of file
diff --git a/client_wizard/Bind_client.pm b/client_wizard/Bind_client.pm
new file mode 100755
index 00000000..396260e2
--- /dev/null
+++ b/client_wizard/Bind_client.pm
@@ -0,0 +1,191 @@
+#!/usr/bin/perl
+
+# Drakwizard
+
+# Copyright (C) 2002,2003 Mandrakesoft
+#
+# Authors: Arnaud Desmons <adesmons@mandrakesoft.com>
+# Florent Villard <warly@mandrakesoft.com>
+#
+# 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, 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.
+
+package MDK::Wizard::Bind_client;
+use lib qw(/usr/lib/libDrakX);
+use strict;
+
+use common;
+use services;
+use MDK::Wizard::Varspaceval;
+use MDK::Wizard::Wizcommon;
+
+my $wiz = new MDK::Wizard::Wizcommon;
+my $wiz_ip_server = $wiz->{net}->itf_get("IPADDR");
+my $wiz_domain_name = $wiz->{net}->network_get("DOMAINNAME");
+
+my $o = {
+ name => N("DNS Client Wizard"),
+ var => {
+ client_ip => '',
+ client_name => ''
+ },
+ needed_rpm => [],
+ defaultimage => "$ENV{__WIZ_HOME__}client_wizard/images/DNS.png",
+ init => sub {
+ if (! -f "/var/named/$wiz_domain_name.db") {
+ return (0, N("You must first run the DNS server wizard"))
+ }
+ 1
+ }
+ };
+
+$o->{pages} = {
+ welcome => {
+ name => N("DNS Client Wizard") . "\n\n" . N("A client of your local network is a machine connected to the network having its own name and IP address.") . "\n\n" . N("This wizard will help you in adding a new client in your local DNS.") . "\n\n" . N("The server will use the information you enter here to make the name of the client available to other machines into your network.") . "\n\n" . N("Press next to begin, or Cancel to leave this wizard."),
+ post => sub { $wiz->check_dhcp },
+ no_back => 1,
+ next => 'client_id'
+ },
+ client_id => {
+ name => N("Client identification:") . "\n\n" . N("Your client on the network will be identified by name, as in clientname.company.net. Every machine on the network must have a (unique) IP address, in the usual dotted syntax.") . "\n\n" . N("(you don't need to type the domain after the name)") . "\n\n" . N("Note that the given IP address and client name should be unique in the network."),
+ pre => sub {
+ $o->{var}{client_ip} = ip();
+ $o->{var}{client_name} = name();
+ },
+ data => [
+ { label => N("Name of the machine:"), val => \$o->{var}{client_name} },
+ { label => N("IP address of the machine:"), val => \$o->{var}{client_ip} },
+ ],
+ next => 'summary'
+ },
+ dhcp_warning => {
+ name => N("Warning") . "\n\n" . N("You are in dhcp, server may not work with your configuration."),
+ ignore => 1,
+ next => 'client_id'
+ },
+ system_error => {
+ name => N("Error") . "\n\n" . N("System error, no configuration done"),
+ ignore => 1,
+ next => 'client_id'
+ },
+ error => {
+ name => N("Error") . "\n\n" . N("This is not a valid address... press next to continue"),
+ ignore => 1,
+ next => 'client_id'
+ },
+ summary => {
+ name => N("Adding a new client to your network") . "\n\n" . N("The wizard collected the following parameters needed to add a client to your network:") . "\n\n" . N("To accept these values, and add your client, click the Next button or use the Back button to correct them."),
+ data => [
+ { label => N("Client name"), fixed_val => \$o->{var}{client_name} },
+ { label => N("Client IP:"), fixed_val => \$o->{var}{client_ip} },
+ ],
+ post => \&do_it,
+ next => 'end'
+ },
+ end => {
+ name => N("Congratulations") . "\n\n" . N("The wizard successfully added the client."),
+ end => 1,
+ },
+};
+
+sub check_dhcp {
+ $wiz->{net}->is_dhcp and return 'dhcp_warning';
+}
+
+sub name {
+ $wiz->{net}->network_get("HOSTNAME");
+}
+
+sub ip {
+ $wiz_ip_server;
+}
+
+sub get_root {
+ my $file = "/etc/sysconfig/named";
+ if (-f $file) {
+ my %mdk = MDK::Wizard::Varspaceval->get($file);
+ return $mdk{ROOTDIR};
+ }
+ "";
+}
+
+sub up_serial {
+ my ($file) = @_;
+
+ my (undef, undef, undef, $mday, $mon, $year) = gmtime(time());
+ $year += 1900;
+ my $serial_nbm = sprintf "%4dY%2dm%2d00", $year, $mon, $mday;
+ output($file, map {
+ my $line = $_;
+ if (/^(\s*)(\d*)(\s*;\s*Serial.*)$/) {
+ my $serial_f = $2;
+ $serial_f++;
+ if ($serial_f <= $serial_nbm) {
+ $serial_f = $serial_nbm;
+ chomp($serial_f);
+ $line = "$1$serial_f$3\n";
+ }
+ }
+ $line;
+ } cat_($file));
+}
+
+sub test {
+ !$o->{client_name} and return 'error';
+ !$o->{client_ip} and return 'error';
+ my $s_trunc = "$1.$2.$3" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $ds = $4 if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $dc = $4 if $o->{var}{client_ip} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $sc_trunc = "$1.$2.$3" if $o->{var}{client_ip} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ (!$sc_trunc || !$dc || !$ds || !$s_trunc || $s_trunc != $sc_trunc || ($dc == $ds || $dc < 0 || $dc > 255)) and return 'error';
+}
+
+sub do_it {
+ $::testing and return;
+ my $date = `date`;
+ chomp($date);
+ #my $wiz_ip_net = "$1.$2.$3.0" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $s_trunc = "$1.$2.$3" if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ #my $ds = $4 if $wiz_ip_server =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+ my $dc = $4 if $o->{var}{client_ip} =~ /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
+
+ my $file="/var/named/$wiz_domain_name.db";
+ my $client_name = $o->{var}{client_name};
+ $client_name =~ s/\.$wiz_domain_name$//;
+ MDK::Common::cp_af($file, $file.".orig");
+ local *NEW;
+ open(NEW, ">> $file") or die "can not open $file";
+ print NEW "\n$client_name IN A $o->{var}{client_ip} ; $date\n\n";
+ close(NEW) or die "can not close $file";
+ up_serial($file);
+
+ $file="/var/named/$s_trunc.rev";
+ MDK::Common::cp_af($file, $file.".orig");
+ open(NEW, ">> $file") or die "can not open $file";
+ print NEW "\n$dc IN PTR $o->{var}{client_name}. ; $date\n\n";
+ close(NEW) or die "can not close $file";
+ up_serial($file);
+ if (services::is_service_running('named')) {
+ services::restart('named')
+ } else {
+ services::start('named')
+ }
+}
+
+sub new {
+ my ($class) = @_;
+ bless $o, $class;
+}
+
+1;
diff --git a/client_wizard/Makefile b/client_wizard/Makefile
new file mode 100644
index 00000000..bf0d1746
--- /dev/null
+++ b/client_wizard/Makefile
@@ -0,0 +1,8 @@
+install2:
+ su -c 'make install'
+
+install:
+ mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/share/wizards/client_wizard/images
+ mkdir -p --mode=u=rwx,g=rx,o=rx ${prefix}/$(PERL_VENDORLIB)/MDK/Wizard
+ install --mode=u=rw,g=r,o=r -p *.pm ${prefix}/$(PERL_VENDORLIB)/MDK/Wizard/
+ install --mode=a=r -p ./images/*.png ${prefix}/share/wizards/client_wizard/images
diff --git a/client_wizard/scripts/test_client.sh b/client_wizard/scripts/test_client.sh
new file mode 100755
index 00000000..6a73e96d
--- /dev/null
+++ b/client_wizard/scripts/test_client.sh
@@ -0,0 +1,93 @@
+#!/bin/bash
+#
+# Wizard
+#
+# Copyright (C) 2000 Mandrakesoft.
+#
+# 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.
+# See file LICENSE for further informations on licensing terms.
+#
+# 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.
+#
+# Authors: Jerome Dumonteil, Maurizio De Cecco, Enzo Maggi
+# icons: Helene Durosini <ln@mandrakesoft.com>
+# <corporate@mandrakesoft.com> http://www.mandrakesoft.com
+
+echo_debug "in $0"
+
+wiz_ip_net=`get_var wiz_ip_net`
+wiz_ip_server=`get_var wiz_ip_server`
+wiz_domain_name=`get_var wiz_domain_name`
+s_trunc=${wiz_ip_net%.*}
+ds=${wiz_ip_server##*.}
+sc_trunc=${wiz_client_ip%.*}
+dc=${wiz_client_ip##*.}
+
+wiz_client_name=${wiz_client_name%%.*}
+
+if [ -z "${wiz_client_name}" ]; then
+ echo_debug "incorrect name"
+ exit 1
+fi
+
+if [ -z "${wiz_client_ip}" ]; then
+ echo_debug "incorrect address"
+ exit 1
+fi
+
+if [ -z "${sc_trunc}" ]; then
+ echo_debug "incorrect address"
+ exit 1
+fi
+if [ -z "${dc}" ]; then
+ echo_debug "incorrect address"
+ exit 1
+fi
+
+if [ "${s_trunc}" != "${sc_trunc}" ]; then
+ echo_debug "range not in network"
+ exit 1
+fi
+
+if [ "${dc}" = "${ds}" -o ${dc} -le 0 -o ${dc} -gt 255 ]; then
+ echo_debug "bad ip"
+ exit 1
+fi
+
+
+file="/var/named/${wiz_domain_name}.db"
+t=`grep -E "^${wiz_client_name}[[:space:]]*IN" ${file}`
+if [ -n "$t" ]; then
+ echo_debug "${wiz_client_name} got in ${file}"
+ exit 2
+fi
+t=`grep -E "^[^;]*A[[:space:]]*${wiz_client_ip}" ${file}`
+if [ -n "$t" ]; then
+ echo_debug "${wiz_client_ip} got in ${file}"
+ exit 2
+fi
+
+file="/var/named/${s_trunc}.rev"
+t=`grep -E "^${dc}[[:space:]]*IN" ${file}`
+if [ -n "$t" ]; then
+ echo_debug "${dc} got in ${file}"
+ exit 2
+fi
+t=`grep -E "^[^;]*PTR[[:space:]]*${wiz_client_name}" ${file}`
+if [ -n "$t" ]; then
+ echo_debug "${wiz_client_name} got in ${file}"
+ exit 2
+fi
+
+# all seems to be ok
+exit 10