function convert_disc_client()
{
    set_time_limit(3600);
    ini_set('default_socket_timeout', 360);
    global $sugar_config;
    require_once 'vendor/nusoap//nusoap.php';
    $errors = array();
    $server_url = "http://";
    $user_name = "";
    $admin_name = "";
    $password = "";
    $oc_install = false;
    if (empty($sugar_config['unique_key'])) {
        $sugar_config['unique_key'] = create_guid();
    }
    if (isset($_SESSION['oc_install']) && $_SESSION['oc_install'] == true) {
        $oc_install = true;
    }
    // run options are: convert, sync
    // default behavior of this page
    $run = "convert";
    if (!$oc_install) {
        if (isset($_REQUEST['run'])) {
            $run = $_REQUEST['run'];
        }
        if ($run == "convert") {
            if (isset($_REQUEST['server_url'])) {
                $server_url = $_REQUEST['server_url'];
                if ($server_url == "") {
                    $errors[] = "Server URL cannot be empty.";
                }
            }
        } else {
            if ($run == "sync") {
                $server_url = $sugar_config['sync_site_url'];
            }
        }
        if (isset($_REQUEST['user_name'])) {
            $user_name = $_REQUEST['user_name'];
            if ($user_name == "") {
                $errors[] = "User Name cannot be empty.";
            }
        }
        if (isset($_REQUEST['password'])) {
            if ($_REQUEST['password'] == "") {
                $errors[] = "Password cannot be empty.";
            } else {
                $password = $_REQUEST['password'];
            }
        }
    } else {
        //this is an offline client install
        if (isset($_SESSION['oc_run'])) {
            $run = $_SESSION['oc_run'];
        }
        if ($run == "convert") {
            if (isset($_SESSION['oc_server_url'])) {
                $server_url = $_SESSION['oc_server_url'];
                if ($server_url == "") {
                    $errors[] = "Server URL cannot be empty.";
                }
            }
        } else {
            if ($run == "sync") {
                $server_url = $sugar_config['sync_site_url'];
            }
        }
        if (isset($_SESSION['oc_username'])) {
            $user_name = $_SESSION['oc_username'];
            if ($user_name == "") {
                $errors[] = "User Name cannot be empty.";
            }
        }
        if (isset($_SESSION['oc_password'])) {
            if ($_SESSION['oc_password'] == "") {
                $errors[] = "Password cannot be empty.";
            } else {
                $password = $_SESSION['oc_password'];
            }
        }
    }
    //end check for offline client install
    if (!isset($_SESSION['is_oc_conversion']) || $_SESSION['is_oc_conversion'] == false) {
        $password = md5($password);
    }
    $sugar_config['oc_username'] = $user_name;
    $sugar_config['oc_password'] = $password;
    $sugar_config['oc_converted'] = false;
    $sugar_config['disc_client'] = true;
    if (isset($_SESSION['install_method'])) {
        $sugar_config['install_method'] = $_SESSION['install_method'];
    }
    if ((isset($_REQUEST['submitted']) || $oc_install) && sizeof($errors) == 0) {
        if (empty($server_url) || $server_url == 'http://') {
            $errors[] = "Server URL is required";
        } else {
            $sugar_config['sync_site_url'] = $server_url;
            $soapclient = new nusoapclient("{$server_url}/soap.php");
            $soapclient->response_timeout = 360;
            if ($soapclient->call('is_loopback', array())) {
                $errors[] = "Server and Client must be on separate machines with unique ip addresses";
            }
            $result = $soapclient->call('get_sugar_flavor', array());
            global $sugar_flavor, $sugar_version;
            if ($result != $sugar_flavor) {
                $errors[] = "Server and Client must both be running the same flavor of Sugar.";
            }
            if (!$soapclient->call('offline_client_available', array())) {
                $errors[] = "No licenses available for offline client";
            }
            $result = $soapclient->call('login', array('user_auth' => array('user_name' => $user_name, 'password' => $password, 'version' => '.01'), 'application_name' => 'Disconnected Client Setup'));
            if ($soapclient->error_str) {
                $errors[] = "Login failed with error: " . $soapclient->response;
            }
            if ($result['error']['number'] != 0) {
                $errors[] = "Login failed with error: " . $result['error']['name'] . ' ' . $result['error']['description'];
            }
            $session = $result['id'];
        }
        $errorString = "";
        if (!empty($errors)) {
            foreach ($errors as $error) {
                $errorString .= $error . "<br>";
            }
        }
        if ($session && empty($errors)) {
            if ($run == "convert") {
                // register this client/user with server
                // update local config.php file
                $install_method = 'web';
                if (isset($sugar_config['install_method'])) {
                    $install_method = $sugar_config['install_method'];
                }
                //attempt to obtain the system_id from the server
                //php_uname('n') will only work on a windows system
                $machine_name = php_uname('n');
                $soapclient->setHeaders('sugar_version=' . $sugar_version);
                $result = $soapclient->call('get_unique_system_id', array('session' => $session, 'unique_key' => $sugar_config['unique_key'], 'system_name' => $machine_name, 'install_method' => $install_method));
                if ($soapclient->error_str) {
                    $errors[] = "Unable to obtain unique system id from server: " . $soapclient->error_str;
                } else {
                    if ($result['error']['number'] != 0) {
                        $errors[] = $result['error']['description'];
                    } else {
                        $admin = BeanFactory::getBean('Administration');
                        $system_id = $result['id'];
                        if (!isset($system_id)) {
                            $system_id = 1;
                        }
                        $admin->saveSetting('system', 'system_id', $system_id);
                    }
                }
            }
            // data sync triggers
            if (empty($errors)) {
                require_once "modules/Sync/SyncHelper.php";
                sync_users($soapclient, $session, true, true);
                $sugar_config['oc_converted'] = true;
                echo 'Updating Local Information<br>';
                //echo 'Done - will auto logout in <div id="seconds_left">10</div> seconds<script> function logout_countdown(left){document.getElementById("seconds_left").innerHTML = left; if(left == 0){document.location.href = "index.php?module=Users&action=Logout";}else{left--; setTimeout("logout_countdown("+ left+")", 1000)}};setTimeout("logout_countdown(10)", 1000)</script>';
                // done with soap calls
                $result = $soapclient->call('logout', array('session' => $session));
                ksort($sugar_config);
                if (!write_array_to_file("sugar_config", $sugar_config, "config.php")) {
                    return;
                }
            }
        }
    }
    $errorString = "";
    foreach ($errors as $error) {
        $errorString .= $error . "<br>";
    }
    return $errorString;
}
function ConvertDiscClient()
{
    global $sugar_config;
    global $app_strings;
    global $app_list_strings;
    global $mod_strings;
    $xtpl = new XTemplate('modules/Administration/ConvertDiscClient.html');
    $xtpl->assign("MOD", $mod_strings);
    $xtpl->assign("APP", $app_strings);
    echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_UPGRADE_CONVERT_DISC_CLIENT_TITLE']), false);
    require_once 'vendor/nusoap//nusoap.php';
    $errors = array();
    $server_url = "http://";
    $user_name = "";
    $admin_name = "";
    $password = "";
    // run options are: convert, sync
    // default behavior of this page
    $run = "convert";
    if (isset($_REQUEST['run'])) {
        $run = $_REQUEST['run'];
    }
    if ($run == "convert") {
        if (isset($_REQUEST['server_url'])) {
            $server_url = $_REQUEST['server_url'];
            if ($server_url == "") {
                $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_SERVER_URL_EMPTY_ERROR'];
            }
        }
    } else {
        if ($run == "sync") {
            $server_url = $sugar_config['sync_site_url'];
        }
    }
    if (isset($_REQUEST['user_name'])) {
        $user_name = $_REQUEST['user_name'];
        if ($user_name == "") {
            $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_USER_NAME_EMPTY_ERROR'];
        }
    }
    if (isset($_REQUEST['password'])) {
        if ($_REQUEST['password'] == "") {
            $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_PASSWORD_EMPTY_ERROR'];
        }
    }
    if (isset($_REQUEST['admin_name'])) {
        $admin_name = $_REQUEST['admin_name'];
        if ($_REQUEST['admin_name'] == "") {
            $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_ADMIN_NAME_EMPTY'];
        }
    }
    if ($run == "convert") {
        if (!is_writable("config.php")) {
            $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_CONFIG_WRITABLE_ERROR'];
        }
    }
    if (isset($_REQUEST['submitted']) && sizeof($errors) == 0) {
        if (empty($server_url) || $server_url == 'http://') {
            $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_SERVER_URL_REQUIRED'];
        } else {
            $soapclient = new nusoapclient("{$server_url}/soap.php");
            $soapclient->response_timeout = 360;
            if ($soapclient->call('is_loopback', array())) {
                $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_SERVER_CLIENT_IP_ERROR'];
            }
            if (!$soapclient->call('offline_client_available', array())) {
                $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_NO_LICENSE'];
            }
            $result = $soapclient->call('login', array('user_auth' => array('user_name' => $admin_name, 'password' => md5($_REQUEST['password']), 'version' => '.01'), 'application_name' => 'Disconnected Client Setup'));
            if ($soapclient->error_str) {
                $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_LOGIN_FAILED_ERROR'] . $soapclient->error_str;
            }
            if ($result['error']['number'] != 0) {
                $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_LOGIN_FAILED_ERROR'] . $result['error']['name'] . ' ' . $result['error']['description'];
            }
            $session = $result['id'];
            if (empty($errors)) {
                $data = array($user_name);
                $result = $soapclient->call('sudo_user', array('session' => $session, 'user_name' => $user_name));
                if ($soapclient->error_str) {
                    $errors[] = string_format($mod_strings['LBL_CONVERT_DISC_CLIENT_SWITCH_TO_USER_ERROR'], $data) . $soapclient->error_str;
                }
                if (isset($result['error']) && $result['error']['number'] != 0) {
                    $errors[] = string_format($mod_strings['LBL_CONVERT_DISC_CLIENT_SWITCH_TO_USER_ERROR'], $data) . $result['error']['name'] . ' ' . $result['error']['description'];
                }
            }
        }
        $errorString = "";
        if (!empty($errors)) {
            foreach ($errors as $error) {
                $errorString .= $error . "<br>";
            }
        }
        echo '<font color="red"> ' . $errorString . '</font>';
        if ($session && empty($errors)) {
            if ($run == "convert") {
                // register this client/user with server
                // update local config.php file
                $sugar_config['disc_client'] = true;
                $sugar_config['sync_site_url'] = $server_url;
                //attempt to obtain the system_id from the server
                $result = $soapclient->call('get_unique_system_id', array('session' => $session, 'unique_key' => $sugar_config['unique_key']));
                if ($soapclient->error_str) {
                    $errors[] = $mod_strings['LBL_CONVERT_DISC_CLIENT_UNIQUE_SYSTEM_ID_ERROR'] . $soapclient->error_str;
                } else {
                    $admin = BeanFactory::getBean('Administration');
                    $system_id = $result['id'];
                    if (!isset($system_id)) {
                        $system_id = 1;
                    }
                    $admin->saveSetting('system', 'system_id', $system_id);
                }
            }
            // run the file sync
            require_once "include/utils/disc_client_utils.php";
            disc_client_file_sync($soapclient, $session, true);
            // data sync triggers
            require_once "modules/Sync/SyncHelper.php";
            sync_users($soapclient, $session, true);
            ksort($sugar_config);
            echo $mod_strings['LBL_CONVERT_DISC_CLIENT_UPDATE_LOCAL_INFO'];
            if (!write_array_to_file("sugar_config", $sugar_config, "config.php")) {
                $xtpl->assign("COMPLETED_MESSAGE", $mod_strings['LBL_CONVERT_DISC_CLIENT_CONFIG_WRITABLE_AGAIN_ERROR']);
                $xtpl->parse("main.complete");
                return;
            }
            echo $mod_strings['LBL_CONVERT_DISC_CLIENT_DONE_LOGOUT'] . '<script> function logout_countdown(left){document.getElementById("seconds_left").innerHTML = left; if(left == 0){document.location.href = "index.php?module=Users&action=Logout";}else{left--; setTimeout("logout_countdown("+ left+")", 1000)}};setTimeout("logout_countdown(10)", 1000)</script>';
            // done with soap calls
            $result = $soapclient->call('logout', array('session' => $session));
            $xtpl->assign("COMPLETED_MESSAGE", $mod_strings['LBL_CONVERT_DISC_CLIENT_SYNC_COMPLETE']);
            $xtpl->parse("main.complete");
            return;
        }
    }
    $errorString = "";
    foreach ($errors as $error) {
        $errorString .= $error . "<br>";
    }
    if (!empty($errorString)) {
        $xtpl->assign("COMPLETED_MESSAGE", $errorString);
        $xtpl->parse("main.complete");
    }
    if ($run == "convert" && isset($sugar_config['disc_client']) && $sugar_config['disc_client'] == true) {
        $xtpl->parse("main.existing");
    } else {
        if ($run == "convert") {
            $xtpl->assign("SERVER_URL", $server_url);
        }
        $xtpl->assign("USER_NAME", $user_name);
        $xtpl->assign("ADMIN_NAME", $admin_name);
        $xtpl->assign("SUBMITTTED", "true");
        $xtpl->assign("RUN", $run);
        if ($run == "convert") {
            $xtpl->assign("SUBMIT_MESSAGE", $mod_strings['LBL_CONVERT_DISC_CLIENT_SUBMIT']);
        } else {
            if ($run == "sync") {
                $xtpl->assign("SUBMIT_MESSAGE", $mod_strings['LBL_CONVERT_DISC_CLIENT_SYNC_SUBMIT']);
            }
        }
        $xtpl->parse("main.convert");
    }
    $xtpl->parse("main");
    $xtpl->out("main");
}
Example #3
0
function emergency_user($uid)
{
    if ($uid == null) {
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Checking uid:{$uid}\n";
    }
    $user = new user($uid);
    $ou = $user->ou;
    if ($GLOBALS["VERBOSE"]) {
        echo "Checking OU:{$ou}\n";
    }
    if ($ou == null) {
        echo "Checking {$uid} no such organization\n";
        return;
    }
    $ldap = new clladp();
    $info = $ldap->OUDatas($ou);
    $zarafaEnabled = 1;
    if (!$info["objectClass"]["zarafa-company"]) {
        $dn = "ou={$ou},dc=organizations,{$ldap->suffix}";
        $upd["objectClass"] = "zarafa-company";
        if (!$ldap->Ldap_add_mod("{$dn}", $upd)) {
            echo $ldap->ldap_last_error;
            return;
        }
    }
    sync_users();
    orphans();
}
Example #4
0
        if (isset($_GET[$url_param])) {
            $url_params[] = $url_param . '=' . $_GET[$url_param];
        }
    }
    $redirect_url = 'admin.php';
    if (count($url_params) > 0) {
        $redirect_url .= '?' . implode('&amp;', $url_params);
    }
    redirect($redirect_url);
}
// +-----------------------------------------------------------------------+
// | Synchronize user informations                                         |
// +-----------------------------------------------------------------------+
// sync_user() is only useful when external authentication is activated
if ($conf['external_authentification']) {
    sync_users();
}
// +-----------------------------------------------------------------------+
// | Variables init                                                        |
// +-----------------------------------------------------------------------+
$change_theme_url = PHPWG_ROOT_PATH . 'admin.php?';
$test_get = $_GET;
unset($test_get['page']);
unset($test_get['section']);
unset($test_get['tag']);
if (count($test_get) == 0 and !empty($_SERVER['QUERY_STRING'])) {
    $change_theme_url .= str_replace('&', '&amp;', $_SERVER['QUERY_STRING']) . '&amp;';
}
$change_theme_url .= 'change_theme=1';
// ?page=plugin-community-pendings is an clean alias of
// ?page=plugin&section=community/admin.php&tab=pendings
Example #5
0
                 $db =& DBManagerFactory::getInstance();
                 $query = "DELETE FROM versions WHERE name='Rebuild Extensions'";
                 $db->query($query);
                 // insert a new database row to show the rebuild extensions is done
                 $id = create_guid();
                 $gmdate = TimeDate::getInstance()->nowDb();
                 $date_entered = db_convert("'{$gmdate}'", 'datetime');
                 $query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) ' . "VALUES ('{$id}', '0', {$date_entered}, {$date_entered}, '1', '1', 'Rebuild Extensions', '4.0.0', '4.0.0')";
                 $db->query($query);
                 $current_step++;
                 update_progress_bar('sync_setup', $current_step, $module_steps);
                 add_to_msg('Done updating files<br>');
                 add_to_msg('Updating User Information<br>');
                 $current_step++;
                 update_progress_bar('sync_setup', $current_step, $module_steps);
                 sync_users($soapclient, $session, $_REQUEST['clean_sync']);
                 $current_step++;
                 update_progress_bar('sync_setup', $current_step, $module_steps);
                 add_to_msg('Done Updating User Information<br>');
             }
             //end new sync
             destroy_flow_bar('file_update');
             echo '<script>document.location.href = "index.php?&action=Popup&module=Sync&sync_module_index=0&new_sync=true&clean_sync=' . $_REQUEST['clean_sync'] . '&global_accept_server=' . $_REQUEST['global_accept_server'] . '";</script>';
             die;
         }
     } else {
         add_to_msg('Server and Client must both be running the same flavor of Sugar.');
     }
 } else {
     add_to_msg('Your Offline Client instance has been disabled by your administrator');
 }