Exemplo n.º 1
0
/**
 * Changes a MySQL user password
 *
 * @since 1.0
 * @package facileManager
 * @subpackage fmSQLPass
 *
 * @param string $server_name Hostname of the database server
 * @param integer $server_port Server port to connect to
 * @param string $admin_user User to login with
 * @param string $admin_pass User password to login with
 * @param string $user Database user to change
 * @param string $user_password New password
 * @param string $server_group Server group to process
 * @return string
 */
function changeMySQLUserPassword($server_name, $server_port, $admin_user, $admin_pass, $user, $user_password, $server_group)
{
    global $__FM_CONFIG;
    /** Connect to remote server */
    $verbose_output = ' --> Connecting to MySQL ';
    if (!socketTest($server_name, $server_port, 5)) {
        return $verbose_output . "[failed] - Could not connect to {$server_name} on tcp/{$server_port}\n";
    }
    $remote_connection = @new mysqli($server_name, $admin_user, $admin_pass, null, $server_port);
    if (!$remote_connection->connect_error) {
        $verbose_output .= "[ok]\n";
    } else {
        $verbose_output .= '[failed] - ' . $remote_connection->connect_error . "\n";
        return $verbose_output;
    }
    /** Ensure database user exists before changing the password */
    $verbose_output .= " --> Verifying {$user} exists ";
    list($user_login, $user_host) = explode('@', $user);
    $user_host_query = !empty($user_host) ? "AND Host='{$user_host}'" : null;
    if ($result = $remote_connection->query("SELECT User FROM mysql.user WHERE User='******' {$user_host_query}")) {
        if ($result->num_rows) {
            $verbose_output .= "[ok]\n --> Updating the password for {$user} ";
            $remote_connection->query("UPDATE mysql.user SET Password=PASSWORD('{$user_password}') WHERE User='******' {$user_host_query}");
            if ($remote_connection->affected_rows > 0) {
                $verbose_output .= "[ok]\n";
                /** Update last changed */
                basicUpdate('fm_' . $__FM_CONFIG['fmSQLPass']['prefix'] . 'groups', $server_group, 'group_pwd_change', time(), 'group_id');
                /** Flush privileges */
                $verbose_output .= ' --> Flushing privileges ';
                $remote_connection->query('FLUSH PRIVILEGES');
                $verbose_output .= $remote_connection->error ? '[failed] - ' . $remote_connection->error . "\n" : "[ok]\n";
                /** Log entry */
                addLogEntry("Updated MySQL Account ({$server_name} : {$user}).");
            } else {
                $verbose_output .= '[failed] - ';
                $verbose_output .= $remote_connection->error ? $remote_connection->error . "\n" : "Password for {$user} was not different.\n";
            }
        } else {
            $verbose_output .= "[failed] - User account ({$user}) does not exist.\n";
        }
    } else {
        $verbose_output .= '[failed] - ' . $remote_connection->error . "\n";
    }
    $remote_connection->close();
    return $verbose_output;
}
Exemplo n.º 2
0
     } else {
         if (getOption('client_auto_register')) {
             /** Add new server */
             $add_server = moduleAddServer('add');
             if ($add_server !== true) {
                 $data = _('Could not add server to account.') . "\n";
             }
         } else {
             $data = _('Client automatic registration is not allowed.') . "\n";
         }
     }
 }
 /** Client installs */
 if (array_key_exists('install', $_GET)) {
     /** Set flags */
     $data = basicUpdate('fm_' . $__FM_CONFIG[$_POST['module_name']]['prefix'] . 'servers', $_POST['SERIALNO'], 'server_installed', 'yes', 'server_serial_no');
     if (function_exists('moduleCompleteClientInstallation')) {
         moduleCompleteClientInstallation();
     }
     $fm_shared_module_servers->updateClientVersion();
 }
 /** Client upgrades */
 if (array_key_exists('upgrade', $_GET)) {
     if (!isset($__FM_CONFIG[$_POST['module_name']]['min_client_auto_upgrade_version'])) {
         $__FM_CONFIG[$_POST['module_name']]['min_client_auto_upgrade_version'] = 0;
     }
     $current_module_version = getOption('client_version', 0, $_POST['module_name']);
     if ($_POST['server_client_version'] == $current_module_version) {
         $data = sprintf(_("Latest version: %s\nNo upgrade available."), $current_module_version) . "\n";
     } elseif (version_compare($_POST['server_client_version'], $__FM_CONFIG[$_POST['module_name']]['min_client_auto_upgrade_version'], '<')) {
         $data = sprintf(_("Latest version: %s\nThis upgrade requires a manual installation."), $current_module_version) . "\n";
Exemplo n.º 3
0
 /**
  * Assigns SOA to domain_id
  *
  * @since 1.3
  * @package facileManager
  * @subpackage fmDNS
  *
  * @param id $soa_id SOA ID to assign
  * @param id $domain_id Domain ID to assign to
  * @return boolean
  */
 function assignSOA($soa_id, $domain_id)
 {
     global $__FM_CONFIG, $fm_dns_zones;
     $old_soa_id = getNameFromID($domain_id, "fm_{$__FM_CONFIG['fmDNS']['prefix']}domains", 'domain_', 'domain_id', 'soa_id');
     if (basicUpdate("fm_{$__FM_CONFIG['fmDNS']['prefix']}domains", $domain_id, 'soa_id', $soa_id, 'domain_id')) {
         /** Delete old custom SOA */
         if (getNameFromID($old_soa_id, "fm_{$__FM_CONFIG['fmDNS']['prefix']}soa", 'soa_', 'soa_id', 'soa_template') == 'no') {
             updateStatus("fm_{$__FM_CONFIG['fmDNS']['prefix']}soa", $old_soa_id, 'soa_', 'deleted', 'soa_id');
         }
         if (!isset($fm_dns_zones)) {
             include ABSPATH . 'fm-modules/' . $_SESSION['module'] . '/classes/class_zones.php';
         }
         /** Update the SOA serial number */
         foreach ($fm_dns_zones->getZoneTemplateChildren($domain_id) as $child_id) {
             $domain_id = getParentDomainID($child_id);
             if (reloadAllowed($domain_id) && getSOACount($domain_id) && getNSCount($domain_id)) {
                 $this->updateSOAReload($child_id, 'yes');
             }
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Updates the selected zone
  */
 function update()
 {
     global $fmdb, $__FM_CONFIG;
     $domain_id = sanitize($_POST['domain_id']);
     /** Validate post */
     $_POST['domain_mapping'] = getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_mapping');
     $_POST['domain_type'] = getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_type');
     $post = $this->validatePost($_POST);
     if (!is_array($post)) {
         return $post;
     }
     $sql_edit = $domain_name_servers = $domain_view = null;
     $old_name = displayFriendlyDomainName(getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'domains', 'domain_', 'domain_id', 'domain_name'));
     $log_message = "Updated a zone ({$old_name}) with the following details:\n";
     /** If changing zone to clone or different domain_type, are there any existing associated records? */
     if ($post['domain_clone_domain_id'] || $post['domain_type'] != 'master') {
         basicGet('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'records', $domain_id, 'record_', 'domain_id');
         if ($fmdb->num_rows) {
             return __('There are associated records with this zone.');
         }
     }
     /** Format domain_view */
     $log_message_views = null;
     if (is_array($post['domain_view'])) {
         foreach ($post['domain_view'] as $val) {
             if ($val == 0) {
                 $domain_view = 0;
                 break;
             }
             $domain_view .= $val . ';';
             $view_name = getNameFromID($val, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'views', 'view_', 'view_id', 'view_name');
             $log_message_views .= $val ? "{$view_name}; " : null;
         }
         $post['domain_view'] = rtrim($domain_view, ';');
     }
     /** Format domain_name_servers */
     $log_message_name_servers = null;
     foreach ($post['domain_name_servers'] as $val) {
         if ($val == '0') {
             $domain_name_servers = 0;
             break;
         }
         $domain_name_servers .= $val . ';';
         $server_name = getNameFromID($val, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'servers', 'server_', 'server_id', 'server_name');
         $log_message_name_servers .= $val ? "{$server_name}; " : null;
     }
     $post['domain_name_servers'] = rtrim($domain_name_servers, ';');
     if (!$post['domain_name_servers']) {
         $post['domain_name_servers'] = 0;
     }
     $exclude = array('submit', 'action', 'domain_id', 'domain_required_servers', 'domain_forward');
     foreach ($post as $key => $data) {
         if (!in_array($key, $exclude)) {
             $sql_edit .= strlen(sanitize($data)) ? $key . "='" . mysql_real_escape_string($data) . "'," : $key . '=NULL,';
             if ($key == 'domain_view') {
                 $data = $log_message_views;
             }
             if ($key == 'domain_name_servers') {
                 $data = $log_message_name_servers;
             }
             $log_message .= $data ? formatLogKeyData('domain_', $key, $data) : null;
             if ($key == 'domain_default' && $data == 'yes') {
                 $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` SET {$key} = 'no' WHERE `account_id`='{$_SESSION['user']['account_id']}'";
                 $result = $fmdb->query($query);
             }
         }
     }
     $sql_edit .= "domain_reload='no'";
     /** Set the server_build_config flag for existing servers */
     if (getSOACount($domain_id) && getNSCount($domain_id)) {
         setBuildUpdateConfigFlag(getZoneServers($domain_id, array('masters', 'slaves')), 'yes', 'build');
     }
     /** Update the zone */
     $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` SET {$sql_edit} WHERE `domain_id`='{$domain_id}' AND `account_id`='{$_SESSION['user']['account_id']}'";
     $result = $fmdb->query($query);
     if ($fmdb->sql_errors) {
         return __('Could not update the zone because a database error occurred.');
     }
     $rows_affected = $fmdb->rows_affected;
     /** Update the child zones */
     if ($post['domain_template'] == 'yes') {
         $query = "UPDATE `fm_{$__FM_CONFIG['fmDNS']['prefix']}domains` SET domain_view='{$post['domain_view']}' WHERE `domain_template_id`='{$domain_id}' AND `account_id`='{$_SESSION['user']['account_id']}'";
         $result = $fmdb->query($query);
         if ($fmdb->sql_errors) {
             return __('Could not update the child zones because a database error occurred.');
         }
         $rows_affected += $fmdb->rows_affected;
     }
     /** Add mandatory config options */
     $query = "INSERT INTO `fm_{$__FM_CONFIG['fmDNS']['prefix']}config` \n\t\t\t(account_id,domain_id,cfg_name,cfg_data) VALUES ({$_SESSION['user']['account_id']}, {$domain_id}, ";
     $required_servers = sanitize($post['domain_required_servers']);
     if (!$post['domain_template_id']) {
         if ($post['domain_type'] == 'forward') {
             if (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='forwarders'")) {
                 basicUpdate("fm_{$__FM_CONFIG['fmDNS']['prefix']}config", getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_id', null, "AND cfg_name='forwarders'"), 'cfg_data', $required_servers, 'cfg_id');
             } else {
                 $result = $fmdb->query($query . "'forwarders', '" . $required_servers . "')");
             }
             $log_message .= formatLogKeyData('domain_', 'forwarders', $required_servers);
             $domain_forward = sanitize($post['domain_forward'][0]);
             if (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='forward'")) {
                 basicUpdate("fm_{$__FM_CONFIG['fmDNS']['prefix']}config", getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_id', null, "AND cfg_name='forward'"), 'cfg_data', $domain_forward, 'cfg_id');
             } else {
                 $result = $fmdb->query($query . "'forward', '" . $domain_forward . "')");
             }
             $log_message .= formatLogKeyData('domain_', 'forward', $domain_forward);
         } elseif (in_array($post['domain_type'], array('slave', 'stub'))) {
             if (getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_data', null, "AND cfg_name='masters'")) {
                 basicUpdate("fm_{$__FM_CONFIG['fmDNS']['prefix']}config", getNameFromID($domain_id, 'fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'config', 'cfg_', 'domain_id', 'cfg_id', null, "AND cfg_name='masters'"), 'cfg_data', $required_servers, 'cfg_id');
             } else {
                 $query .= "'masters', '" . $required_servers . "')";
                 $result = $fmdb->query($query);
             }
             $log_message .= formatLogKeyData('domain_', 'masters', $required_servers);
         }
     } else {
         /** Remove all zone config options */
         basicDelete("fm_{$__FM_CONFIG['fmDNS']['prefix']}config", $domain_id, 'domain_id');
     }
     if ($fmdb->sql_errors) {
         return __('Could not update zone because a database error occurred.') . ' ' . $fmdb->last_error;
     }
     /** Return if there are no changes */
     if ($rows_affected + ($fmdb->rows_affected = 0)) {
         return true;
     }
     /** Set the server_build_config flag for new servers */
     if (getSOACount($domain_id) && getNSCount($domain_id)) {
         setBuildUpdateConfigFlag(getZoneServers($domain_id, array('masters', 'slaves')), 'yes', 'build');
     }
     /** Delete associated records from fm_{$__FM_CONFIG['fmDNS']['prefix']}track_builds */
     basicDelete('fm_' . $__FM_CONFIG['fmDNS']['prefix'] . 'track_builds', $domain_id, 'domain_id', false);
     addLogEntry($log_message);
     return true;
 }
Exemplo n.º 5
0
 /**
  * Deletes the selected user
  *
  * @since 1.0
  * @package facileManager
  */
 function delete($id, $type = 'user')
 {
     global $fm_name;
     if ($type == 'user') {
         /** Ensure user is not current LDAP template user */
         if (getOption('auth_method') == 2) {
             $template_user_id = getOption('ldap_user_template');
             if ($id == $template_user_id) {
                 return _('This user is the LDAP user template and cannot be deleted at this time.');
             }
         }
         $field = 'user_login';
     } elseif ($type == 'group') {
         $field = 'group_name';
         if (basicUpdate('fm_users', $id, 'user_group', null, 'user_group') === false) {
             return _('This group could not be removed from the associated users.');
         }
     }
     $tmp_name = getNameFromID($id, 'fm_' . $type . 's', $type . '_', $type . '_id', $field);
     if (!updateStatus('fm_' . $type . 's', $id, $type . '_', 'deleted', $type . '_id')) {
         return sprintf(_('This %s could not be deleted.'), $type) . "\n";
     } else {
         addLogEntry(sprintf(_("Deleted %s '%s'."), $type, $tmp_name), $fm_name);
         return true;
     }
 }