function reconnect() { global $gbl, $sgbl, $login, $ghtml; $this->__readserver = 'localhost'; $user = $sgbl->__var_admin_user; $db = $sgbl->__var_dbf; $pass = getAdminDbPass(); $readserver = $this->__readserver; $fdbvar = "__fdb_" . $this->__readserver; log_log("database_reconnect", "Reconnecting again"); if ($sgbl->__var_database_type === 'mysql') { $gbl->{$fdbvar} = mysql_connect($readserver, $user, $pass); mysql_select_db($db); self::$__database = 'mysql'; } else { if ($sgbl->__var_database_type === 'mssql') { //print("$user, $pass <br> \n"); //$gbl->$fdbvar = mssql_connect('\\.\pipe\MSSQL$LXLABS\sql\query'); $gbl->{$fdbvar} = mssql_pconnect("{$readserver},{$sgbl->__var_mssqlport}"); mssql_select_db($db); self::$__database = 'mssql'; } else { $gbl->{$fdbvar} = new PDO("sqlite:{$db}"); self::$__database = 'sqlite'; } } }
function changeSuperAdminPass() { if ($this->nname === 'superadmin') { $oldpass = getAdminDbPass(); $newp = client::createDbPass($this->realpass); $return = lfile_put_contents("__path_super_pass", $newp); if (!$return) { log_log("admin_error", "Admin pass change failed {$last_error}"); throw new lxException("could_not_change_superadmin_pass", ''); } $return = $sql->setPassword($newp); if ($return) { $return = lfile_put_contents("__path_super_pass", $oldpass); log_log("admin_error", "mysqladmin Failed . {$out}"); throw new lxException("could_not_change_superadmin_pass", ''); } } }
function connect() { global $gbl, $sgbl; $fdbvar = "__fdb_{$this->__readserver}"; if (!isset($gbl->{$fdbvar}) || $this->__force) { if (is_running_secondary()) { throw new lxexception("this_is_a_running_secondary_master", '', ""); } } $user = $sgbl->__var_admin_user; $db = $sgbl->__var_dbf; $pass = getAdminDbPass(); if ($sgbl->__var_database_type === 'mysql') { $gbl->{$fdbvar} = mysql_connect($this->__readserver, $user, $pass) or dprint("Could not connect to the MySql server.\n"); mysql_select_db($db) or dprint("Could not select {$db} MySQL database.\n"); self::$__database = 'mysql'; } else { if ($sgbl->__var_database_type === 'mssql') { //print("$user, $pass <br> \n"); //$gbl->$fdbvar = mssql_connect('\\.\pipe\MSSQL$LXLABS\sql\query'); $gbl->{$fdbvar} = mssql_pconnect("{$this->__readserver},{$sgbl->__var_mssqlport}") or dprint("Could not connect to the MSSQL server.\n"); mssql_select_db($db) or dprint("Could not select {$db} MSSQL database.\n"); self::$__database = 'mssql'; } else { try { $gbl->{$fdbvar} = new PDO("sqlite:{$db}"); self::$__database = 'sqlite'; } catch (PDOException $e) { dprint("PDO Error: " . $e->getMessage() . "\n"); } } } if (!$gbl->{$fdbvar}) { die("Could not open database connection."); } }
function do_remote_exec($machine, $rmt, $cmdtype, $nname, $dbaction) { global $gbl, $sgbl, $login, $ghtml; $remotechar = $sgbl->__var_remote_char; if ($login && $login->isSuperClient()) { $table = 'node'; $class = 'admin'; } else { $table = 'pserver'; $class = 'slave'; } if (!isLocalhost($machine)) { $var = $table . "_password"; if (isset($gbl->{$var}) && $gbl->{$var}) { $password = $gbl->{$var}; } else { $ssm = new Sqlite(null, $table); $res = $ssm->rawQuery("select realpass from {$table} where nname = '{$machine}'"); if ($res) { $password = $res[0]['realpass']; } else { throw new lxException("machine_doesnt_exist_in_db", 'nname', $machine); } } } else { $password = getAdminDbPass(); $machine = 'localhost'; } $port = $sgbl->__var_prog_port; $rmt->version = $sgbl->__ver_major_minor_release; $rmt->machine = $machine; $rmt->remote_login = $class; $rmt->password = $password; $rmt->master_c = getOneIPForLocalhost($machine); $var = base64_encode(serialize($rmt)); if (!isLocalhost($rmt->machine)) { $user = base64_encode('slave'); $pass = base64_encode($rmt->password); $var = $remotechar . "\n" . $user . "\n" . $pass . "\n" . $var; } $totalout = send_to_some_server($machine, $var); $res = unserialize(base64_decode($totalout)); if (!$res) { throw new lxException('could_not_connect_to_server', 'syncserver', $machine); } //dprint($res->message); if ($res->exception) { throw $res->exception; } //dprint($res->message); //print_time('server', "remote<b> $raddress</b>: $size KB", 2); // We have only return values. The output of the command is discarded. This leads to tremendous savings of bandwidth; makes the communication almost one way. If you want to get the output, you have to use the lxshell_output function and give your command as the argument. This function changes the output as a return value which is then returned back. The whole concept is about function execution, and returning the ret value of the function. $err = $res ? 3 : 2; dprint("<br> <table border=2> <tr> <td > Remote: {$machine}, {$cmdtype}, {$nname}, {$dbaction}<br> ", $err); if (!$res) { dprint("<b> <font color=red>Got Error: </b> </font> {$res}", $err); //$ser = base64_decode($res); //dprint($ser); } else { dprint("Message: " . $res->message . "<br> ", $err); } dprint("</td> </tr> </table> ", $err); if (!$res) { dprint("Warning"); } if ($res->__this_warning) { $gbl->__this_warning = $res->__this_warning; } return $res; }