summaryrefslogtreecommitdiffstats
path: root/perl-install/pixmaps/stock_right.xpm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/pixmaps/stock_right.xpm')
0 files changed, 0 insertions, 0 deletions
'#n180'>180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.

package Bugzilla;

use 5.10.1;
use strict;

# We want any compile errors to get to the browser, if possible.
BEGIN {
    # This makes sure we're in a CGI.
    if ($ENV{SERVER_SOFTWARE} && !$ENV{MOD_PERL}) {
        require CGI::Carp;
        CGI::Carp->import('fatalsToBrowser');
    }
}

use Bugzilla::Config;
use Bugzilla::Constants;
use Bugzilla::Auth;
use Bugzilla::Auth::Persist::Cookie;
use Bugzilla::CGI;
use Bugzilla::Extension;
use Bugzilla::DB;
use Bugzilla::Install::Localconfig qw(read_localconfig);
use Bugzilla::Install::Requirements qw(OPTIONAL_MODULES);
use Bugzilla::Install::Util qw(init_console include_languages);
use Bugzilla::Template;
use Bugzilla::User;
use Bugzilla::Error;
use Bugzilla::Util;
use Bugzilla::Field;
use Bugzilla::Flag;
use Bugzilla::Token;

use File::Basename;
use File::Spec::Functions;
use DateTime::TimeZone;
use Date::Parse;
use Safe;

#####################################################################
# Constants
#####################################################################

# Scripts that are not stopped by shutdownhtml being in effect.
use constant SHUTDOWNHTML_EXEMPT => qw(
    editparams.cgi
    checksetup.pl
    migrate.pl
    recode.pl
);

# Non-cgi scripts that should silently exit.
use constant SHUTDOWNHTML_EXIT_SILENTLY => qw(
    whine.pl
);

# shutdownhtml pages are sent as an HTTP 503. After how many seconds
# should search engines attempt to index the page again?
use constant SHUTDOWNHTML_RETRY_AFTER => 3600;

#####################################################################
# Global Code
#####################################################################

# $::SIG{__DIE__} = i_am_cgi() ? \&CGI::Carp::confess : \&Carp::confess;

# Note that this is a raw subroutine, not a method, so $class isn't available.
sub init_page {
    if (Bugzilla->usage_mode == USAGE_MODE_CMDLINE) {
        init_console();
    }
    elsif (Bugzilla->params->{'utf8'}) {
        binmode STDOUT, ':utf8';
    }

    if (${^TAINT}) {
        # Some environment variables are not taint safe
        delete @::ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
        # Some modules throw undefined errors (notably File::Spec::Win32) if
        # PATH is undefined.
        $ENV{'PATH'} = '';
    }

    # Because this function is run live from perl "use" commands of
    # other scripts, we're skipping the rest of this function if we get here
    # during a perl syntax check (perl -c, like we do during the
    # 001compile.t test).
    return if $^C;

    # IIS prints out warnings to the webpage, so ignore them, or log them
    # to a file if the file exists.
    if ($ENV{SERVER_SOFTWARE} && $ENV{SERVER_SOFTWARE} =~ /microsoft-iis/i) {
        $SIG{__WARN__} = sub {
            my ($msg) = @_;
            my $datadir = bz_locations()->{'datadir'};
            if (-w "$datadir/errorlog") {
                my $warning_log = new IO::File(">>$datadir/errorlog");
                print $warning_log $msg;
                $warning_log->close();
            }
        };
    }

    my $script = basename($0);

    # Because of attachment_base, attachment.cgi handles this itself.
    if ($script ne 'attachment.cgi') {
        do_ssl_redirect_if_required();
    }

    # If Bugzilla is shut down, do not allow anything to run, just display a
    # message to the user about the downtime and log out.  Scripts listed in 
    # SHUTDOWNHTML_EXEMPT are exempt from this message.
    #
    # This code must go here. It cannot go anywhere in Bugzilla::CGI, because
    # it uses Template, and that causes various dependency loops.
    if (Bugzilla->params->{"shutdownhtml"}
        && !grep { $_ eq $script } SHUTDOWNHTML_EXEMPT)
    {
        # Allow non-cgi scripts to exit silently (without displaying any
        # message), if desired. At this point, no DBI call has been made
        # yet, and no error will be returned if the DB is inaccessible.
        if (!i_am_cgi()
            && grep { $_ eq $script } SHUTDOWNHTML_EXIT_SILENTLY)
        {
            exit;
        }

        # For security reasons, log out users when Bugzilla is down.
        # Bugzilla->login() is required to catch the logincookie, if any.
        my $user;
        eval { $user = Bugzilla->login(LOGIN_OPTIONAL); };
        if ($@) {
            # The DB is not accessible. Use the default user object.
            $user = Bugzilla->user;
            $user->{settings} = {};
        }
        my $userid = $user->id;
        Bugzilla->logout();

        my $template = Bugzilla->template;
        my $vars = {};
        $vars->{'message'} = 'shutdown';
        $vars->{'userid'} = $userid;
        # Generate and return a message about the downtime, appropriately
        # for if we're a command-line script or a CGI script.
        my $extension;
        if (i_am_cgi() && (!Bugzilla->cgi->param('ctype')
                           || Bugzilla->cgi->param('ctype') eq 'html')) {
            $extension = 'html';
        }
        else {
            $extension = 'txt';
        }
        if (i_am_cgi()) {
            # Set the HTTP status to 503 when Bugzilla is down to avoid pages
            # being indexed by search engines.
            print Bugzilla->cgi->header(-status => 503, 
                -retry_after => SHUTDOWNHTML_RETRY_AFTER);
        }
        my $t_output;
        $template->process("global/message.$extension.tmpl", $vars, \$t_output)
            || ThrowTemplateError($template->error);
        say $t_output;
        exit;
    }
}

