Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sub askSqlRootUser
- {
- my ($dialog) = @_;
- my $host = $main::imscpConfig{'SQL_SERVER'} eq 'remote_server' ? '' : 'localhost';
- my $port = 3306;
- my $user = 'root';
- my $pwd = '';
- my ($rs, $msg) = (0, '');
- if($host eq 'localhost') {
- # If authentication is made through unix socket, password is normally not required.
- # We try a connect without password with 'root' as user and we return on success
- return 0 unless tryDbConnect($host, $port, $user, $pwd);
- }
- do {
- ($rs, $host) = $dialog->inputbox(<<"EOF", $host, 'utf-8') unless $host eq 'localhost';
- Please enter your SQL server hostname or IP address:$msg
- EOF
- $msg = $host eq '' ? "\n\n\\Z1SQL server hostname or IP address is required.\\Zn\n\nPlease try again:" : '';
- } while($rs < 30 && $msg ne '');
- return $rs if $rs >= 30;
- do {
- ($rs, $port) = $dialog->inputbox(<<"EOF", $port) unless $host eq 'localhost';
- Please enter your SQL server port:$msg
- EOF
- $msg = $port eq '' ? "\n\n\\Z1A SQL server port is required.\\Zn\n\nPlease try again:" : '';
- } while($rs < 30 && $msg ne '');
- return $rs if $rs >= 30;
- do {
- ($rs, $user) = $dialog->inputbox(<<"EOF", $user);
- Please enter your SQL root username:$msg
- Note that this user must have full privileges on the SQL server.
- i-MSCP only uses that user while installation or reconfiguration.
- EOF
- $msg = $user eq '' ? "\n\n\\Z1A SQL root user is required.\\Zn\n\nPlease try again:" : '';
- } while($rs < 30 && $msg) ne '';
- return $rs if $rs >= 30;
- do {
- ($rs, $pwd) = $dialog->passwordbox(<<"EOF");
- Please enter your SQL root user password:$msg
- EOF
- $msg = $pwd eq '' ? "\n\n\\Z1SQL root user password is required.\\Zn\n\nPlease try again:" : '';
- } while($rs < 30 && $msg);
- return $rs if $rs >= 30;
- if(my $connectError = tryDbConnect($host, $port, $user, $pwd)) {
- $rs = $dialog->msgbox(<<"EOF");
- \\Z1Connection to SQL server failed\\Zn
- i-MSCP installer could not connect to SQL server using the following data:
- \\Z4Host:\\Zn $host
- \\Z4Port:\\Zn $port
- \\Z4Username:\\Zn $user
- \\Z4Password:\\Zn $pwd
- Error was: \\Z1$connectError\\Zn
- Please try again.
- EOF
- goto &{askSqlRootUser} unless $rs >= 30;
- }
- if($rs < 30) {
- setupSetQuestion('DATABASE_TYPE', 'mysql');
- setupSetQuestion('DATABASE_HOST', $host);
- setupSetQuestion('DATABASE_PORT', $port);
- }
- $rs;
- }
- sub askMasterSqlUser
- {
- my $dialog = shift;
- my $host = setupGetQuestion('DATABASE_HOST');
- my $port = setupGetQuestion('DATABASE_PORT');
- my $user = setupGetQuestion('DATABASE_USER', 'imscp_user');
- my $pwd = setupGetQuestion('DATABASE_PASSWORD');
- my ($rs, $msg) = (0, '');
- $pwd = decryptBlowfishCBC($main::imscpDBKey, $main::imscpDBiv, $pwd) unless $pwd eq '' || iMSCP::Getopt->preseed;
- if(grep($_ eq $main::reconfigure, ( 'sql', 'servers', 'all', 'forced' ))
- || $host eq '' || $port eq '' || $user eq '' || $user eq 'root' || $pwd eq ''
- || tryDbConnect($host, $port, $user, $pwd)
- ) {
- $rs = askSqlRootUser($dialog);
- return $rs if $rs >= 30;
- do {
- ($rs, $user) = $dialog->inputbox( <<"EOF", $msg eq '' ? $user : '' );
- Please enter a username for the master i-MSCP SQL username:$msg
- EOF
- if ($user eq 'root') {
- $msg = "\n\n\\Z1Usage of SQL root user is disallowed. \\Zn\n\nPlease try again:";
- } elsif (length $user > 16) {
- $msg = "\n\n\\Username can be up to 16 characters long.\\Zn\n\nPlease try again:";
- } elsif (length $user < 6) {
- $msg = "\n\n\\Z1Username must be at least 6 characters long.\\Zn\n\nPlease try again:";
- } elsif ($user !~ /^[\x21-\x5b\x5d-\x7e]+$/) {
- $msg = "\n\n\\Z1Only printable ASCII characters (excepted space and backslash) are allowed.\\Zn\n\nPlease try again:";
- } else {
- $msg = '';
- }
- } while ($rs < 30 && $msg ne '');
- if ($rs < 30) {
- $pwd = '';
- do {
- ($rs, $pwd) = $dialog->passwordbox( <<"EOF", $msg eq '' ? $pwd : '');
- Please enter a password for the master i-MSCP SQL user (blank for autogenerate):$msg
- EOF
- if ($pwd ne '' && length $pwd < 6) {
- $msg = "\n\n\\Z1Password must be at least 6 characters long.\\Zn\n\nPlease try again:";
- } elsif ($pwd =~ /[^\x21-\x5b\x5d-\x7e]/) {
- $msg = "\n\n\\Z1Only printable ASCII characters (excepted space and backslash) are allowed.\\Zn\n\nPlease try again:";
- } else {
- $msg = '';
- }
- } while ($rs < 30 && $msg ne '');
- if ($rs < 30) {
- unless ($pwd) {
- my @allowedChr = map { chr } (0x21 .. 0x5b, 0x5d .. 0x7e);
- $pwd = '';
- $pwd .= $allowedChr[rand @allowedChr] for 1 .. 16;
- }
- $dialog->msgbox( <<"EOF" );
- Password for master i-MSCP SQL user set to: $pwd
- EOF
- }
- }
- }
- if($rs < 30) {
- setupSetQuestion('DATABASE_USER', $user);
- setupSetQuestion('DATABASE_PASSWORD', $pwd)
- }
- $rs;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement