diff options
author | carlosg <carlosg> | 2004-09-14 12:29:21 +0000 |
---|---|---|
committer | carlosg <carlosg> | 2004-09-14 12:29:21 +0000 |
commit | ffae3defa96586346a1fe94aaf216f393dddf618 (patch) | |
tree | ba95ad3df6849fdef088c342fec63fd5379d0d18 | |
parent | b61d9a1b91eaf24803104e6868fa0bf84d357e62 (diff) |
2004-09-14 Carlos Garnacho Parro <carlosg@gnome.org>
* network-conf.in (xml_print_statichost): moved to network.pl.in
* network.pl.in (network_xml_print_statichost): added
* parse.pl.in: fixed a bug when searching in .ini like files, now
it stops at the end of the section
* share.pl.in, shares-conf.in: removed/comented unused code, made
it safe to store info in modern systems, added the get_network_conf
directive
* xml.pl.in: fixed a badly indented line
-rw-r--r-- | ChangeLog | 11 | ||||
-rwxr-xr-x | network-conf.in | 27 | ||||
-rw-r--r-- | network.pl.in | 23 | ||||
-rw-r--r-- | parse.pl.in | 18 | ||||
-rw-r--r-- | share.pl.in | 19 | ||||
-rwxr-xr-x | shares-conf.in | 169 | ||||
-rw-r--r-- | xml.pl.in | 2 |
7 files changed, 131 insertions, 138 deletions
@@ -1,5 +1,16 @@ 2004-09-14 Carlos Garnacho Parro <carlosg@gnome.org> + * network-conf.in (xml_print_statichost): moved to network.pl.in + * network.pl.in (network_xml_print_statichost): added + * parse.pl.in: fixed a bug when searching in .ini like files, now + it stops at the end of the section + * share.pl.in, shares-conf.in: removed/comented unused code, made + it safe to store info in modern systems, added the get_network_conf + directive + * xml.pl.in: fixed a badly indented line + +2004-09-14 Carlos Garnacho Parro <carlosg@gnome.org> + * shares-conf.in: made "/etc/exports" the default NFS exports file for all distros, this is pretty standard * share.pl.in, shares-conf.in: small fixes, made it work (at least diff --git a/network-conf.in b/network-conf.in index dcb503e..c9d5c15 100755 --- a/network-conf.in +++ b/network-conf.in @@ -242,29 +242,6 @@ sub xml_parse_profiledb # --- XML printing --- # -sub xml_print_statichost -{ - my ($h) = $_[0]; - my ($statichost, $i, $j, $val); - - &gst_xml_print_vspace (); - foreach $i (keys %{$$h{"statichost"}}) - { - $statichost = $ {$$h{"statichost"}}{$i}; - &gst_xml_print_line ("<statichost>\n"); - &gst_xml_enter (); - $val = &gst_xml_quote ($i); - &gst_xml_print_line ("<ip>$val</ip>\n"); - foreach $j (@$statichost) - { - $val = &gst_xml_quote ($j); - &gst_xml_print_line ("<alias>$val</alias>\n"); - } - &gst_xml_leave (); - &gst_xml_print_line ("</statichost>\n"); - } -} - sub xml_print_profiledb { my ($h) = @_; @@ -288,7 +265,7 @@ sub xml_print_profiledb #print profile contents &gst_xml_print_scalars ($i, @scalar_keys); &gst_xml_print_arrays ($i, @array_keys); - &xml_print_statichost ($i); + &network_xml_print_statichost ($i); &gst_xml_print_hash_hash ($$i{"interface"}, "interface"); &gst_xml_print_hash_hash ($$i{"dialing"}, "dialing"); @@ -316,7 +293,7 @@ sub xml_print &gst_xml_print_scalars ($h, @scalar_keys); &gst_xml_print_arrays ($h, @array_keys); - &xml_print_statichost ($h); + &network_xml_print_statichost ($h); &gst_xml_print_hash_hash ($$h{"interface"}, "interface"); &gst_xml_print_hash_hash ($$h{"dialing"}, "dialing"); diff --git a/network.pl.in b/network.pl.in index 2e3a265..09b1f12 100644 --- a/network.pl.in +++ b/network.pl.in @@ -42,6 +42,29 @@ require "$SCRIPTSDIR/service.pl$DOTIN"; require "$SCRIPTSDIR/util.pl$DOTIN"; require "$SCRIPTSDIR/xml.pl$DOTIN"; + +# Shared XML printing function +sub network_xml_print_statichost +{ + my ($h) = $_[0]; + my ($statichost, $i, $j, $val); + + &gst_xml_print_vspace (); + foreach $i (keys %{$$h{"statichost"}}) + { + $statichost = $ {$$h{"statichost"}}{$i}; + &gst_xml_container_enter ("statichost"); + $val = &gst_xml_quote ($i); + &gst_xml_print_pcdata ("ip", $val); + foreach $j (@$statichost) + { + $val = &gst_xml_quote ($j); + &gst_xml_print_pcdata ("alias", $val); + } + &gst_xml_container_leave ("statichost"); + } +} + sub gst_network_get_linux_wireless_ifaces { my ($fd, $line); diff --git a/parse.pl.in b/parse.pl.in index 11de5b6..a41ce3a 100644 --- a/parse.pl.in +++ b/parse.pl.in @@ -820,17 +820,25 @@ sub gst_parse_ini { $_ = $$line; next if (/^$/); + if (/\[$section\]/i) { - s/\[$section\][ \t]*//i; $found_section_flag = 1; + next; } - if ($found_section_flag && /^$var[ \t]*=/i) + if ($found_section_flag) { - s/^$var[ \t]*=[ \t]*//i; - $res = $_; - last; + if (/^$var[ \t]*=/i) + { + s/^$var[ \t]*=[ \t]*//i; + $res = $_; + last; + } + elsif (/\[\S+\]/i) + { + last; + } } } diff --git a/share.pl.in b/share.pl.in index 7d4f65b..7cf7b67 100644 --- a/share.pl.in +++ b/share.pl.in @@ -368,7 +368,7 @@ sub gst_share_parse_smb_conf for $section (@sections) { next if ($section =~ /^(global)|(homes)|(printers)$/); - next if (!&gst_parse_ini_bool ($smb_conf_name, $section, "printable")); + next if (&gst_parse_ini_bool ($smb_conf_name, $section, "printable")); my $sesi = &gst_share_smb_info_new (); my $point, $comment, $enabled, $browseable, $public, $writable, $printable; @@ -403,7 +403,7 @@ sub gst_share_parse_nfs_exports my (@sections, $table, $entries); my $point; - $table = gst_share_nfs_table_new (); + $table = &gst_share_nfs_table_new (); $entries = &gst_parse_split_hash_with_continuation ($nfs_exports_name, "[ \t]+", "[ \t]+"); @@ -452,7 +452,7 @@ sub gst_share_parse_nfs_exports sub gst_share_replace_smb_conf { my ($file, $table) = @_; - my (@sections); + my (@sections, $export); # Get the sections. @@ -735,35 +735,22 @@ sub gst_share_replace_nfs_exports # filename, table { my $old_info = &gst_share_nfs_table_find_info_equivalent ($old_table, $info); -# print "Looking for entry - "; if (!$old_info) { -# print "adding.\n"; &gst_share_nfs_exports_add_entry ($file, $info); } elsif ($old_info && !&gst_share_nfs_info_match_data ($old_info, $info)) { -# print "updating.\n"; &gst_share_nfs_exports_update_entry ($file, $info); } - else - { -# print "found.\n"; - } } for $old_info (@$old_table) { -# print "Looking for entry - "; if (!&gst_share_nfs_table_find_info_equivalent ($new_table, $old_info)) { -# print "removing.\n"; &gst_share_nfs_exports_remove_entry ($file, $old_info); } - else - { -# print "found.\n"; - } } } diff --git a/shares-conf.in b/shares-conf.in index e455217..73043c4 100755 --- a/shares-conf.in +++ b/shares-conf.in @@ -57,7 +57,6 @@ BEGIN { require "$SCRIPTSDIR/share.pl$DOTIN"; } - # --- Tool information --- # $name = "shares"; @@ -74,66 +73,12 @@ $version = "@VERSION@"; "pld-1.0", "pld-1.1", "pld-1.99", "conectiva-9", "conectiva-10", "slackware-9.1.0", "slackware-10.0.0", - "gentoo", "freebsd-4", "freebsd-5", "freebsd-6"); + "gentoo", "freebsd-5"); $description =<<"end_of_description;"; Configures network shares for import or export. end_of_description; -# --- Platform handling --- # - -$platmap = -{ - "redhat-5.2" => "redhat-6.2", - "redhat-6.0" => "redhat-6.2", - "redhat-6.1" => "redhat-6.2", - "redhat-6.2" => "redhat-6.2", - "redhat-7.0" => "redhat-7.0", - "redhat-7.1" => "redhat-7.0", - "redhat-7.2" => "redhat-7.0", - "openna-1.0" => "redhat-7.0", - "debian-2.2" => "redhat-7.0", - "debian-woody" => "redhat-7.0", - "mandrake-7.2" => "redhat-7.0", - "suse-7.0" => "redhat-6.2", - "freebsd-4" => "freebsd-4", - "freebsd-5" => "freebsd-4", - "freebsd-6" => "freebsd-4", - "turbolinux-7.0" => "redhat-7.0" -}; - -$filemap = -{ - "redhat-6.2" => - { - "fstab" => "/etc/fstab", - "mtab" => "/etc/mtab", - "exports" => "/etc/exports", - "smb.conf" => "/etc/smb.conf" - }, - - "redhat-7.0" => - { - "fstab" => "/etc/fstab", - "mtab" => "/etc/mtab", - "exports" => "/etc/exports", - "smb.conf" => "/etc/samba/smb.conf" - }, - - "freebsd-4" => - { - "fstab" => "/etc/fstab", - "exports" => "/etc/exports", - "smb.conf" => "/usr/local/etc/smb.conf" - } -}; - -sub distro_file -{ - my ($file) = @_; - return $$filemap{$$platmap{$gst_dist}}->{$file}; -} - # --- XML parsing --- # Scan XML from standard input to an internal tree. @@ -615,31 +560,40 @@ sub get_installed_tools return $tools; } -sub get_configured_imports -{ - my ($imports, $listed_imports, $mounted_imports); +#sub get_configured_imports +#{ +# my ($imports, $listed_imports, $mounted_imports); - $listed_imports = &gst_filesys_fstab_parse (&distro_file ("fstab")); - $mounted_imports = &gst_filesys_mtab_parse (&distro_file ("mtab")); +# $listed_imports = &gst_filesys_fstab_parse (&distro_file ("fstab")); +# $mounted_imports = &gst_filesys_mtab_parse (&distro_file ("mtab")); - &gst_filesys_table_set_permanent_true ($listed_imports); - &gst_filesys_table_set_mounted_true ($mounted_imports); +# &gst_filesys_table_set_permanent_true ($listed_imports); +# &gst_filesys_table_set_mounted_true ($mounted_imports); - $imports = &gst_filesys_table_merge_superset ($mounted_imports, $listed_imports); - return $imports; -} +# $imports = &gst_filesys_table_merge_superset ($mounted_imports, $listed_imports); +# return $imports; +#} -sub get_configured_exports +sub get_distro_files { - my ($smb_exports, $nfs_exports); - my (%dist_attrib, $smb_conf, $exports); - + my ($smb_comb, $exports); + %dist_attrib = &gst_network_get_parse_table (); $smb_conf = $dist_attrib{"fn"}{"SMB_CONF"}; # This is pretty standard $exports = "/etc/exports"; + return ($smb_conf, $exports); +} + +sub get_configured_exports +{ + my ($smb_exports, $nfs_exports); + my (%dist_attrib, $smb_conf, $exports); + + ($smb_conf, $exports) = &get_distro_files (); + $smb_exports = &gst_share_parse_smb_conf ($smb_conf); $nfs_exports = &gst_share_parse_nfs_exports ($exports); @@ -669,31 +623,36 @@ sub get sub set { my $config; - my ($fs, $fs_no_shares, $fs_new_shares); - my $imports; +# my ($fs, $fs_no_shares, $fs_new_shares); + my ($smb_conf, $exports); +# my $imports; + + ($smb_conf, $exports) = &get_distro_files (); $config = &xml_parse (); - $imports = $$config{"imports"}; - for $import (@$imports) - { - &gst_filesys_info_settings_to_options ($import); - } +# $imports = $$config{"imports"}; +# for $import (@$imports) +# { +# &gst_filesys_info_settings_to_options ($import); +# } - $fs = &gst_filesys_fstab_parse (&distro_file ("fstab")); - &gst_filesys_table_set_permanent_true ($fs); +# $fs = &gst_filesys_fstab_parse (&distro_file ("fstab")); +# &gst_filesys_table_set_permanent_true ($fs); - $fs_no_shares = &gst_filesys_table_dup ($fs); - &remove_shares_from_filesys_table ($fs_no_shares); +# $fs_no_shares = &gst_filesys_table_dup ($fs); +# &remove_shares_from_filesys_table ($fs_no_shares); - $fs_new_shares = &gst_filesys_table_merge_superset ($$config{"imports"}, $fs_no_shares); - $fs_new_shares = &gst_filesys_table_merge_subset ($fs_new_shares, $fs); +# $fs_new_shares = &gst_filesys_table_merge_superset ($$config{"imports"}, $fs_no_shares); +# $fs_new_shares = &gst_filesys_table_merge_subset ($fs_new_shares, $fs); - &gst_filesys_fstab_replace (&distro_file ("fstab"), $fs_new_shares); - &gst_share_replace_smb_conf (&distro_file ("smb.conf"), $$config{"smb_exports"}); - &gst_share_replace_nfs_exports (&distro_file ("exports"), $$config{"nfs_exports"}); +# &gst_filesys_fstab_replace (&distro_file ("fstab"), $fs_new_shares); - &gst_filesys_mount_sync_all (&distro_file ("fstab"), &distro_file ("mtab"), $$config{"imports"}); + &gst_share_replace_smb_conf ($smb_conf, $$config{"smb_exports"}); + &gst_share_replace_nfs_exports ($exports, $$config{"nfs_exports"}); + + +# &gst_filesys_mount_sync_all (&distro_file ("fstab"), &distro_file ("mtab"), $$config{"imports"}); &gst_report_end (); } @@ -716,16 +675,44 @@ sub scan &xml_print (\%config); } +sub get_network_conf +{ + my ($hash, $ifaces, $i, @arr); + + $ifaces = &gst_network_interfaces_get_info (); + + foreach $i (keys %$ifaces) + { + if (($$ifaces{$i}{"active"} == 1) + && ($$ifaces{$i}{"dev"} ne "lo")) + { + $$ifaces{$i}{"network"} = &gst_network_ipv4_calc_subnet ($$ifaces{$i}{"addr"}, + $$ifaces{$i}{"mask"}); + push @arr, $$ifaces{$i}; + } + } + + # network interface stuff + $hash = &gst_network_conf_get (); + &gst_report_end (); + + &gst_xml_print_begin ("network-conf"); + &network_xml_print_statichost ($hash); + &gst_xml_print_structure (\@arr, "interface"); + &gst_xml_print_end ("network-conf"); +} + # --- Main --- # # get, set and filter are special cases that don't need more parameters than a ref to their function. # Read general.pl.in:gst_run_directive to know about the format of this hash. $directives = { - "get" => [ \&get, [], "" ], - "set" => [ \&set, [], "" ], - "filter" => [ \&filter, [], "" ], - "scan_network" => [ \&scan, [], "Looks for smb or nfs shares in the network." ] + "get" => [ \&get, [], "" ], + "set" => [ \&set, [], "" ], + "filter" => [ \&filter, [], "" ], + "get_network_conf" => [ \&get_network_conf, [], "Gets the hosts info plus the interfaces networks." ], + "scan_network" => [ \&scan, [], "Looks for smb or nfs shares in the network." ] }; $tool = &gst_init ($name, $version, $description, $directives, @ARGV); @@ -269,7 +269,7 @@ sub gst_xml_print_structure { my ($x, $tag) = @_; - if (ref $x eq "ARRAY") { &gst_xml_print_array ($x, $tag); } + if (ref $x eq "ARRAY") { &gst_xml_print_array ($x, $tag); } elsif (ref $x eq "HASH") { &gst_xml_print_hash ($x, $tag); } else { |