/** * @return void * @param * @param * @desc A generic function, that can be used by all programs. Does all the basic login stuff. */ function initProgramlib($ctype = null) { global $gbl, $sgbl, $login, $ghtml; // /* // --- solution for some scripts running well in slave // REVERT - back to original if ($sgbl->is_this_slave()) { print "This is a Slave Server. Operate it at the Master server.\n"; exit; } // */ static $var = 0; $var++; $progname = $sgbl->__var_program_name; lfile_put_contents($sgbl->__var_error_file, ""); set_exception_handler("lx_exception_handler"); //xdebug_disable(); set_error_handler("lx_error_handler"); //setcookie("XDEBUG_SESSION", "sess"); if ($var >= 2) { dprint("initProgramlib called twice \n <br> "); } if ($ctype === 'superadmin') { $sgbl->__var_dbf = $sgbl->__path_supernode_db; $sgbl->__path_admin_pass = $sgbl->__path_super_pass; $sgbl->__var_admin_user = $sgbl->__var_super_user; $login = new SuperClient(null, null, 'superadmin', 'login', 'forced'); $login->get(); return; } else { if ($ctype === "guest") { $login = new Client(null, null, "____________", "guest"); $login->get(); return; } else { if ($ctype != "") { $login = new Client(null, null, $ctype, "login", "forced"); $login->get(); return; } } } $sessobj = null; if ($ghtml->frm_consumedlogin === 'true') { $clientname = $_COOKIE["{$progname}-consumed-clientname"]; $classname = $_COOKIE["{$progname}-consumed-classname"]; $session_id = $_COOKIE["{$progname}-consumed-session-id"]; get_login($classname, $clientname); $login->__session_id = $session_id; $sessobj = $login->getObject('ssession'); } else { if (isset($_COOKIE["{$progname}-session-id"])) { $clientname = $_COOKIE["{$progname}-clientname"]; $classname = $_COOKIE["{$progname}-classname"]; $session_id = $_COOKIE["{$progname}-session-id"]; if ($classname === 'superclient') { $sgbl->__var_dbf = $sgbl->__path_supernode_db; $sgbl->__path_admin_pass = $sgbl->__path_super_pass; $sgbl->__var_admin_user = $sgbl->__var_super_user; } if ($classname === 'slave') { $sgbl->__var_dbf = $sgbl->__path_slave_db; } if ($classname) { get_login($classname, $clientname); $login->__session_id = $session_id; $sessobj = $login->getObject('ssession'); } } } if (!$sessobj || $sessobj->dbaction === 'add') { if ($ghtml->frm_ssl) { $ssl = unserialize(base64_decode($ghtml->frm_ssl)); $string = $ssl['string']; $ssl_param = $ssl['ssl_param']; $encrypted_string = base64_decode($ssl['encrypted_string']); if (!$string || !checkPublicKey($string, $encrypted_string)) { print "SSL Connection Failed <br> \n"; exit; } $class = 'client'; $clientname = 'admin'; get_login($class, $clientname); do_login($class, $clientname, $ssl_param); $sessobj = $gbl->c_session; $sessobj->write(); $sessobj->dbaction = 'clean'; } } //get_savedlogin($classname, $clientname); //print_time('login_get', "Login Get"); //dprintr($login); //avoid some php warnings if (isset($login)) { $gbl->client = $login->nname; $gbl->client_ttype = $login->cttype; } //dprintr($login->hpfilter); // This means the session object got created fresh. if (!$sessobj || $sessobj->dbaction === 'add') { dprint("Session id is empty. Clearing cookies and redirect to login."); clear_all_cookie(); $ghtml->print_redirect_self("/login/"); } $gbl->c_session = $sessobj; if ($login->getClName() !== $sessobj->parent_clname) { dprint_r($login->ssession_l); dprint(" <br> {$session_id} <br> <br> <br> "); print "Session error! Login again."; clear_all_cookie(); $ghtml->print_redirect_self("/login/?frm_emessage=sessionname_not_client"); } $gen = $login->getObject('general')->generalmisc_b; if (!$gen->isOn('disableipcheck') && $_SERVER['REMOTE_ADDR'] != $sessobj->ip_address) { $hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']); log_message("An attempt to hack from {$hostname} (" . $_SERVER['REMOTE_ADDR'] . ") with sess {$sessobj->nname}, session ip: {$sessobj->ip_address}"); if ($gen->isOn('disableipcheck')) { } else { clear_all_cookie(); if ($gbl->c_session->ssl_param) { $sessobj->delete(); $sessobj->write(); $ghtml->print_redirect("{$gbl->c_session->ssl_param['backurl']}&frm_emessage=ipaddress_changed_amidst_session"); } else { $ghtml->print_redirect_self("/login/?frm_emessage=ipaddress_changed_amidst_session"); } } } if (intval($login->getSpecialObject('sp_specialplay')->ssession_timeout) <= 100) { $login->getSpecialObject('sp_specialplay')->ssession_timeout = 100; $login->setUpdateSubaction(); } $timeout = $sessobj->last_access + $login->getSpecialObject('sp_specialplay')->ssession_timeout; $sessobj->timeout = $timeout; //$timeout = $sessobj->last_access + 4; $sessobj->last_access = time(); $sessobj->setUpdateSubaction(); if ($sessobj->auxiliary_id) { $aux = new Auxiliary(null, null, $sessobj->auxiliary_id); $aux->get(); $login->__auxiliary_object = $aux; } if (time() > $timeout) { $sessobj->delete(); $sessobj->write(); //print("session error timeout"); if ($gbl->c_session->ssl_param) { $ghtml->print_redirect("{$gbl->c_session->ssl_param['backurl']}&frm_emessage=session_timeout"); } else { $ghtml->print_redirect_self("/login/?frm_emessage=session_timeout"); } } addToUtmp($sessobj, 'update'); }
function add_admin($pass) { global $gbl, $sgbl, $login, $ghtml; $client = new Client(null, null, 'admin'); $login = $client; $client->initThisDef(); $client->priv->pserver_num = 'Unlimited'; $client->priv->maindomain_num = 'Unlimited'; $client->priv->vps_num = 'Unlimited'; $client->priv->client_num = 'Unlimited'; $client->ddate = time(); $ddb = new Sqlite(null, "client"); if (!$ddb->existInTable("nname", 'admin')) { if ($sgbl->dbg > 0) { $pass = '******'; $res['contacemail'] = '*****@*****.**'; } $res['password'] = crypt($pass); $res['cttype'] = 'admin'; $res['cpstatus'] = 'on'; if (if_demo()) { $res['email'] = "*****@*****.**"; } $client->create($res); $client->driverApp = new client__sync(null, null, 'admin'); $client->was(); lxfile_mkdir("__path_client_root/{$client->nname}"); lxfile_generic_chown("__path_client_root/{$client->nname}", "lxlabs"); } $notif = new Notification(null, null, $client->getClName()); $notif->initThisDef(); $notif->dbaction = 'add'; $notif->text_newaccountmessage = lfile_get_contents("__path_program_root/file/welcome.txt"); $notif->parent_clname = $client->getClName(); $notif->write(); $display = new sp_SpecialPlay(null, null, $client->getClName()); $display->initThisDef(); $display->parent_clname = $client->getClName(); $display->dbaction = 'add'; $display->write(); }