summaryrefslogtreecommitdiffstats
path: root/perl-install/Xconfig/test.pm
blob: d14cca7554f7eb10f1ceadb61ceedbc1ef8c48c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package Xconfig::test; # $Id$

use diagnostics;
use strict;

use Xconfig::card;
use run_program;
use common;
use log;


my $tmpconfig = "/tmp/Xconfig";


sub xtest {
    my ($display) = @_;
    $::isStandalone ? 
      system("DISPLAY=$display /usr/X11R6/bin/xtest") == 0 : 
      c::Xtest($display);    
}

sub test {
    my ($in, $raw_X, $card, $auto, $skip_badcard) = @_;

    my $bad_card = !Xconfig::card::check_bad_card($card);
    return 1 if $skip_badcard && $bad_card;

    if ($bad_card || !$auto) {
	$in->ask_yesorno(N("Test of the configuration"), 
			 N("Do you want to test the configuration?") . ($bad_card ? "\n" . N("Warning: testing this graphic card may freeze your computer") : ''),
			 !$bad_card) or return 1;
    }

    unlink "$::prefix/tmp/.X9-lock";

    #- create a link from the non-prefixed /tmp/.X11-unix/X9 to the prefixed one
    #- that way, you can talk to :9 without doing a chroot
    #- but take care of non X11 install :-)
    if (-d "/tmp/.X11-unix") {
	symlinkf "$::prefix/tmp/.X11-unix/X9", "/tmp/.X11-unix/X9" if $::prefix;
    } else {
	symlinkf "$::prefix/tmp/.X11-unix", "/tmp/.X11-unix" if $::prefix;
    }

    #- ensure xfs is running
    fuzzy_pidofs(qr/\bxfs\b/) or do { run_program::rooted($::prefix, "/etc/rc.d/init.d/xfs", $_) foreach 'stop', 'start' };
    fuzzy_pidofs(qr/\bxfs\b/) or die "xfs is not running";

    my $f = $::testing ? $tmpconfig : "/etc/X11/XF86Config.test";
    $raw_X->{Xconfig::card::using_xf4($card) ? 'xfree4' : 'xfree3'}->write("$::prefix/$f");

    $ENV{HOME} || $::isInstall or die q($HOME is unset, so I don't know where to put my temporary files);
    my $f_err = "$::prefix$ENV{HOME}/tmp/.drakx.Xoutput";
    my $pid;
    unless ($pid = fork()) {
	system("xauth add :9 . `mcookie`");
	open STDERR, ">$f_err";
	chroot $::prefix if $::prefix;
	exec $card->{prog}, 
	  if_($card->{prog} !~ /Xsun/, "-xf86config", $f),
	  ":9" or c::_exit(0);
    }

    do { sleep 1 } until xtest(":9") || waitpid($pid, c::WNOHANG());

    my $_b = before_leaving { unlink $f_err };

    my $warn_error = sub {
	my ($error_msg) = @_;
	$in->ask_warn('', [ N("An error occurred:\n%s\nTry to change some parameters", $error_msg) ]);
    };

    if (!xtest(":9")) {
	open(my $F, $f_err);

	local $_;
      i: while (<$F>) {
	    if (Xconfig::card::using_xf4($card)) {
		if (/^\(EE\)/ && !/Disabling/ || /^Fatal\b/) {
		    my @msg = !/error/ && $_;
		    local $_;
		    while (<$F>) {
			/reporting a problem/ and last;
			$warn_error->(join(@msg, $_));
			return 0;
		    }
		}
	    } else {
		if (/\b(error|not supported)\b/i) {
		    my @msg = !/error/ && $_;
		    local $_;
		    while (<$F>) {
			/not fatal/ and last i;
			/^$/ and last;
			push @msg, $_;
		    }
		    $warn_error->(join(@msg));
		    return 0;
		}
	    }
	}
    }

    $::noShadow = 1;
    open(my $F, "|perl 2>/dev/null");
    print $F 
    printf $F q(
        use lib qw(%s);
        BEGIN { $::no_ugtk_init = 1 }
        require lang;
        require ugtk2; #- help perl_checker
        ugtk2->import(qw(:wrappers :helpers)); #- help perl_checker
	use interactive::gtk;
        use run_program;
        use common;

        $::prefix = "%s";
        $::isStandalone = 1;

        lang::bindtextdomain();

	$ENV{DISPLAY} = ":9";
        Gtk2->init([]);

        gtkset_background(200 * 257, 210 * 257, 210 * 257);
        my ($h, $w) = gtkroot()->get_size;
        $ugtk2::force_position = [ $w / 3, $h / 2.4 ];
	$ugtk2::force_focus = 1;
        my $text = Gtk2::Label->new;
        my $time = 12;
        Glib::Timeout->add(1000, sub {
	    $text->set(sprintf(translate("%s"), $time));
	    $time-- or Gtk2->main_quit;
            1;
	});

        eval {  #- eval it so that missing pixmap will not break the test completely
            my $root = gtkroot();
            my $gc = Gtk2::Gdk::GC->new($root);
            my $pixbuf = Gtk2::Gdk::Pixbuf->new_from_file("$::prefix/usr/share/mdk/xfdrake/xfdrake-test-card.jpg");
            my ($w, $h) = ($pixbuf->get_width, $pixbuf->get_height);
            my $pixmap = Gtk2::Gdk::Pixmap->new($root, $w, $h, $root->get_depth);
            $pixbuf->render_to_drawable($pixmap, $gc, 0, 0, 0, 0, $w, $h, 'none', 0, 0);
            $root->set_back_pixmap($pixmap, 0);
            $root->clear;
        };

        my $in = interactive::gtk->new;
	$in->exit($in->ask_yesorno('', [ translate("%s"), $text ], 0) ? 0 : 222);
    ), join(' ', @INC), $::prefix, N_("Leaving in %d seconds"), N_("Is this the correct setting?");
    my $rc = close $F;
    my $err = $?;

    $rc || $err == 222 << 8 or $warn_error->('');

    unlink "$::prefix/$f", "$::prefix/$f-4";
    unlink "/tmp/.X11-unix/X9" if $::prefix;
    kill 2, $pid;
    $::noShadow = 0;

    $rc;
}
ss="hl opt">{ $this->is_in_admin = (bool) $is_in_admin; } /** * Returns the is_in_admin option * * @return bool */ public function get_is_admin() { return $this->is_in_admin; } /** * Set table name * * @param string $log_table Can overwrite the table to use for the logs * @return null */ public function set_log_table($log_table) { $this->log_table = $log_table; } /** * This function returns the state of the log system. * * {@inheritDoc} */ public function is_enabled($type = '') { if ($type == '' || $type == 'all') { return !isset($this->disabled_types['all']); } return !isset($this->disabled_types[$type]) && !isset($this->disabled_types['all']); } /** * Disable log * * This function allows disabling the log system or parts of it, for this * page call. When add_log is called and the type is disabled, * the log will not be added to the database. * * {@inheritDoc} */ public function disable($type = '') { if (is_array($type)) { foreach ($type as $disable_type) { $this->disable($disable_type); } return; } // Empty string is an equivalent for all types. if ($type == '') { $type = 'all'; } $this->disabled_types[$type] = true; } /** * Enable log * * This function allows re-enabling the log system. * * {@inheritDoc} */ public function enable($type = '') { if (is_array($type)) { foreach ($type as $enable_type) { $this->enable($enable_type); } return; } if ($type == '' || $type == 'all') { $this->disabled_types = array(); return; } unset($this->disabled_types[$type]); } /** * Adds a log to the database * * {@inheritDoc} */ public function add($mode, $user_id, $log_ip, $log_operation, $log_time = false, $additional_data = array()) { if (!$this->is_enabled($mode)) { return false; } if ($log_time == false) { $log_time = time(); } $sql_ary = array( 'user_id' => $user_id, 'log_ip' => $log_ip, 'log_time' => $log_time, 'log_operation' => $log_operation, ); switch ($mode) { case 'admin': $sql_ary += array( 'log_type' => LOG_ADMIN, 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; case 'mod': $forum_id = (int) $additional_data['forum_id']; unset($additional_data['forum_id']); $topic_id = (int) $additional_data['topic_id']; unset($additional_data['topic_id']); $sql_ary += array( 'log_type' => LOG_MOD, 'forum_id' => $forum_id, 'topic_id' => $topic_id, 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; case 'user': $reportee_id = (int) $additional_data['reportee_id']; unset($additional_data['reportee_id']); $sql_ary += array( 'log_type' => LOG_USERS, 'reportee_id' => $reportee_id, 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; case 'critical': $sql_ary += array( 'log_type' => LOG_CRITICAL, 'log_data' => (!empty($additional_data)) ? serialize($additional_data) : '', ); break; } /** * Allows to modify log data before we add it to the database * * NOTE: if sql_ary does not contain a log_type value, the entry will * not be stored in the database. So ensure to set it, if needed. * * @event core.add_log * @var string mode Mode of the entry we log * @var int user_id ID of the user who triggered the log * @var string log_ip IP of the user who triggered the log * @var string log_operation Language key of the log operation * @var int log_time Timestamp, when the log was added * @var array additional_data Array with additional log data * @var array sql_ary Array with log data we insert into the * database. If sql_ary[log_type] is not set, * we won't add the entry to the database. * @since 3.1-A1 */ $vars = array('mode', 'user_id', 'log_ip', 'log_operation', 'log_time', 'additional_data', 'sql_ary'); extract($this->dispatcher->trigger_event('core.add_log', $vars)); // We didn't find a log_type, so we don't save it in the database. if (!isset($sql_ary['log_type'])) { return false; } $this->db->sql_query('INSERT INTO ' . $this->log_table . ' ' . $this->db->sql_build_array('INSERT', $sql_ary)); return $this->db->sql_nextid(); } /** * Grab the logs from the database * * {@inheritDoc} */ public function get_logs($mode, $count_logs = true, $limit = 0, $offset = 0, $forum_id = 0, $topic_id = 0, $user_id = 0, $log_time = 0, $sort_by = 'l.log_time DESC', $keywords = '') { $this->entry_count = 0; $this->last_page_offset = $offset; $topic_id_list = $reportee_id_list = array(); $profile_url = ($this->get_is_admin() && $this->phpbb_admin_path) ? append_sid("{$this->phpbb_admin_path}index.{$this->php_ext}", 'i=users&amp;mode=overview') : append_sid("{$this->phpbb_root_path}memberlist.{$this->php_ext}", 'mode=viewprofile'); switch ($mode) { case 'admin': $log_type = LOG_ADMIN; $sql_additional = ''; break; case 'mod': $log_type = LOG_MOD; $sql_additional = ''; if ($topic_id) { $sql_additional = 'AND l.topic_id = ' . (int) $topic_id; } else if (is_array($forum_id)) { $sql_additional = 'AND ' . $this->db->sql_in_set('l.forum_id', array_map('intval', $forum_id)); } else if ($forum_id) { $sql_additional = 'AND l.forum_id = ' . (int) $forum_id; } break; case 'user': $log_type = LOG_USERS; $sql_additional = 'AND l.reportee_id = ' . (int) $user_id; break; case 'users': $log_type = LOG_USERS; $sql_additional = ''; break; case 'critical': $log_type = LOG_CRITICAL; $sql_additional = ''; break; default: $log_type = false; $sql_additional = ''; } /** * Overwrite log type and limitations before we count and get the logs * * NOTE: if log_type is false, no entries will be returned. * * @event core.get_logs_modify_type * @var string mode Mode of the entries we display * @var bool count_logs Do we count all matching entries? * @var int limit Limit the number of entries * @var int offset Offset when fetching the entries * @var mixed forum_id Limit entries to the forum_id, * can also be an array of forum_ids * @var int topic_id Limit entries to the topic_id * @var int user_id Limit entries to the user_id * @var int log_time Limit maximum age of log entries * @var string sort_by SQL order option * @var string keywords Will only return entries that have the * keywords in log_operation or log_data * @var string profile_url URL to the users profile * @var int log_type Limit logs to a certain type. If log_type * is false, no entries will be returned. * @var string sql_additional Additional conditions for the entries, * e.g.: 'AND l.forum_id = 1' * @since 3.1-A1 */ $vars = array('mode', 'count_logs', 'limit', 'offset', 'forum_id', 'topic_id', 'user_id', 'log_time', 'sort_by', 'keywords', 'profile_url', 'log_type', 'sql_additional'); extract($this->dispatcher->trigger_event('core.get_logs_modify_type', $vars)); if ($log_type === false) { $this->last_page_offset = 0; return array(); } $sql_keywords = ''; if (!empty($keywords)) { // Get the SQL condition for our keywords $sql_keywords = $this->generate_sql_keyword($keywords); } if ($count_logs) { $sql = 'SELECT COUNT(l.log_id) AS total_entries FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . ' u WHERE l.log_type = ' . (int) $log_type . ' AND l.user_id = u.user_id AND l.log_time >= ' . (int) $log_time . " $sql_keywords $sql_additional"; $result = $this->db->sql_query($sql); $this->entry_count = (int) $this->db->sql_fetchfield('total_entries'); $this->db->sql_freeresult($result); if ($this->entry_count == 0) { // Save the queries, because there are no logs to display $this->last_page_offset = 0; return array(); } // Return the user to the last page that is valid while ($this->last_page_offset >= $this->entry_count) { $this->last_page_offset = max(0, $this->last_page_offset - $limit); } } $sql = 'SELECT l.*, u.username, u.username_clean, u.user_colour FROM ' . LOG_TABLE . ' l, ' . USERS_TABLE . ' u WHERE l.log_type = ' . (int) $log_type . ' AND u.user_id = l.user_id ' . (($log_time) ? 'AND l.log_time >= ' . (int) $log_time : '') . " $sql_keywords $sql_additional ORDER BY $sort_by"; $result = $this->db->sql_query_limit($sql, $limit, $this->last_page_offset); $i = 0; $log = array(); while ($row = $this->db->sql_fetchrow($result)) { $row['forum_id'] = (int) $row['forum_id']; if ($row['topic_id']) { $topic_id_list[] = (int) $row['topic_id']; } if ($row['reportee_id']) { $reportee_id_list[] = (int) $row['reportee_id']; } $log_entry_data = array( 'id' => (int) $row['log_id'], 'reportee_id' => (int) $row['reportee_id'], 'reportee_username' => '', 'reportee_username_full'=> '', 'user_id' => (int) $row['user_id'], 'username' => $row['username'], 'username_full' => get_username_string('full', $row['user_id'], $row['username'], $row['user_colour'], false, $profile_url), 'ip' => $row['log_ip'], 'time' => (int) $row['log_time'], 'forum_id' => (int) $row['forum_id'], 'topic_id' => (int) $row['topic_id'],