More work on new package system
authorJamie Cameron <jcameron@webmin.com>
Fri, 27 Feb 2009 02:14:27 +0000 (02:14 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 27 Feb 2009 02:14:27 +0000 (02:14 +0000)
WebminCore.pm
fsdump/edit_dump.cgi
fsdump/fsdump-lib.pl
fsdump/ftp.pl
web-lib-funcs.pl

index bc77a25..c4d887f 100644 (file)
@@ -8,7 +8,7 @@ require Exporter;
 # Add functions in web-lib-funcs.pl
 # Generated with :
 # grep -h "^sub " web-lib-funcs.pl ui-lib.pl | sed -e 's/sub /\&/' | xargs echo
-@EXPORT = qw(&read_file &read_file_cached &write_file &html_escape &quote_escape &tempname &transname &trunc &indexof &indexoflc &sysprint &check_ipaddress &check_ip6address &generate_icon &urlize &un_urlize &include &copydata &ReadParseMime &ReadParse &read_fully &read_parse_mime_callback &read_parse_mime_javascript &PrintHeader &header &get_html_title &get_html_framed_title &get_html_status_line &popup_header &footer &popup_footer &load_theme_library &redirect &kill_byname &kill_byname_logged &find_byname &error &popup_error &error_setup &wait_for &fast_wait_for &has_command &make_date &file_chooser_button &popup_window_button &read_acl &acl_filename &acl_check &get_miniserv_config &put_miniserv_config &restart_miniserv &reload_miniserv &check_os_support &http_download &complete_http_download &ftp_download &ftp_upload &no_proxy &open_socket &download_timeout &ftp_command &to_ipaddress &icons_table &replace_file_line &read_file_lines &flush_file_lines &unflush_file_lines &unix_user_input &unix_group_input &hlink &user_chooser_button &group_chooser_button &foreign_check &foreign_exists &foreign_available &foreign_require &foreign_call &foreign_config &foreign_installed &foreign_defined &get_system_hostname &get_webmin_version &get_module_acl &get_group_module_acl &save_module_acl &save_group_module_acl &init_config &load_language &text_subs &text &encode_base64 &decode_base64 &get_module_info &get_all_module_infos &get_theme_info &list_languages &read_env_file &write_env_file &lock_file &unlock_file &test_lock &unlock_all_files &can_lock_file &webmin_log &additional_log &webmin_debug_log &system_logged &backquote_logged &backquote_with_timeout &backquote_command &kill_logged &rename_logged &rename_file &symlink_logged &symlink_file &link_file &make_dir &set_ownership_permissions &unlink_logged &unlink_file &copy_source_dest &remote_session_name &remote_foreign_require &remote_foreign_call &remote_foreign_check &remote_foreign_config &remote_eval &remote_write &remote_read &remote_finished &remote_error_setup &remote_rpc_call &remote_multi_callback &remote_multi_callback_error &serialise_variable &unserialise_variable &other_groups &date_chooser_button &help_file &seed_random &disk_usage_kb &recursive_disk_usage &help_search_link &make_http_connection &read_http_connection &write_http_connection &close_http_connection &clean_environment &reset_environment &progress_callback &switch_to_remote_user &create_user_config_dirs &create_missing_homedir &filter_javascript &resolve_links &simplify_path &same_file &flush_webmin_caches &list_usermods &available_usermods &get_available_module_infos &get_visible_module_infos &get_visible_modules_categories &is_under_directory &parse_http_url &check_clicks_function &load_entities_map &entities_to_ascii &get_product_name &get_charset &get_display_hostname &save_module_config &save_user_module_config &nice_size &get_perl_path &get_goto_module &select_all_link &select_invert_link &select_rows_link &check_pid_file &get_mod_lib &module_root_directory &list_mime_types &guess_mime_type &open_tempfile &close_tempfile &print_tempfile &is_selinux_enabled &get_clear_file_attributes &reset_file_attributes &cleanup_tempnames &open_lock_tempfile &END &month_to_number &number_to_month &get_rbac_module_acl &supports_rbac &use_rbac_module_acl &execute_command &open_readfile &open_execute_command &translate_filename &translate_command &register_filename_callback &register_command_callback &capture_function_output &modules_chooser_button &substitute_template &running_in_zone &running_in_vserver &running_in_xen &list_categories &is_readonly_mode &command_as_user &list_osdn_mirrors &convert_osdn_url &get_current_dir &supports_users &supports_symlinks &quote_path &get_windows_root &read_file_contents &unix_crypt &split_quoted_string &write_to_http_cache &check_in_http_cache &supports_javascript &ui_table_start &ui_table_end &ui_table_row &ui_table_hr &ui_table_span &ui_columns_start &ui_columns_row &ui_columns_header &ui_checked_columns_row &ui_radio_columns_row &ui_columns_end &ui_columns_table &ui_form_columns_table &ui_form_start &ui_form_end &ui_textbox &ui_filebox &ui_bytesbox &ui_upload &ui_password &ui_hidden &ui_select &ui_multi_select &ui_multi_select_javascript &ui_radio &ui_yesno_radio &ui_checkbox &ui_oneradio &ui_textarea &ui_user_textbox &ui_group_textbox &ui_opt_textbox &ui_submit &ui_reset &ui_button &ui_date_input &ui_buttons_start &ui_buttons_end &ui_buttons_row &ui_buttons_hr &ui_post_header &ui_pre_footer &ui_print_header &ui_print_unbuffered_header &ui_print_footer &ui_config_link &ui_print_endpage &ui_subheading &ui_links_row &ui_hidden_javascript &ui_hidden_start &ui_hidden_end &ui_hidden_table_row_start &ui_hidden_table_row_end &ui_hidden_table_start &ui_hidden_table_end &ui_tabs_start &ui_tabs_end &ui_tabs_start_tab &ui_tabs_start_tabletab &ui_tabs_end_tab &ui_tabs_end_tabletab &ui_max_text_width &ui_radio_selector &ui_radio_selector_javascript &ui_grid_table &ui_radio_table &ui_up_down_arrows &ui_hr &ui_nav_link &ui_confirmation_form &js_disable_inputs &ui_page_flipper &js_checkbox_disable &js_redirect &get_module_name);
+@EXPORT = qw(&read_file &read_file_cached &write_file &html_escape &quote_escape &tempname &transname &trunc &indexof &indexoflc &sysprint &check_ipaddress &check_ip6address &generate_icon &urlize &un_urlize &include &copydata &ReadParseMime &ReadParse &read_fully &read_parse_mime_callback &read_parse_mime_javascript &PrintHeader &header &get_html_title &get_html_framed_title &get_html_status_line &popup_header &footer &popup_footer &load_theme_library &redirect &kill_byname &kill_byname_logged &find_byname &error &popup_error &error_setup &wait_for &fast_wait_for &has_command &make_date &file_chooser_button &popup_window_button &read_acl &acl_filename &acl_check &get_miniserv_config &put_miniserv_config &restart_miniserv &reload_miniserv &check_os_support &http_download &complete_http_download &ftp_download &ftp_upload &no_proxy &open_socket &download_timeout &ftp_command &to_ipaddress &icons_table &replace_file_line &read_file_lines &flush_file_lines &unflush_file_lines &unix_user_input &unix_group_input &hlink &user_chooser_button &group_chooser_button &foreign_check &foreign_exists &foreign_available &foreign_require &foreign_call &foreign_config &foreign_installed &foreign_defined &get_system_hostname &get_webmin_version &get_module_acl &get_group_module_acl &save_module_acl &save_group_module_acl &init_config &load_language &text_subs &text &encode_base64 &decode_base64 &get_module_info &get_all_module_infos &get_theme_info &list_languages &read_env_file &write_env_file &lock_file &unlock_file &test_lock &unlock_all_files &can_lock_file &webmin_log &additional_log &webmin_debug_log &system_logged &backquote_logged &backquote_with_timeout &backquote_command &kill_logged &rename_logged &rename_file &symlink_logged &symlink_file &link_file &make_dir &set_ownership_permissions &unlink_logged &unlink_file &copy_source_dest &remote_session_name &remote_foreign_require &remote_foreign_call &remote_foreign_check &remote_foreign_config &remote_eval &remote_write &remote_read &remote_finished &remote_error_setup &remote_rpc_call &remote_multi_callback &remote_multi_callback_error &serialise_variable &unserialise_variable &other_groups &date_chooser_button &help_file &seed_random &disk_usage_kb &recursive_disk_usage &help_search_link &make_http_connection &read_http_connection &write_http_connection &close_http_connection &clean_environment &reset_environment &progress_callback &switch_to_remote_user &create_user_config_dirs &create_missing_homedir &filter_javascript &resolve_links &simplify_path &same_file &flush_webmin_caches &list_usermods &available_usermods &get_available_module_infos &get_visible_module_infos &get_visible_modules_categories &is_under_directory &parse_http_url &check_clicks_function &load_entities_map &entities_to_ascii &get_product_name &get_charset &get_display_hostname &save_module_config &save_user_module_config &nice_size &get_perl_path &get_goto_module &select_all_link &select_invert_link &select_rows_link &check_pid_file &get_mod_lib &module_root_directory &list_mime_types &guess_mime_type &open_tempfile &close_tempfile &print_tempfile &is_selinux_enabled &get_clear_file_attributes &reset_file_attributes &cleanup_tempnames &open_lock_tempfile &END &month_to_number &number_to_month &get_rbac_module_acl &supports_rbac &use_rbac_module_acl &execute_command &open_readfile &open_execute_command &translate_filename &translate_command &register_filename_callback &register_command_callback &capture_function_output &modules_chooser_button &substitute_template &running_in_zone &running_in_vserver &running_in_xen &list_categories &is_readonly_mode &command_as_user &list_osdn_mirrors &convert_osdn_url &get_current_dir &supports_users &supports_symlinks &quote_path &get_windows_root &read_file_contents &unix_crypt &split_quoted_string &write_to_http_cache &check_in_http_cache &supports_javascript &ui_table_start &ui_table_end &ui_table_row &ui_table_hr &ui_table_span &ui_columns_start &ui_columns_row &ui_columns_header &ui_checked_columns_row &ui_radio_columns_row &ui_columns_end &ui_columns_table &ui_form_columns_table &ui_form_start &ui_form_end &ui_textbox &ui_filebox &ui_bytesbox &ui_upload &ui_password &ui_hidden &ui_select &ui_multi_select &ui_multi_select_javascript &ui_radio &ui_yesno_radio &ui_checkbox &ui_oneradio &ui_textarea &ui_user_textbox &ui_group_textbox &ui_opt_textbox &ui_submit &ui_reset &ui_button &ui_date_input &ui_buttons_start &ui_buttons_end &ui_buttons_row &ui_buttons_hr &ui_post_header &ui_pre_footer &ui_print_header &ui_print_unbuffered_header &ui_print_footer &ui_config_link &ui_print_endpage &ui_subheading &ui_links_row &ui_hidden_javascript &ui_hidden_start &ui_hidden_end &ui_hidden_table_row_start &ui_hidden_table_row_end &ui_hidden_table_start &ui_hidden_table_end &ui_tabs_start &ui_tabs_end &ui_tabs_start_tab &ui_tabs_start_tabletab &ui_tabs_end_tab &ui_tabs_end_tabletab &ui_max_text_width &ui_radio_selector &ui_radio_selector_javascript &ui_grid_table &ui_radio_table &ui_up_down_arrows &ui_hr &ui_nav_link &ui_confirmation_form &js_disable_inputs &ui_page_flipper &js_checkbox_disable &js_redirect &get_module_name clear_time_locale reset_time_locale);
 
 # Add global variables in web-lib.pl
 push(@EXPORT, qw(&unique));
index 811fc96..2531da6 100755 (executable)
@@ -52,8 +52,8 @@ else {
 print &ui_form_start("save_dump.cgi", "post");
 print &ui_hidden("id", $in{'id'}),"\n";
 print &ui_hidden("fs", $dump->{'fs'}),"\n";
-print &ui_table_start(&text('edit_header', uc($dump->{'fs'})),
-                     "width=100%", 2);
+print &ui_hidden_table_start(&text('edit_header', uc($dump->{'fs'})),
+                            "width=100%", 2, "source", 1);
 
 print &ui_table_row($text{'dump_format'},
        $dump->{'fs'} eq 'tar' ? $text{'dump_tar'}
@@ -76,9 +76,9 @@ else {
        }
 
 &dump_form($dump, \@tds);
-print &ui_table_end();
+print &ui_hidden_table_end();
 
-print &ui_table_start($text{'edit_header3'}, "width=100%", 4);
+print &ui_hidden_table_start($text{'edit_header3'}, "width=100%", 4, "opts", 0);
 if (defined(&dump_options_form)) {
        &dump_options_form($dump, \@tds);
        }
@@ -112,9 +112,10 @@ if ($access{'cmds'}) {
                                         !$dump->{'afterfok'}),
                            3, \@tds);
        }
-print &ui_table_end();
+print &ui_hidden_table_end();
 
-print &ui_table_start($text{'edit_header2'}, "width=100%", 4);
+print &ui_hidden_table_start($text{'edit_header2'}, "width=100%", 4,
+                            "sched", 0);
 
 # Show input for selecting when to run a dump, which can be never, on schedule
 # or after some other dump
@@ -157,7 +158,7 @@ else {
                          ('hourly', 'daily', 'weekly', 'monthly', 'yearly') ]),
                3, \@tds);
        }
