Willkommen bei WordPress. Dies ist dein erster Beitrag. Bearbeite oder lösche ihn und beginne mit dem Schreiben!
Hallo Welt!
von raredesign | Dez 3, 2019 | Allgemein | 0 Kommentare
Cokiee Shell
Current Path : /proc/self/root/usr/local/siteapps/ODFaq-2.1.0-1/scripts/ |
Current File : //proc/self/root/usr/local/siteapps/ODFaq-2.1.0-1/scripts/postinstall |
#!/usr/bin/perl -w use strict; use File::Path; use File::Copy; my %params; my %psa_params; my @imp_params = qw( vhost_path domain_name install_prefix ssl_target_directory dbuser dbpasswd dbname admin_login admin_passwd ); my $is_error=0; sub print_out { my ($text) = @_; print STDERR $text; } sub check_parameter { my ($param) = @_; unless (defined $params{$param}){ return 0; } else { return 1; } } sub modify_file { my ($fname, $fparams) = @_; unless (open F, $fname){ print_out "postinstall: can't open file `$fname` for reading\n"; return 0; } my $file_content; while (<F>){ $file_content .= $_; } close F; my ($k,$v); while (($k,$v)=each(%$fparams)){ $file_content =~ s/\@\@${k}\@\@/$v/g; } unless (open F, ">$fname"){ print_out "postinstall: can't open file `$fname` for writing\n"; return 0; } print F $file_content; close F; return 1; } sub mysql_quote { my ($qstr) = @_; # replace ' for \' # replace \ for \\ $qstr =~ s/\\/\\\\/g; $qstr =~ s/'/\\'/g; return $qstr; } sub php_quote { my ($qstr) = @_; # replace ' for \' # replace \ for \\ $qstr =~ s/\\/\\\\/g; $qstr =~ s/'/\\'/g; return $qstr; } sub shell_quote { my ($qstr) = @_; # replace ' for \' # replace \ for \\ $qstr =~ s/\\/\\\\/g; $qstr =~ s/"/\\\"/g; $qstr =~ s/\$/\\\$/g; return $qstr; } # parse input to hash while (<STDIN>){ my ($k,$v); if (/^([^=]+)=(.+)$/){ $v = $2; chomp $v; $k = $1; $params{"$k"} = $v; } } # parse plesk config file open PSACONF, '/etc/psa/psa.conf'; while (<PSACONF>){ chomp; unless (/^#/){ if (/^(\s*[_a-zA-Z]+)\s+(.+?)\s*$/){ $psa_params{$1} = $2; } } } close PSACONF; # check important parameters foreach (@imp_params){ unless (check_parameter($_)){ print_out "postinstall: parameter `$_` not found\n"; $is_error = 1; } } if ($is_error){ exit 1; } # remote DB checking my ($dbhost, $dbport, $dbremote_params, $dbhostport); $dbremote_params = ''; $dbhost = 'localhost'; $dbhostport = $dbhost; if (defined $params{'dbhost'} && $params{'dbhost'} ne '') { my ($m_dbhost, $m_dbport); $dbhost = $params{'dbhost'}; $m_dbhost = shell_quote($dbhost); $dbremote_params = " --host=\"${m_dbhost}\" "; $dbhostport = $dbhost; if (defined $params{'dbport'} && $params{'dbport'} ne '') { $dbport = $params{'dbport'}; $dbhostport .= ":${dbport}"; $m_dbport = shell_quote($dbport); $dbremote_params .= " --port=\"${m_dbport}\" "; } } # check SSL my $ssl_enable; my $proto; my $documents_directory; if ($params{'ssl_target_directory'} eq 'true'){ $documents_directory = 'httpsdocs'; $ssl_enable = "1"; $proto = "https://"; } else { $documents_directory = 'httpdocs'; $ssl_enable = "0"; $proto = "http://"; } my $root_dir = $params{'vhost_path'}.'/'.$documents_directory.'/'.$params{'install_prefix'}; my $config_file = "${root_dir}/config.inc.php"; my $config_file_in = $config_file . '.in'; my $url = $proto.$params{'domain_name'}.'/'.$params{'install_prefix'}; # generate config file my %config_params = ( 'DBUSER' => php_quote($params{dbuser}), 'DBNAME' => php_quote($params{dbname}), 'DBPASSWD' => php_quote($params{dbpasswd}), 'DBHOSTPORT'=> php_quote($dbhostport), 'BASEURL' => php_quote($url), 'ROOTDIR' => php_quote($root_dir), 'INSTALL_PREFIX' => php_quote($params{install_prefix}), 'ADMIN_EMAIL' => php_quote($params{admin_email}), 'DOMAIN_NAME' => php_quote($params{domain_name}), 'CONFIG_DONE' => '1' ); unless (copy($config_file_in, $config_file)) { print_out "couldn't copy config file\n"; exit 1; } unless (modify_file($config_file, \%config_params)) { print_out "could't change file ${config_file}\n"; exit 1; } # import mysql data my $mysql_schema_file = "${root_dir}/schema.sql"; my %mysql_params = ( 'ADMIN_LOGIN' => mysql_quote($params{admin_login}), 'ADMIN_PASSWD' => mysql_quote($params{admin_passwd}), 'ADMIN_EMAIL' => mysql_quote($params{admin_email}), 'BASEURL' => mysql_quote($url), 'ROOTDIR' => php_quote($root_dir), 'DOMAIN_NAME' => php_quote($params{domain_name}), 'INSTALL_PREFIX' => php_quote($params{install_prefix}) ); unless (modify_file($mysql_schema_file, \%mysql_params)) { print_out "couldn't modify sql schema file\n"; exit 1; } # importing database my $mysql_bin = $psa_params{'MYSQL_BIN_D'}.'/mysql'; my ($m_dbuser, $m_dbpass, $m_dbname) = (shell_quote($params{'dbuser'}), shell_quote($params{'dbpasswd'}), shell_quote($params{'dbname'})); my $mysql_cmd = "${mysql_bin} ${dbremote_params} -u\"${m_dbuser}\" -p\"${m_dbpass}\" \"${m_dbname}\" <${mysql_schema_file}"; my $str_res = `$mysql_cmd`; if ($?){ print_out "unable to import sql data (`${mysql_schema_file}`):\n${str_res}\n"; exit 1; } # delete temporary and installation files unlink $mysql_schema_file; if (-e $mysql_schema_file) { print_out "unable to delete file `${mysql_schema_file}`: $!\nPlease remove it manually!"; exit 1; }
Cokiee Shell Web 1.0, Coded By Razor
Neueste Kommentare