#####################################################################
# Subroutines and Methods
#####################################################################

sub template {
    return $_[0]->request_cache->{template} ||= Bugzilla::Template->create();
}

sub template_inner {
    my ($class, $lang) = @_;
    my $cache = $class->request_cache;
    my $current_lang = $cache->{template_current_lang}->[0];
    $lang ||= $current_lang || '';
    return $cache->{"template_inner_$lang"} ||= Bugzilla::Template->create(language => $lang);
}

our $extension_packages;
sub extensions {
    my ($class) = @_;
    my $cache = $class->request_cache;
    if (!$cache->{extensions}) {
        # Under mod_perl, mod_perl.pl populates $extension_packages for us.
        if (!$extension_packages) {
            $extension_packages = Bugzilla::Extension->load_all();
        }
        my @extensions;
        foreach my $package (@$extension_packages) {
            my $extension = $package->new();
            if ($extension->enabled) {
                push(@extensions, $extension);
            }        
        }
        $cache->{extensions} = \@extensions;
    }
    return $cache->{extensions};
}

sub feature {
    my ($class, $feature) = @_;
    my $cache = $class->request_cache;
    return $cache->{feature}->{$feature}
        if exists $cache->{feature}->{$feature};

    my $feature_map = $cache->{feature_map};
    if (!$feature_map) {
        foreach my $package (@{ OPTIONAL_MODULES() }) {
            foreach my $f (@{ $package->{feature} }) {
                $feature_map->{$f} ||= [];
                push(@{ $feature_map->{$f} }, $package->{module});
            }
        }
        $cache->{feature_map} = $feature_map;
    }

    if (!$feature_map->{$feature}) {
        ThrowCodeError('invalid_feature', { feature => $feature });
    }

    my $success = 1;
    foreach my $module (@{ $feature_map->{$feature} }) {
        # We can't use a string eval and "use" here (it kills Template-Toolkit,
        # see https://rt.cpan.org/Public/Bug/Display.html?id=47929), so we have
        # to do a block eval.
        $module =~ s{::}{/}g;
        $module .= ".pm";
        eval { require $module; 1; } or $success = 0;
    }
    $cache->{feature}->{$feature} = $success;
    return $success;
}

sub cgi {
    return $_[0]->request_cache->{cgi} ||= new Bugzilla::CGI();
}

sub input_params {
    my ($class, $params) = @_;
    my $cache = $class->request_cache;
    # This is how the WebService and other places set input_params.
    if (defined $params) {
        $cache->{input_params} = $params;
    }
    return $cache->{input_params} if defined $cache->{input_params};

    # Making this scalar makes it a tied hash to the internals of $cgi,
    # so if a variable is changed, then it actually changes the $cgi object
    # as well.
    $cache->{input_params} = $class->cgi->Vars;
    return $cache->{input_params};
}

sub localconfig {
    return $_[0]->process_cache->{localconfig} ||= read_localconfig();
}

sub params {
    return $_[0]->request_cache->{params} ||= Bugzilla::Config::read_param_file();
}

sub user {
    return $_[0]->request_cache->{user} ||= new Bugzilla::User;
}

sub set_user {
    my ($class, $user) = @_;
    $class->request_cache->{user} = $user;
}

