/** * UpdateUserProfile * * @param $user_id * @param $pass1 * @param $hideOffline * @param $theme * @param $language */ function UpdateUserProfile($user_id, $pass1, $hideOffline, $theme, $language) { global $cfg, $db; if (empty($hideOffline) || $hideOffline == "" || !isset($hideOffline)) { $hideOffline = "0"; } // update values $rec = array(); if ($pass1 != "") { $rec['password'] = md5($pass1); AuditAction($cfg["constants"]["update"], $cfg['_PASSWORD']); } $sql = "select * from tf_users where user_id = " . $db->qstr($user_id); $rs = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } $rec['hide_offline'] = $hideOffline; $rec['theme'] = $theme; $rec['language_file'] = $language; $sql = $db->GetUpdateSQL($rs, $rec); if ($sql != "") { $result = $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } // flush session-cache cacheFlush($cfg["user"]); } }
function actionCache() { $dataList = array('pageCache' => '页面缓存', 'dataCache' => '数据缓存', 'allCache' => '全部缓存'); // ppr($dataList); $notice = '选择缓存类型'; if (XUtils::method() == 'POST') { $cacheType = reqPost('cacheType', NULL); $path = SITE_BACKEND_PATH . 'assets'; switch ($cacheType) { case 'pageCache': XUtils::delDirAndFile($path); break; case 'dataCache': cacheFlush(); break; case 'allCache': cacheFlush(); XUtils::delDirAndFile($path); break; } $notice .= '<br />清空完成!'; } $this->render('cache', array('dataList' => $dataList, 'notice' => $notice)); }
function deleteAllUserSettings() { global $cfg, $db; // delete from db $sql = "DELETE FROM tf_settings_user"; $db->Execute($sql); if ($db->ErrorNo() != 0) { dbError($sql); } // flush session-cache cacheFlush(); // return return true; }
/** * update * * @param $action */ function sa_update($action = "") { global $cfg, $error, $statusImage, $statusMessage, $htmlTitle, $htmlTop, $htmlMain; if ($action == "") { return; } switch ($action) { case "0": // get updateIndex to check if update from this version possible $updateIndexData = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY . "?u=0&v=" . _VERSION)); if (isset($updateIndexData) && $updateIndexData != "") { $updateIndexVars = explode("\n", $updateIndexData); $updatePossible = trim($updateIndexVars[0]); if ($updatePossible != "1") { buildPage("-u"); printPage(); exit; } else { $htmlTop = "<strong>Update - Check</strong>"; $htmlMain = "<br>Update from your Version possible."; $htmlMain .= '<br><br>'; $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">'; $htmlMain .= '<input type="Hidden" name="u" value="1">'; $htmlMain .= '<input type="submit" value="Next Step - Database-Update">'; $htmlMain .= '</form>'; $htmlMain .= '<br>'; $statusImage = "yellow.gif"; $htmlTitle = "Update"; printPage(); exit; } } else { buildPage("-u"); printPage(); exit; } break; case "1": // get db-settings $updateDBData = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY . "?u=1&v=" . _VERSION)); if (isset($updateDBData) && $updateDBData != "") { $updateDBVars = explode("\n", $updateDBData); $updateNeeded = trim($updateDBVars[0]); if ($updateNeeded == "0") { $htmlTop = "<strong>Update - Database</strong>"; $htmlMain = "<br>Database-Update in this Update not needed."; $htmlMain .= '<br><br>'; $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">'; $htmlMain .= '<input type="Hidden" name="u" value="3">'; $htmlMain .= '<input type="submit" value="Next Step - File-Update">'; $htmlMain .= '</form>'; $htmlMain .= '<br>'; $statusImage = "yellow.gif"; $htmlTitle = "Update"; printPage(); exit; } else { if ($updateNeeded == "1") { $htmlTop = "<strong>Update - Database</strong>"; $htmlMain = "<br>Database-Update in this Update is needed."; $htmlMain .= '<br><br>'; $htmlMain .= 'Type: <em>' . $cfg["db_type"] . '</em>'; $htmlMain .= '<br><br>'; $htmlMain .= '<form name="update" action="' . _FILE_THIS . '" method="post">'; $htmlMain .= '<input type="Hidden" name="u" value="2">'; $htmlMain .= '<input type="submit" value="Next Step - Perform Database-Update">'; $htmlMain .= '</form>'; $htmlMain .= '<br>'; $statusImage = "yellow.gif"; $htmlTitle = "Update"; printPage(); exit; } else { updateError($updateDBData); exit; } } } else { updateError(); } break; case "2": // get sql-data $updateSQLData = @trim(gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY . "?u=2&v=" . _VERSION . "&d=" . $cfg["db_type"]))); if (isset($updateSQLData) && $updateSQLData != "") { sendLine('<strong>Update - Database</strong><br><br><em>Updating Database... Please Wait...</em><ul>'); $updateSQLStates = explode("\n", $updateSQLData); // get ado-connection $dbCon = getAdoConnection(); if (!$dbCon) { echo '</em></li></ul><font color="red"><strong>Error updating Database.</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>'; echo $dbCon->ErrorMsg(); exit; } else { foreach ($updateSQLStates as $sqlState) { $sqlState = trim($sqlState); if (isset($sqlState) && $sqlState != "" && substr($sqlState, 0, 2) != "--") { sendLine('<li>' . $sqlState); $dbCon->Execute($sqlState); if ($dbCon->ErrorNo() == 0) { sendLine(' <font color="green">Ok</font></li>'); } else { // damn there was an error // close ado-connection $dbCon->Close(); // talk and out echo '</em></li></ul><font color="red"><strong>Error updating Database.</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>'; exit; } } } // close ado-connection $dbCon->Close(); // talk and continue sendLine('</ul><p><font color="green">Database-Update done.</font><br><br>'); sendLine('<form name="update" action="' . _FILE_THIS . '" method="post"><input type="Hidden" name="u" value="3"><input type="submit" value="Next Step - File-Update"></form><br>'); exit; } } else { updateError("\n" . "cant get update-sql." . "\n" . $updateSQLData); } break; case "3": // get file-list $updateFileList = @trim(gzinflate(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY . "?u=3&v=" . _VERSION))); if (isset($updateFileList) && $updateFileList != "") { sendLine('<strong>Update - Files</strong>'); sendLine('<br><br>'); sendLine('Files that require an update in this Version:'); sendLine('<pre>'); sendLine($updateFileList); sendLine('</pre>'); sendLine('<form name="update" action="' . _FILE_THIS . '" method="post">'); sendLine('<input type="Hidden" name="u" value="4">'); sendLine('<input type="submit" value="Next Step - Perform File-Update">'); sendLine('</form>'); sendLine('<strong>Ensure script can write to docroot <em>' . $cfg['docroot'] . '</em> now !</strong>'); exit; } else { updateError("\n" . "cant get file-list." . "\n" . $updateFileList); } break; case "4": sendLine('<strong>Update - Files</strong><br><br><em>Updating Files... Please Wait...</em><br><ul>'); sendLine('<li>Getting Update-Archive:<br>'); @ini_set("allow_url_fopen", "1"); @ini_set("user_agent", "torrentflux-b4rt/" . _VERSION); // get md5 $md5hash = getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY . "?u=4&v=" . _VERSION); if (!isset($md5hash) || strlen($md5hash) != 32) { sendLine('</li></ul><br><br><font color="red"><strong>Error getting Update-Archive.</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>'); exit; } // download archive $fileHandle = @fopen($cfg['docroot'] . _UPDATE_ARCHIVE, "w"); $urlHandle = @fopen(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY . "?u=5&v=" . _VERSION, 'r'); if ($fileHandle && $urlHandle) { $results = array(); $i = 0; stream_set_timeout($urlHandle, 15); $info = stream_get_meta_data($urlHandle); while (!feof($urlHandle) && !$info['timed_out']) { $data = @fgets($urlHandle, 8192); $results[$i] = @fwrite($fileHandle, $data); $info = stream_get_meta_data($urlHandle); sendLine('.'); $i++; } @fclose($fileHandle); @fclose($urlHandle); $done = true; foreach ($results as $result) { if ($result === false) { $done = false; } } if ($done) { sendLine('<font color="green">done</font></li>'); } else { sendLine('<br></li></ul><br><br><strong><font color="red">Error writing archive <em>' . $cfg['docroot'] . _UPDATE_ARCHIVE . '</em>.</font></strong><br><br>Please restore backup and try again (or do manual update).<br><br>'); exit; } } else { sendLine('</li></ul><br><br><strong><font color="red">Error updating files.</font></strong><br><br>Please restore backup and try again (or do manual update).<br><br>'); exit; } // validate archive sendLine('<li>Validating Update-Archive: '); if (file_exists($cfg['docroot'] . _UPDATE_ARCHIVE) && $md5hash == @md5_file($cfg['docroot'] . _UPDATE_ARCHIVE)) { sendLine('<font color="green">Ok</font> (<em>' . $md5hash . '</em>)<br></li>'); } else { sendLine('<font color="red">failed</font></ul><br><br>Please restore backup and try again (or do manual update).</strong><br><br>'); exit; } // extract archive sendLine('<li>Extracting Update-Archive: <br>'); sendLine('<em>'); $cmd = 'cd ' . tfb_shellencode($cfg['docroot']) . ' && tar jxvf ' . _UPDATE_ARCHIVE; $cmd .= ' 2>&1'; $handle = @popen($cmd, 'r'); while (!@feof($handle)) { $read = @fread($handle, 64); sendLine(nl2br($read)); } @pclose($handle); sendLine('</em>'); sendLine('<font color="green">done</font></li>'); // delete archive sendLine('<li>Deleting Update-Archive: '); if (@unlink($cfg['docroot'] . _UPDATE_ARCHIVE)) { sendLine('<font color="green">done</font></li>'); } else { sendLine('<font color="red">failed</font><br>remove archive ' . $cfg['docroot'] . _UPDATE_ARCHIVE . ' manual now.</li>'); } // version-file sendLine('<li>Updating Version-Information: '); $versionAvailable = trim(getDataFromUrl(_SUPERADMIN_URLBASE . _SUPERADMIN_PROXY)); if (isset($versionAvailable) && $versionAvailable != "") { if ($handle = @fopen("version.php", "w")) { if (@fwrite($handle, '<?php define("_VERSION", "' . $versionAvailable . '"); ?>')) { @fclose($handle); sendLine(' <font color="green">done</font></li>'); } else { @fclose($handle); sendLine('</li></ul><br><br><font color="red"><strong>Error writing version-file</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>'); exit; } } else { sendLine('<br><br>'); sendLine('</li></ul><font color="red"><strong>Error writing version-file</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>'); exit; } } else { sendLine('</li></ul><br><br><font color="red"><strong>Error getting version-file</strong></font><br><br>Please restore backup and try again (or do manual update).<br><br>'); exit; } sendLine('</ul>'); // done sendLine('<p><em>Done Updating Files.</em></p>'); sendLine('<hr><br><strong>Update to ' . $versionAvailable . ' completed.</strong><br><br>'); sendLine('<form name="update" action="#" method="get"><input type="submit" onClick="window.close()" value="Close"></form>'); sendLine('<br>'); // flush cache cacheFlush(); // exit exit; } exit; }
/** * start a client. */ function _start() { global $cfg; if ($this->state != CLIENTHANDLER_STATE_READY) { $this->state = CLIENTHANDLER_STATE_ERROR; array_push($this->messages, "Error. ClientHandler in wrong state on start-request."); // write error to stat $sf = new StatFile($this->transfer, $this->owner); $sf->time_left = 'Error'; $sf->write(); // return return; } // Save transfer settings $this->settingsSave(); // flush session-cache (trigger transfers-cache-set on next page-load) cacheFlush($cfg['user']); // write the session to close so older version of PHP will not hang @session_write_close(); // sf $sf = new StatFile($this->transfer, $this->owner); // queue or start ? if ($this->queue) { // queue if (FluxdQmgr::isRunning()) { // write stat-file $sf->queue(); // send command FluxdQmgr::enqueueTransfer($this->transfer, $cfg['user']); // log AuditAction($cfg["constants"]["queued_transfer"], $this->transfer); $this->logMessage("transfer enqueued : " . $this->transfer . "\n", true); } else { $msg = "queue-request (" . $this->transfer . "/" . $cfg['user'] . ") but Qmgr not active"; array_push($this->messages, $msg); AuditAction($cfg["constants"]["error"], $msg); $this->logMessage($msg . "\n", true); } // set flag $this->running = 0; } else { // start // write stat-file $sf->start(); // log the command $this->logMessage("executing command : \n" . $this->command . "\n", true); // startup $this->callResult = exec($this->command); AuditAction($cfg["constants"]["start_torrent"], $this->transfer); // set flag $this->running = 1; // wait until transfer is up waitForTransfer($this->transfer, true, 20); } if (empty($this->messages)) { // set state $this->state = CLIENTHANDLER_STATE_OK; } else { // error $this->state = CLIENTHANDLER_STATE_ERROR; $msg = "error starting client. messages :\n"; $msg .= implode("\n", $this->messages); $this->logMessage($msg . "\n", true); // write error to stat $sf->time_left = 'Error'; $sf->write(); } }
******************************************************************************/ case "maintenance": require_once "inc/classes/MaintenanceAndRepair.php"; MaintenanceAndRepair::maintenance(tfb_getRequestVar('trestart') == "true" ? MAINTENANCEANDREPAIR_TYPE_EXT : MAINTENANCEANDREPAIR_TYPE_STD); // set transfers-cache cacheTransfersSet(); break; /******************************************************************************* * Cache-Flush ******************************************************************************/ /******************************************************************************* * Cache-Flush ******************************************************************************/ case "cacheFlush": // flush session-cache cacheFlush(); // flush transfers-cache (not really needed as reload is triggered) cacheTransfersFlush(); break; /******************************************************************************* * Cookie-Flush ******************************************************************************/ /******************************************************************************* * Cookie-Flush ******************************************************************************/ case "cookieFlush": @setcookie("autologin", "", time() - 3600); break; /******************************************************************************* * bulk operations ******************************************************************************/
/** * sets webapp-lock * * @param $lock 1|0 * @return true or function exits with error */ function setWebappLock($lock) { global $db; $db->Execute("UPDATE tf_settings SET tf_value = " . $db->qstr($lock) . " WHERE tf_key = 'webapp_locked'"); // flush session-cache cacheFlush(); // return return $db->ErrorNo() == 0 ? true : $db->ErrorMsg(); }
public function actionWelcome() { cacheFlush(); $data = array(); // 系统基本信息 $serverapi = strtoupper(php_sapi_name()); $phpversion = PHP_VERSION; $systemversion = explode(" ", php_uname()); $sysReShow = 'none'; switch (PHP_OS) { case "Linux": $sysReShow = false !== ($sysInfo = XUtils::sys_linux()) ? "show" : "none"; $sysinfo = $systemversion[0] . ' ' . $systemversion[2]; break; case "FreeBSD": $sysReShow = false !== ($sysInfo = XUtils::sys_freebsd()) ? "show" : "none"; $sysinfo = $systemversion[0] . ' ' . $systemversion[2]; break; default: $sysinfo = $systemversion[0] . ' ' . $systemversion[1] . ' ' . $systemversion[3] . $systemversion[4] . $systemversion[5]; break; } if ($sysReShow == 'show') { $pmemory = '共' . $sysInfo['memTotal'] . 'M, 已使用' . $sysInfo['memUsed'] . 'M, 空闲' . $sysInfo['memFree'] . 'M, 使用率' . $sysInfo['memPercent'] . '%'; $pmemorybar = $sysInfo['memPercent']; $swapmomory = '共' . $sysInfo['swapTotal'] . 'M, 已使用' . $sysInfo['swapUsed'] . 'M, 空闲' . $sysInfo['swapFree'] . 'M, 使用率' . $sysInfo['swapPercent'] . '%'; $swapmemorybar = $sysInfo['swapPercent']; $syslaodavg = $sysInfo['loadAvg']; } $mysql = Yii::app()->db->createCommand("SELECT VERSION() AS dbversion")->queryAll(); $mysql = $mysql[0]['dbversion']; $phpsafe = $this->getcon("safe_mode"); $dispalyerror = $this->getcon("display_errors"); $allowurlopen = $this->getcon("allow_url_fopen"); $registerglobal = $this->getcon("register_globals"); $maxpostsize = $this->getcon("post_max_size"); $maxupsize = $this->getcon("upload_max_filesize"); $maxexectime = $this->getcon("max_execution_time") . 's'; $mqqsp = get_magic_quotes_gpc() === 1 ? 'YES' : 'NO'; $mprsp = get_magic_quotes_runtime() === 1 ? 'YES' : 'NO'; $zendoptsp = get_cfg_var("zend_optimizer.optimization_level") || get_cfg_var("zend_extension_manager.optimizer_ts") || get_cfg_var("zend_extension_ts") ? 'YES' : 'NO'; $iconvsp = XUtils::isfun('iconv'); $curlsp = XUtils::isfun('curl_init'); $gdsp = XUtils::isfun('gd_info'); $zlibsp = XUtils::isfun('gzclose'); $eaccsp = XUtils::isfun('eaccelerator_info'); $xcachesp = extension_loaded('XCache') ? 'YES' : 'NO'; $sessionsp = XUtils::isfun("session_start"); $cookiesp = isset($_COOKIE) ? 'YES' : 'NO'; $serverip = @gethostbyname($_SERVER['SERVER_NAME']); $serverip = $serverip == '' ? '' : " ({$serverip})"; $systime = gmdate("Y年n月j日 H:i:s", time() + 8 * 3600); $phpversionsp = $phpversion > '5.0' ? 'YES' : 'NO'; $mysqlversionsp = $mysql['dbversion'] > '4.1' ? 'YES' : 'NO'; $dbasp = extension_loaded('dba') ? 'YES' : 'NO'; // 数据库大小 $databasesize = 0; $rt = Yii::app()->db->createCommand("SHOW TABLE STATUS")->queryAll(); foreach ($rt as $rsarr) { $databasesize += $rsarr['Data_length'] + $rsarr['Index_length']; } $databasesize = XUtils::bytes_to_string($databasesize); //站点统计 $rt = Yii::app()->db->createCommand("SELECT count(*) as sum FROM {{links}}")->queryAll(); $sitesum = $rt[0]['sum']; $data['serverip'] = $serverip; $data['systime'] = $systime; $data['sysinfo'] = $sysinfo; $data['phpversion'] = $phpversion; $data['dbversion'] = $mysql; $data['dispalyerror'] = $dispalyerror; $data['serverapi'] = $serverapi; $data['phpsafe'] = $phpsafe; $data['sessionsp'] = $sessionsp; $data['cookiesp'] = $cookiesp; $data['zendoptsp'] = $zendoptsp; $data['eaccsp'] = $eaccsp; $data['xcachesp'] = $xcachesp; $data['registerglobal'] = $registerglobal; $data['mqqsp'] = $mqqsp; $data['mprsp'] = $mprsp; $data['maxupsize'] = $maxupsize; $data['maxpostsize'] = $maxpostsize; $data['maxexectime'] = $maxexectime; $data['allowurlopen'] = $allowurlopen; $data['curlsp'] = $curlsp; $data['iconvsp'] = $iconvsp; $data['zlibsp'] = $zlibsp; $data['gdsp'] = $gdsp; $data['dbasp'] = $dbasp; $data['datasize'] = $databasesize; $data['sitesum'] = $sitesum; $tmp = explode('/', dirname($_SERVER['PHP_SELF'])); $data['safe_notice'] = is_array($tmp) && !empty($tmp[count($tmp) - 1]) && $tmp[count($tmp) - 1] == 'admin' ? 1 : 0; //判断admin目录是否存在 is_dir(SITE_PATH . 'admin/') && ($data['tips']['backend'] = 1); //判断install目录是否存在 is_dir(SITE_PATH . 'install/') && ($data['tips']['install'] = 1); $this->render('welcome', array('data' => $data)); }