Server IP : 195.201.23.43 / Your IP : 18.119.143.234 Web Server : Apache System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64 User : kdecoratie ( 1041) PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/webmin/virtual-server/ |
Upload File : |
#!/usr/bin/perl =head1 create-redirect.pl Adds a web redirect or alias to some domain A redirect maps some URL path like /foo to either a different URL, or a different directory on the same virtual server. This can be used to provide more friendly URL paths on your website, or to cope with the movement of web pages to new locations. This command takes a mandatory C<--domain> parameter, followed by a virtual server's domain name. The C<--path> parameter is also mandatory, and must be followed by a local URL path like C</rails> or even C</>. To redirect to a different URL, use the C<--redirect> flag followed by a complete URL starting with http or https, or a URL path on this same domain. To map the path to a directory, use the C<--alias> flag followed by a full directory path, ideally under the domain's C<public_html> directory. By default, requests for sub-paths under the URL path will be mapped to the same sub-path in the destination directory or path. However, you can use the C<--exact> flag to only match the given path, or the C<--regexp> flag to ignore sub-paths when redirecting. For domains with both non-SSL and SSL websites, you can use the C<--http> and C<--https> flags to limit the alias or redirect to one website type or the other. To set a custom HTTP status code for the redirect, you can use the C<--code> flag followed by a number. Otherwise the default code of 301 (temporary redirect) will be used. =cut package virtual_server; if (!$module_name) { $main::no_acl_check++; $ENV{'WEBMIN_CONFIG'} ||= "/etc/webmin"; $ENV{'WEBMIN_VAR'} ||= "/var/webmin"; if ($0 =~ /^(.*)\/[^\/]+$/) { chdir($pwd = $1); } else { chop($pwd = `pwd`); } $0 = "$pwd/create-redirect.pl"; require './virtual-server-lib.pl'; $< == 0 || die "create-redirect.pl must be run as root"; } @OLDARGV = @ARGV; # Parse command-line args &require_mail(); while(@ARGV > 0) { local $a = shift(@ARGV); if ($a eq "--domain") { $domain = shift(@ARGV); } elsif ($a eq "--path") { $path = shift(@ARGV); } elsif ($a eq "--redirect") { $url = shift(@ARGV); } elsif ($a eq "--alias") { $dir = shift(@ARGV); } elsif ($a eq "--regexp") { $regexp = 1; } elsif ($a eq "--exact") { $exact = 1; } elsif ($a eq "--multiline") { $multiline = 1; } elsif ($a eq "--http") { $http = 1; } elsif ($a eq "--https") { $https = 1; } elsif ($a eq "--code") { $code = shift(@ARGV); $code =~ /^\d{3}$/ && $code >= 300 && $code < 400 || &usage("--code must be followed by a HTTP status code between 300 and 400"); } elsif ($a eq "--help") { &usage(); } else { &usage("Unknown parameter $a"); } } $domain || &usage("No domain specified"); $path || &usage("No redirect path specified"); $exact && $regexp && &usage("Only one of --regexp or --exact can be given"); if ($url) { $url =~ /^*(http|https):\/\/\S+$/ || $url =~ /^\/\S+$/ || &usage("The --redirect flag must be followed by a URL or ". "a URL path"); } elsif ($dir) { $dir =~ /^\/\S+$/ && -d $dir || &usage("The --alias flag must be followed by a directory"); } else { &usage("One of --redirect or --alias must be given"); } if (!$http && !$https) { # If no protocol was given, assume both for backwards compatability $http = $https = 1; } $d = &get_domain_by("dom", $domain); $d || usage("Virtual server $domain does not exist"); &has_web_redirects($d) || &usage("Virtual server $domain does not support redirects"); # Check for clash &obtain_lock_web($d); @redirects = &list_redirects($d); ($clash) = grep { $_->{'path'} eq $path } @balancers; $clash && &usage("A redirect for the path $path already exists"); # Create it $r = { 'path' => $path, 'dest' => $url || $dir, 'alias' => $dir ? 1 : 0, 'regexp' => $regexp, 'exact' => $exact, 'http' => $http, 'https' => $https, 'code' => $code, }; $err = &create_redirect($d, $r); &release_lock_web($d); if ($err) { print "Failed to create redirect : $err\n"; exit(1); } else { &set_all_null_print(); &run_post_actions(); &virtualmin_api_log(\@OLDARGV, $d); print "Redirect for $path created successfully\n"; } sub usage { print "$_[0]\n\n" if ($_[0]); print "Adds redirect or alias to a virtual server's website.\n"; print "\n"; print "virtualmin create-redirect --domain domain.name\n"; print " --path url-path\n"; print " --alias directory | --redirect url\n"; print " [--regexp | --exact]\n"; print " [--code number]\n"; print " [--http | --https]\n"; exit(1); }Private