-print &ui_table_end();
+print &ui_hidden_table_end();
 
 if ($in{'id'}) {
        print &ui_form_end([ [ "save", $text{'save'} ],
index 09956f5..b15dbcd 100644 (file)
@@ -1,11 +1,12 @@
 #!/usr/local/bin/perl
 # fsdump-lib.pl
 # Common functions for doing filesystem backups with dump
-# XXX multi-volume tar restore
 
-do '../web-lib.pl';
+BEGIN { push(@INC, ".."); };
+use WebminCore;
+#do '../web-lib.pl';
+#do '../ui-lib.pl';
 &init_config();
-do '../ui-lib.pl';
 if ($gconfig{'os_type'} =~ /^\S+\-linux$/) {
        do "linux-lib.pl";
        }
@@ -241,6 +242,7 @@ local ($cmd, $fh, $fhmode, $pass) = @_;
 local ($cfh, $fpid) = &proc::pty_process_exec_logged($cmd);
 local ($wrong_password, $got_login, $connect_failed);
 local $out;
+$main::wait_for_debug = 1;
 while(1) {
        local $rv = &wait_for($cfh, "password:", "yes\\/no", "(^|\\n)\\s*Permission denied.*\n", "ssh: connect.*\n", ".*\n");
        if ($wait_for_input !~ /^\s*DUMP:\s+ACLs\s+in\s+inode/i) {
index fb1f9d6..a582e47 100755 (executable)
@@ -69,11 +69,11 @@ while(1) {
                }
        elsif ($line =~ /^W(\d+)/) {
                # Write to FTP server
+               $len = $1;
                if ($opened != 1) {
                        &open_ftp_file($mode);
                        }
                #$opened || &error_exit("FTP connection not opened yet");
-               $len = $1;
                read(STDIN, $buf, $len);
                $wrote = (print CON $buf);
                print "A".($wrote ? $len : 0)."\n";
@@ -148,7 +148,7 @@ $pasv || &error_exit("FTP port failed : $err");
 $pasv =~ /\(([0-9,]+)\)/;
 local @n = split(/,/ , $1);
 &open_socket("$n[0].$n[1].$n[2].$n[3]", $n[4]*256 + $n[5],
-            "CON", \$err) ||
+            CON, \$err) ||
        &error_exit("FTP port failed : $err");
 
 if ($mode == 0) {
index 58e389f..7d5eeec 100755 (executable)
@@ -2405,7 +2405,14 @@ parameters are :
 =cut
 sub open_socket
 {
-my ($addr, $h); $h = $_[2];
+
+# Force file handle into caller's package
+my $h = $_[2];
+my $callpkg = (caller(0))[0];
+if ($callpkg ne __PACKAGE__ && __PACKAGE__ eq 'WebminCore') {
+       $h = $callpkg."::".$h;
+       }
+
 if ($gconfig{'debug_what_net'}) {
        &webmin_debug_log('TCP', "host=$_[0] port=$_[1]");
        }
@@ -2413,6 +2420,7 @@ if (!socket($h, PF_INET, SOCK_STREAM, getprotobyname("tcp"))) {
        if ($_[3]) { ${$_[3]} = "Failed to create socket : $!"; return 0; }
        else { &error("Failed to create socket : $!"); }
        }
+my $addr;
 if (!($addr = inet_aton($_[0]))) {
        if ($_[3]) { ${$_[3]} = "Failed to lookup IP address for $_[0]"; return 0; }
        else { &error("Failed to lookup IP address for $_[0]"); }
@@ -2451,21 +2459,30 @@ for internal use by the ftp_download and ftp_upload functions.
 =cut
 sub ftp_command
 {
-my ($line, $rcode, $reply, $c);
-$what = $_[0] ne "" ? "<i>$_[0]</i>" : "initial connection";
-if ($_[0] ne "") {
-        print SOCK "$_[0]\r\n";
+my ($cmd, $expect, $err, $fh) = @_;
+
+# Work out file handle, and force into caller's package
+$fh ||= "SOCK";
+my $callpkg = (caller(0))[0];
+if ($callpkg ne __PACKAGE__ && __PACKAGE__ eq 'WebminCore') {
+       $fh = $callpkg."::".$fh;
+       }
+
+my $line;
+my $what = $cmd ne "" ? "<i>$cmd/i>" : "initial connection";
+if ($cmd ne "") {
+        print $fh "$cmd\r\n";
         }
 alarm(60);
-if (!($line = <SOCK>)) {
+if (!($line = <$fh>)) {
        alarm(0);
-       if ($_[2]) { ${$_[2]} = "Failed to read reply to $what"; return undef; }
+       if ($err) { $$err = "Failed to read reply to $what"; return undef; }
        else { &error("Failed to read reply to $what"); }
         }
 $line =~ /^(...)(.)(.*)$/;
 my $found = 0;
-if (ref($_[1])) {
-       foreach $c (@{$_[1]}) {
+if (ref($expect)) {
+       foreach my $c (@$expect) {
                $found++ if (int($1/100) == $c);
                }
        }
@@ -2474,16 +2491,17 @@ else {
        }
 if (!$found) {
        alarm(0);
-       if ($_[2]) { ${$_[2]} = "$what failed : $3"; return undef; }
+       if ($err) { $$err = "$what failed : $3"; return undef; }
        else { &error("$what failed : $3"); }
        }
-$rcode = $1; $reply = $3;
+my $rcode = $1;
+my $reply = $3;
 if ($2 eq "-") {
         # Need to skip extra stuff..
         while(1) {
-                if (!($line = <SOCK>)) {
+                if (!($line = <$fh>)) {
                        alarm(0);
-                       if ($_[2]) { ${$_[2]} = "Failed to read reply to $what";
+                       if ($$err) { $$err = "Failed to read reply to $what";
                                     return undef; }
                        else { &error("Failed to read reply to $what"); }
                         }
@@ -7121,6 +7139,13 @@ if (@_ == 1) {
 else {
        # Actually opening
        my ($fh, $file, $noerror, $notemp, $safe) = @_;
+
+       # Force file handler into caller's package
+       my $callpkg = (caller(0))[0];
+       if ($callpkg ne __PACKAGE__ && __PACKAGE__ eq 'WebminCore') {
+               $fh = $callpkg."::".$fh;
+               }
+
        my %gaccess = &get_module_acl(undef, "");
        my $db = $gconfig{'debug_what_write'};
        if ($file =~ /\r|\n|\0/) {
@@ -7230,10 +7255,18 @@ successful. The handle must have been one passed to open_tempfile.
 sub close_tempfile
 {
 my $file;
-if (defined($file = $main::open_temphandles{$_[0]})) {
+
+# Force file handle into caller's package
+my $fh = $_[0];
+my $callpkg = (caller(0))[0];
+if ($callpkg ne __PACKAGE__ && __PACKAGE__ eq 'WebminCore') {
+       $fh = $callpkg."::".$fh;
+       }
+
+if (defined($file = $main::open_temphandles{$fh})) {
        # Closing a handle
-       close($_[0]) || &error(&text("efileclose", $file, $!));
-       delete($main::open_temphandles{$_[0]});
+       close($fh) || &error(&text("efileclose", $file, $!));
+       delete($main::open_temphandles{$fh});
        return &close_tempfile($file);
        }
 elsif (defined($main::open_tempfiles{$_[0]})) {
@@ -7279,6 +7312,10 @@ only partially written.
 sub print_tempfile
 {
 my ($fh, @args) = @_;
+my $callpkg = (caller(0))[0];
+if ($callpkg ne __PACKAGE__ && __PACKAGE__ eq 'WebminCore') {
+       $fh = $callpkg."::".$fh;
+       }
 (print $fh @args) || &error(&text("efilewrite",
                            $main::open_temphandles{$fh} || $fh, $!));
 }