sub sudoer {
    return $_[0]->request_cache->{sudoer};
}

sub sudo_request {
    my ($class, $new_user, $new_sudoer) = @_;
    $class->request_cache->{user}   = $new_user;
    $class->request_cache->{sudoer} = $new_sudoer;
    # NOTE: If you want to log the start of an sudo session, do it here.
}

sub page_requires_login {
    return $_[0]->request_cache->{page_requires_login};
}

sub login {
    my ($class, $type) = @_;

    return $class->user if $class->user->id;

    my $authorizer = new Bugzilla::Auth();
    $type = LOGIN_REQUIRED if $class->cgi->param('GoAheadAndLogIn');

    if (!defined $type || $type == LOGIN_NORMAL) {
        $type = $class->params->{'requirelogin'} ? LOGIN_REQUIRED : LOGIN_NORMAL;
    }

    # Allow templates to know that we're in a page that always requires
    # login.
    if ($type == LOGIN_REQUIRED) {
        $class->request_cache->{page_requires_login} = 1;
    }

    my $authenticated_user = $authorizer->login($type);
    
    # At this point, we now know if a real person is logged in.
    # We must now check to see if an sudo session is in progress.
    # For a session to be in progress, the following must be true:
    # 1: There must be a logged in user
    # 2: That user must be in the 'bz_sudoer' group
    # 3: There must be a valid value in the 'sudo' cookie
    # 4: A Bugzilla::User object must exist for the given cookie value
    # 5: That user must NOT be in the 'bz_sudo_protect' group
    my $token = $class->cgi->cookie('sudo');
    if (defined $authenticated_user && $token) {
        my ($user_id, $date, $sudo_target_id) = Bugzilla::Token::GetTokenData($token);
        if (!$user_id
            || $user_id != $authenticated_user->id
            || !detaint_natural($sudo_target_id)
            || (time() - str2time($date) > MAX_SUDO_TOKEN_AGE))
        {
            $class->cgi->remove_cookie('sudo');
            ThrowUserError('sudo_invalid_cookie');
        }

        my $sudo_target = new Bugzilla::User($sudo_target_id);
        if ($authenticated_user->in_group('bz_sudoers')
            && defined $sudo_target
            && !$sudo_target->in_group('bz_sudo_protect'))
        {
            $class->set_user($sudo_target);
            $class->request_cache->{sudoer} = $authenticated_user;
            # And make sure that both users have the same Auth object,
            # since we never call Auth::login for the sudo target.
            $sudo_target->set_authorizer($authenticated_user->authorizer);

            # NOTE: If you want to do any special logging, do it here.
        }
        else {
            delete_token($token);
            $class->cgi->remove_cookie('sudo');
            ThrowUserError('sudo_illegal_action', { sudoer => $authenticated_user,
                                                    target_user => $sudo_target });
        }
    }
    else {
        $class->set_user($authenticated_user);
    }

    if ($class->sudoer) {
        $class->sudoer->update_last_seen_date();
    } else {
        $class->user->update_last_seen_date();
    }

    return $class->user;
}

sub logout {
    my ($class, $option) = @_;

    # If we're not logged in, go away
    return unless $class->user->id;

    $option = LOGOUT_CURRENT unless defined $option;
    Bugzilla::Auth::Persist::Cookie->logout({type => $option});
    $class->logout_request() unless $option eq LOGOUT_KEEP_CURRENT;
}

sub logout_user {
    my ($class, $user) = @_;
    # When we're logging out another user we leave cookies alone, and
    # therefore avoid calling Bugzilla->logout() directly.
    Bugzilla::Auth::Persist::Cookie->logout({user => $user});
}

# just a compatibility front-end to logout_user that gets a user by id
sub logout_user_by_id {
    my ($class, $id) = @_;
    my $user = new Bugzilla::User($id);
    $class->logout_user($user);
}

# hack that invalidates credentials for a single request
sub logout_request {
    my $class = shift;
    delete $class->request_cache->{user};
    delete $class->request_cache->{sudoer};
    # We can't delete from $cgi->cookie, so logincookie data will remain
    # there. Don't rely on it: use Bugzilla->user->login instead!
}

sub job_queue {
    require Bugzilla::JobQueue;
    return $_[0]->request_cache->{job_queue} ||= Bugzilla::JobQueue->new();
}

sub dbh {
    # If we're not connected, then we must want the main db
    return $_[0]->request_cache->{dbh} ||= $_[0]->dbh_main;
}

sub dbh_main {
    return $_[0]->request_cache->{dbh_main} ||= Bugzilla::DB::connect_main();
}