* @license GNU General Public License, version 2 (GPL-2.0) * * For full copyright and license information, please see * the docs/CREDITS.txt file. * */ namespace phpbb\db\migration\data\v310; class dev extends \phpbb\db\migration\migration { public function effectively_installed() { return version_compare($this->config['version'], '3.1.0-dev', '>='); } static public function depends_on() { return array( '\phpbb\db\migration\data\v310\extensions', '\phpbb\db\migration\data\v310\style_update_p2', '\phpbb\db\migration\data\v310\timezone_p2', '\phpbb\db\migration\data\v310\reported_posts_display', '\phpbb\db\migration\data\v310\migrations_table', ); } public function update_schema() { return array( 'add_columns' => array( $this->table_prefix . 'groups' => array( 'group_teampage' => array('UINT', 0, 'after' => 'group_legend'), ), $this->table_prefix . 'profile_fields' => array( 'field_show_on_pm' => array('BOOL', 0), ), $this->table_prefix . 'styles' => array( 'style_path' => array('VCHAR:100', ''), 'bbcode_bitfield' => array('VCHAR:255', 'kNg='), 'style_parent_id' => array('UINT:4', 0), 'style_parent_tree' => array('TEXT', ''), ), $this->table_prefix . 'reports' => array( 'reported_post_text' => array('MTEXT_UNI', ''), 'reported_post_uid' => array('VCHAR:8', ''), 'reported_post_bitfield' => array('VCHAR:255', ''), ), ), 'change_columns' => array( $this->table_prefix . 'groups' => array( 'group_legend' => array('UINT', 0), ), ), ); } public function revert_schema() { return array( 'drop_columns' => array( $this->table_prefix . 'groups' => array( 'group_teampage', ), $this->table_prefix . 'profile_fields' => array( 'field_show_on_pm', ), $this->table_prefix . 'styles' => array( 'style_path', 'bbcode_bitfield', 'style_parent_id', 'style_parent_tree', ), $this->table_prefix . 'reports' => array( 'reported_post_text', 'reported_post_uid', 'reported_post_bitfield', ), ), ); } public function update_data() { return array( array('if', array( (strpos('phpbb_search_', $this->config['search_type']) !== 0), array('config.update', array('search_type', 'phpbb_search_' . $this->config['search_type'])), )), array('config.add', array('fulltext_postgres_ts_name', 'simple')), array('config.add', array('fulltext_postgres_min_word_len', 4)), array('config.add', array('fulltext_postgres_max_word_len', 254)), array('config.add', array('fulltext_sphinx_stopwords', 0)), array('config.add', array('fulltext_sphinx_indexer_mem_limit', 512)), array('config.add', array('load_jquery_cdn', 0)), array('config.add', array('load_jquery_url', '//ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js')), array('config.add', array('use_system_cron', 0)), array('config.add', array('legend_sort_groupname', 0)), array('config.add', array('teampage_forums', 1)), array('config.add', array('teampage_memberships', 1)), array('config.add', array('load_cpf_pm', 0)), array('config.add', array('display_last_subject', 1)), array('config.add', array('assets_version', 1)), array('config.add', array('site_home_url', '')), array('config.add', array('site_home_text', '')), array('permission.add', array('u_chgprofileinfo', true, 'u_sig')), array('module.add', array( 'acp', 'ACP_GROUPS', array( 'module_basename' => 'acp_groups', 'modes' => array('position'), ), )), array('module.add', array( 'acp', 'ACP_ATTACHMENTS', array( 'module_basename' => 'acp_attachments', 'modes' => array('manage'), ), )), array('module.add', array( 'acp', 'ACP_STYLE_MANAGEMENT', array( 'module_basename' => 'acp_styles', 'modes' => array('install', 'cache'), ), )), array('module.add', array( 'ucp', 'UCP_PROFILE', array( 'module_basename' => 'ucp_profile', 'modes' => array('autologin_keys'), ), )), // Module will be renamed later array('module.add', array( 'acp', 'ACP_CAT_STYLES', 'ACP_LANGUAGE' )), array('module.remove', array( 'acp', false, 'ACP_TEMPLATES', )), array('module.remove', array( 'acp', false, 'ACP_THEMES', )), array('module.remove', array( 'acp', false, 'ACP_IMAGESETS', )), array('custom', array(array($this, 'rename_module_basenames'))), array('custom', array(array($this, 'rename_styles_module'))), array('custom', array(array($this, 'add_group_teampage'))), array('custom', array(array($this, 'update_group_legend'))), array('custom', array(array($this, 'localise_global_announcements'))), array('custom', array(array($this, 'update_ucp_pm_basename'))), array('custom', array(array($this, 'update_ucp_profile_auth'))), array('custom', array(array($this, 'move_customise_modules'))), array('config.update', array('version', '3.1.0-dev')), ); } public function move_customise_modules() { // Move language management to new location in the Customise tab // First get language module id $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " WHERE module_basename = 'acp_language'"; $result = $this->db->sql_query($sql); $language_module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); // Next get language management module id of the one just created $sql = 'SELECT module_id FROM ' . MODULES_TABLE . " WHERE module_langname = 'ACP_LANGUAGE'"; $result = $this->db->sql_query($sql); $language_management_module_id = $this->db->sql_fetchfield('module_id'); $this->db->sql_freeresult($result); if (!class_exists('acp_modules')) { include($this->phpbb_root_path . 'includes/acp/acp_modules.' . $this->php_ext); } // acp_modules calls adm_back_link, which is undefined at this point if (!function_exists('adm_back_link')) { include($this->phpbb_root_path . 'includes/functions_acp.' . $this->php_ext); } $module_manager = new \acp_modules(); $module_manager->module_class = 'acp'; $module_manager->move_module($language_module_id, $language_management_module_id); } public function update_ucp_pm_basename() { $sql = 'SELECT module_id, module_basename FROM ' . MODULES_TABLE . " WHERE module_basename <> 'ucp_pm' AND module_langname='UCP_PM'"; $result = $this->db->sql_query_limit($sql, 1); if ($row = $this->db->sql_fetchrow($result)) { // This update is still not applied. Applying it $sql = 'UPDATE ' . MODULES_TABLE . " SET module_basename = 'ucp_pm' WHERE module_id = " . (int) $row['module_id']; $this->sql_query($sql); } $this->db->sql_freeresult($result); } public function update_ucp_profile_auth() { // Update the auth setting for the module $sql = 'UPDATE ' . MODULES_TABLE . " SET module_auth = 'acl_u_chgprofileinfo' WHERE module_class = 'ucp' AND module_basename = 'ucp_profile' AND module_mode = 'profile_info'"; $this->sql_query($sql); } public function rename_styles_module() { // Rename styles module to Customise $sql = 'UPDATE ' . MODULES_TABLE . " SET module_langname = 'ACP_CAT_CUSTOMISE' WHERE module_langname = 'ACP_CAT_STYLES'"; $this->sql_query($sql); } public function rename_module_basenames() { // rename all module basenames to full classname $sql = 'SELECT module_id, module_basename, module_class FROM ' . MODULES_TABLE; $result = $this->db->sql_query($sql); while ($row = $this->db->sql_fetchrow($result)) { $module_id = (int) $row['module_id']; unset($row['module_id']); if (!empty($row['module_basename']) && !empty($row['module_class'])) { // all the class names start with class name or with phpbb_ for auto loading if (strpos($row['module_basename'], $row['module_class'] . '_') !== 0 && strpos($row['module_basename'], 'phpbb_') !== 0) { $row['module_basename'] = $row['module_class'] . '_' . $row['module_basename']; $sql_update = $this->db->sql_build_array('UPDATE', $row); $sql = 'UPDATE ' . MODULES_TABLE . ' SET ' . $sql_update . ' WHERE module_id = ' . $module_id; $this->sql_query($sql); } } } $this->db->sql_freeresult($result); } public function add_group_teampage() { $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_teampage = 1 WHERE group_type = ' . GROUP_SPECIAL . " AND group_name = 'ADMINISTRATORS'"; $this->sql_query($sql); $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_teampage = 2 WHERE group_type = ' . GROUP_SPECIAL . " AND group_name = 'GLOBAL_MODERATORS'"; $this->sql_query($sql); } public function update_group_legend() { $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_legend = 1 ORDER BY group_name ASC'; $result = $this->db->sql_query($sql); $next_legend = 1; while ($row = $this->db->sql_fetchrow($result)) { $sql = 'UPDATE ' . GROUPS_TABLE . ' SET group_legend = ' . $next_legend . ' WHERE group_id = ' . (int) $row['group_id']; $this->sql_query($sql); $next_legend++; } $this->db->sql_freeresult($result); } public function localise_global_announcements() { // Localise Global Announcements $sql = 'SELECT topic_id, topic_approved, (topic_replies + 1) AS topic_posts, topic_last_post_id, topic_last_post_subject, topic_last_post_time, topic_last_poster_id, topic_last_poster_name, topic_last_poster_colour FROM ' . TOPICS_TABLE . ' WHERE forum_id = 0 AND topic_type = ' . POST_GLOBAL; $result = $this->db->sql_query($sql); $global_announcements = $update_lastpost_data = array(); $update_lastpost_data['forum_last_post_time'] = 0; $update_forum_data = array( 'forum_posts' => 0, 'forum_topics' => 0, 'forum_topics_real' => 0, ); while ($row = $this->db->sql_fetchrow($result)) { $global_announcements[] = (int) $row['topic_id']; $update_forum_data['forum_posts'] += (int) $row['topic_posts']; $update_forum_data['forum_topics_real']++; if ($row['topic_approved']) { $update_forum_data['forum_topics']++; } if ($update_lastpost_data['forum_last_post_time'] < $row['topic_last_post_time']) { $update_lastpost_data = array( 'forum_last_post_id' => (int) $row['topic_last_post_id'], 'forum_last_post_subject' => $row['topic_last_post_subject'], 'forum_last_post_time' => (int) $row['topic_last_post_time'], 'forum_last_poster_id' => (int) $row['topic_last_poster_id'], 'forum_last_poster_name' => $row['topic_last_poster_name'], 'forum_last_poster_colour' => $row['topic_last_poster_colour'], ); } } $this->db->sql_freeresult($result); if (!empty($global_announcements)) { // Update the post/topic-count for the forum and the last-post if needed $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST; $result = $this->db->sql_query_limit($sql, 1); $ga_forum_id = $this->db->sql_fetchfield('forum_id'); $this->db->sql_freeresult($result); $sql = 'SELECT forum_last_post_time FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $ga_forum_id; $result = $this->db->sql_query($sql); $lastpost = (int) $this->db->sql_fetchfield('forum_last_post_time'); $this->db->sql_freeresult($result); $sql_update = 'forum_posts = forum_posts + ' . $update_forum_data['forum_posts'] . ', '; $sql_update .= 'forum_topics_real = forum_topics_real + ' . $update_forum_data['forum_topics_real'] . ', '; $sql_update .= 'forum_topics = forum_topics + ' . $update_forum_data['forum_topics']; if ($lastpost < $update_lastpost_data['forum_last_post_time']) { $sql_update .= ', ' . $this->db->sql_build_array('UPDATE', $update_lastpost_data); } $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $sql_update . ' WHERE forum_id = ' . $ga_forum_id; $this->sql_query($sql); // Update some forum_ids $table_ary = array(TOPICS_TABLE, POSTS_TABLE, LOG_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE); foreach ($table_ary as $table) { $sql = "UPDATE $table SET forum_id = $ga_forum_id WHERE " . $this->db->sql_in_set('topic_id', $global_announcements); $this->sql_query($sql); } unset($table_ary); } } } 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
package fs; # $Id$

use diagnostics;
use strict;

use MDK::Common::System;
use MDK::Common::Various;
use common;
use log;
use devices;
use fs::type;
use fs::get;
use fs::format;
use fs::mount_options;
use run_program;
use detect_devices;
use modules;
use fsedit;
use loopback;


sub read_fstab {
    my ($prefix, $file, @reading_options) = @_;

    if (member('keep_default', @reading_options)) {
	push @reading_options, 'freq_passno', 'keep_devfs_name', 'keep_device_LABEL';
    }

    my %comments;
    my $comment;
    my @l = grep {
	if (/^Filename\s*Type\s*Size/) {
	    0; #- when reading /proc/swaps
	} elsif (/^\s*#/) {
	    $comment .= chomp_($_) . "\n";
	    0;
	} else {
	    $comments{$_} = $comment if $comment;
	    $comment = '';
	    1;
	}
    } cat_("$prefix$file");

    #- attach comments at the end of fstab to the previous line
    $comments{$l[-1]} = $comment if $comment;

    map {
	my ($dev, $mntpoint, $fs_type, $options, $freq, $passno) = split;
	my $comment = $comments{$_};

	$options = 'defaults' if $options eq 'rw'; # clean-up for mtab read

	if ($fs_type eq 'supermount') {
	    # normalize this bloody supermount
	    $options = join(",", 'supermount', grep {
		if (/fs=(.*)/) {
		    $fs_type = $1;
		    0;
		} elsif (/dev=(.*)/) {
		    $dev = $1;
		    0;
		} elsif ($_ eq '--') {
		    0;
		} else {
		    1;
		}
	    } split(',', $options));
	} elsif ($fs_type eq 'smb') {
	    # prefering type "smbfs" over "smb"
	    $fs_type = 'smbfs';
	}
	s/\\040/ /g foreach $mntpoint, $dev, $options;

	my $h = { 
		 mntpoint => $mntpoint, fs_type => $fs_type,
		 options => $options, comment => $comment,
		 if_(member('keep_freq_passno', @reading_options), freq => $freq, passno => $passno),
		};

	put_in_hash($h, subpart_from_wild_device_name($dev));

	if ($h->{device_LABEL} && member('keep_device_LABEL', @reading_options)) {
	    $h->{prefer_device_LABEL} = 1;
        } elsif ($h->{devfs_device} && member('keep_devfs_name', @reading_options)) {
	    $h->{prefer_devfs_name} = 1;
	}

	if ($h->{options} =~ /credentials=/ && !member('verbatim_credentials', @reading_options)) {
	    require network::smb;
	    #- remove credentials=file with username=foo,password=bar,domain=zoo
	    #- the other way is done in fstab_to_string
	    my ($options, $unknown) = fs::mount_options::unpack($h);
	    my $file = delete $options->{'credentials='};
	    my $credentials = network::smb::read_credentials_raw($file);
	    if ($credentials->{username}) {
		$options->{"$_="} = $credentials->{$_} foreach qw(username password domain);
		fs::mount_options::pack($h, $options, $unknown);
	    }
	}

	$h;
    } @l;
}

sub merge_fstabs {
    my ($loose, $fstab, @l) = @_;

    foreach my $p (@$fstab) {
	my ($l1, $l2) = partition { fsedit::is_same_hd($_, $p) } @l;
	my ($p2) = @$l1 or next;
	@l = @$l2;

	$p->{mntpoint} = $p2->{mntpoint} if delete $p->{unsafeMntpoint};

	$p->{fs_type} = $p2->{fs_type} if $p2->{fs_type} && !$loose;
	$p->{options} = $p2->{options} if $p2->{options} && !$loose;
	#- important to get isMounted property else DrakX may try to mount already mounted partitions :-(
	add2hash($p, $p2);
	$p->{device_alias} ||= $p2->{device_alias} || $p2->{device} if $p->{device} ne $p2->{device} && $p2->{device} !~ m|/|;

	$p->{fs_type} && $p2->{fs_type} && $p->{fs_type} ne $p2->{fs_type}
	  && $p->{fs_type} ne 'auto' && $p2->{fs_type} ne 'auto' and
	    log::l("err, fstab and partition table do not agree for $p->{device} type: $p->{fs_type} vs $p2->{fs_type}");
    }
    @l;
}

sub analyze_wild_device_name {
    my ($dev) = @_;

    if ($dev =~ m!^/u?dev/(.*)!) {
	'dev', $dev;
    } elsif ($dev !~ m!^/! && (-e "/dev/$dev" || -e "$::prefix/dev/$dev")) {
	'dev', "/dev/$dev";
    } elsif ($dev =~ /^LABEL=(.*)/) {
	'label', $1;
    } elsif ($dev eq 'none' || $dev eq 'rootfs') {
	'virtual';
    } elsif ($dev =~ m!^(\S+):/\w!) {
	'nfs';
    } elsif ($dev =~ m!^//\w!) {
	'smb';
    } elsif ($dev =~ m!^http://!) {
	'dav';
    }
}

sub subpart_from_wild_device_name {
    my ($dev) = @_;

    my $part = { device => $dev, faked_device => 1 }; #- default

    if (my ($kind, $val) = analyze_wild_device_name($dev)) {
	if ($kind eq 'label') {	    
	    $part->{device_LABEL} = $val;
	} elsif ($kind eq 'dev') {
	    my %part = (faked_device => 0);
	    if (my $rdev = (stat "$::prefix$dev")[6]) {
		($part{major}, $part{minor}) = unmakedev($rdev);
	    }

	    my $symlink = readlink("$::prefix$dev");
	    $dev =~ s!/u?dev/!!;

	    if ($symlink && $symlink =~ m|^[^/]+$|) {