| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187 |
- <?php
- /* $Id: functions.admin.php 3325 2008-01-23 14:05:07Z b4rt $ */
- /*******************************************************************************
- LICENSE
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License (GPL)
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- To read the license please visit http://www.gnu.org/copyleft/gpl.html
- *******************************************************************************/
- /**
- * updateServerSettings
- */
- function admin_updateServerSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Server Settings");
- @header("location: admin.php?op=serverSettings");
- exit();
- }
- /**
- * updateTransferSettings
- */
- function admin_updateTransferSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Transfer Settings");
- @header("location: admin.php?op=transferSettings");
- exit();
- }
- /**
- * updateWebappSettings
- */
- function admin_updateWebappSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating WebApp Settings");
- @header("location: admin.php?op=webappSettings");
- exit();
- }
- /**
- * updateIndexSettings
- */
- function admin_updateIndexSettings() {
- global $cfg;
- $settings = processSettingsParams(true, true);
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Index Settings");
- @header("location: admin.php?op=indexSettings");
- exit();
- }
- /**
- * updateControlSettings
- */
- function admin_updateControlSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Control Settings");
- @header("location: admin.php?op=controlSettings");
- exit();
- }
- /**
- * updateDirSettings
- */
- function admin_updateDirSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings_dir', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Dir Settings");
- @header("location: admin.php?op=dirSettings");
- exit();
- }
- /**
- * updateStatsSettings
- */
- function admin_updateStatsSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings_stats', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Stats Settings");
- @header("location: admin.php?op=statsSettings");
- exit();
- }
- /**
- * updateXferSettings
- */
- function admin_updateXferSettings() {
- global $cfg;
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], " Updating Xfer Settings");
- @header("location: admin.php?op=xferSettings");
- exit();
- }
- /**
- * updateFluxdSettings
- */
- function admin_updateFluxdSettings() {
- global $cfg;
- if ($_POST["fluxd_dbmode"] != $cfg["fluxd_dbmode"] ||
- $_POST["fluxd_loglevel"] != $cfg["fluxd_loglevel"] ||
- $_POST["fluxd_Qmgr_enabled"] != $cfg["fluxd_Qmgr_enabled"] ||
- $_POST["fluxd_Fluxinet_enabled"] != $cfg["fluxd_Fluxinet_enabled"] ||
- $_POST["fluxd_Maintenance_enabled"] != $cfg["fluxd_Maintenance_enabled"] ||
- $_POST["fluxd_Trigger_enabled"] != $cfg["fluxd_Trigger_enabled"] ||
- $_POST["fluxd_Watch_enabled"] != $cfg["fluxd_Watch_enabled"] ||
- $_POST["fluxd_Rssad_enabled"] != $cfg["fluxd_Rssad_enabled"] ||
- $_POST["fluxd_Qmgr_maxTotalTransfers"] != $cfg["fluxd_Qmgr_maxTotalTransfers"] ||
- $_POST["fluxd_Qmgr_maxUserTransfers"] != $cfg["fluxd_Qmgr_maxUserTransfers"] ||
- $_POST["fluxd_Qmgr_interval"] != $cfg["fluxd_Qmgr_interval"] ||
- $_POST["fluxd_Fluxinet_port"] != $cfg["fluxd_Fluxinet_port"] ||
- $_POST["fluxd_Watch_interval"] != $cfg["fluxd_Watch_interval"] ||
- $_POST["fluxd_Rssad_interval"] != $cfg["fluxd_Rssad_interval"] ||
- $_POST["fluxd_Maintenance_interval"] != $cfg["fluxd_Maintenance_interval"] ||
- $_POST["fluxd_Trigger_interval"] != $cfg["fluxd_Trigger_interval"]) {
- $message = 'Settings changed. ';
- // fluxd Running?
- if (Fluxd::isRunning()) {
- // restart ?
- if ($_POST["fluxd_dbmode"] != $cfg["fluxd_dbmode"]) {
- // save settings
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- $message .= 'fluxd needs to be restarted to change db-mode.';
- } else {
- // reload ?
- $reloadModules = false;
- if ($_POST["fluxd_Qmgr_enabled"] != $cfg["fluxd_Qmgr_enabled"] ||
- $_POST["fluxd_Fluxinet_enabled"] != $cfg["fluxd_Fluxinet_enabled"] ||
- $_POST["fluxd_Maintenance_enabled"] != $cfg["fluxd_Maintenance_enabled"] ||
- $_POST["fluxd_Trigger_enabled"] != $cfg["fluxd_Trigger_enabled"] ||
- $_POST["fluxd_Watch_enabled"] != $cfg["fluxd_Watch_enabled"] ||
- $_POST["fluxd_Rssad_enabled"] != $cfg["fluxd_Rssad_enabled"]) {
- $reloadModules = true;
- }
- // reconfig of running daemon :
- if ($_POST["fluxd_loglevel"] != $cfg["fluxd_loglevel"]) {
- Fluxd::setConfig('LOGLEVEL', $_POST["fluxd_loglevel"]);
- sleep(2);
- }
- // save settings
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- // reload fluxd-database-cache
- Fluxd::reloadDBCache();
- // reload fluxd-modules
- if ($reloadModules) {
- sleep(5);
- Fluxd::reloadModules();
- $message .= 'modules reloaded.';
- } else {
- $message .= ' reload module(s) to use new settings.';
- }
- }
- } else {
- // save settings
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- $message .= 'fluxd is not running.';
- }
- // log
- AuditAction($cfg["constants"]["fluxd"], " Updating fluxd Settings");
- // redir
- @header("Location: admin.php?op=fluxdSettings&m=".urlencode($message));
- } else {
- // save settings
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- // log
- AuditAction($cfg["constants"]["fluxd"], " Updating fluxd Settings");
- // redir
- @header("Location: admin.php?op=fluxdSettings");
- }
- exit();
- }
- /**
- * controlFluxd
- */
- function admin_controlFluxd() {
- global $cfg;
- $message = "";
- $action = tfb_getRequestVar('a');
- switch($action) {
- case "start":
- // start fluxd
- if (Fluxd::isReadyToStart()) {
- Fluxd::start();
- if (Fluxd::isRunning()) {
- $message = 'fluxd started';
- } else {
- $message = 'Error starting fluxd.';
- $msgs = Fluxd::getMessages();
- Fluxd::logError("Error starting fluxd.".( (!empty($msgs)) ? "\n".implode("\n", $msgs)."\n" : "\n"), true);
- array_push($msgs, "please check fluxd-logs");
- @error($message, "admin.php?op=fluxdSettings", "fluxd-Settings", $msgs);
- }
- break;
- }
- $message = 'fluxd not ready to start';
- break;
- case "stop":
- // kill fluxd
- if (Fluxd::isRunning()) {
- Fluxd::stop();
- $message = (Fluxd::isRunning())
- ? 'Stop-Command sent.'
- : 'fluxd stopped.';
- }
- break;
- default:
- $message = 'Error : no control-operation.';
- break;
- }
- if ($message != "")
- @header("Location: admin.php?op=fluxdSettings&m=".urlencode($message));
- else
- @header("Location: admin.php?op=fluxdSettings");
- exit();
- }
- /**
- * updateFluAzuSettings
- */
- function admin_updateFluAzuSettings() {
- global $cfg;
- // FluAzu
- require_once("inc/classes/FluAzu.php");
- $message = "";
- if ($_POST["fluazu_host"] != $cfg["fluazu_host"] ||
- $_POST["fluazu_port"] != $cfg["fluazu_port"] ||
- $_POST["fluazu_secure"] != $cfg["fluazu_secure"] ||
- $_POST["fluazu_user"] != $cfg["fluazu_user"] ||
- $_POST["fluazu_pw"] != $cfg["fluazu_pw"]) {
- // fluazu Running?
- if (FluAzu::isRunning()) {
- $message = 'fluazu needs to be stopped before settings can be changed.';
- } else {
- // save settings
- $settings = processSettingsParams(false, false);
- saveSettings('tf_settings', $settings);
- $message = 'Settings changed.';
- // log
- AuditAction($cfg["constants"]["admin"], " Updating fluazu Settings");
- }
- }
- if ($message != "")
- @header("Location: admin.php?op=fluazuSettings&m=".urlencode($message));
- else
- @header("Location: admin.php?op=fluazuSettings");
- exit();
- }
- /**
- * controlFluAzu
- */
- function admin_controlFluAzu() {
- global $cfg;
- // FluAzu
- require_once("inc/classes/FluAzu.php");
- $message = "";
- $action = tfb_getRequestVar('a');
- switch($action) {
- case "start":
- // start fluazu
- if (!FluAzu::isRunning()) {
- if (FluAzu::start()) {
- $message = 'fluazu started';
- } else {
- $message = 'Error starting fluazu.';
- $msgs = FluAzu::getMessages();
- FluAzu::logMessage("Error starting fluazu.".( (!empty($msgs)) ? "\n".implode("\n", $msgs)."\n" : "\n"), true);
- array_push($msgs, "please check fluazu-log");
- @error($message, "admin.php?op=fluazuSettings", "fluazu-Settings", $msgs);
- }
- break;
- }
- break;
- case "stop":
- // kill fluazu
- if (FluAzu::isRunning()) {
- FluAzu::stop();
- $message = (FluAzu::isRunning())
- ? 'Stop-Command sent.'
- : 'fluazu stopped.';
- }
- break;
- default:
- $message = 'Error : no control-operation.';
- break;
- }
- if ($message != "")
- @header("Location: admin.php?op=fluazuSettings&m=".urlencode($message));
- else
- @header("Location: admin.php?op=fluazuSettings");
- exit();
- }
- /**
- * updateAzureusSettings
- */
- function admin_updateAzureusSettings() {
- global $cfg;
- // FluAzu
- require_once("inc/classes/FluAzu.php");
- $message = "";
- // fluazu Running?
- if (FluAzu::isRunning()) {
- $status = FluAzu::getStatus();
- $statusKeys = FluAzu::getStatusKeys();
- // current settings
- $settingsCurrent = array();
- foreach ($statusKeys as $statusKey)
- $settingsCurrent[$statusKey] = $status[$statusKey];
- // new settings
- $settingsNew = array();
- foreach ($statusKeys as $statusKey) {
- $settingsNew[$statusKey] = tfb_getRequestVar($statusKey);
- if ($settingsNew[$statusKey] == "")
- $settingsNew[$statusKey] = $settingsCurrent[$statusKey];
- }
- // customize settings
- if ($cfg['transfer_customize_settings'] == 2)
- $customize_settings = 1;
- elseif ($cfg['transfer_customize_settings'] == 1 && $cfg['isAdmin'])
- $customize_settings = 1;
- else
- $customize_settings = 0;
- // get changes
- $settingsChanged = array();
- foreach ($statusKeys as $statusKey) {
- if ($settingsNew[$statusKey] != $settingsCurrent[$statusKey]) {
- if ($customize_settings == 1)
- array_push($settingsChanged, $statusKey);
- }
- }
- if (empty($settingsChanged)) { /* no changes */
- $message = 'no changes.';
- } else { /* something changed */
- // set
- foreach ($settingsChanged as $statusKey)
- FluAzu::setAzu($statusKey, $settingsNew[$statusKey], false);
- // send
- FluAzu::sendCommands();
- // give fluazu some time
- sleep(2);
- $message = 'Settings changed.';
- // log
- AuditAction($cfg["constants"]["admin"], "Updating azureus Settings");
- }
- } else {
- $message = 'fluazu/azureus not running.';
- }
- if ($message != "")
- @header("Location: admin.php?op=fluazuSettings&m=".urlencode($message));
- else
- @header("Location: admin.php?op=fluazuSettings");
- exit();
- }
- /**
- * updateSearchSettings
- */
- function admin_updateSearchSettings() {
- global $cfg;
- $settings = array();
- foreach ($_POST as $key => $value) {
- if ($key != "searchEngine")
- $settings[$key] = $value;
- }
- if (count($settings) > 0) {
- saveSettings('tf_settings', $settings);
- AuditAction($cfg["constants"]["admin"], "Updating Search Settings");
- }
- $searchEngine = tfb_getRequestVar('searchEngine');
- if (empty($searchEngine))
- $searchEngine = $cfg["searchEngine"];
- @header("location: admin.php?op=searchSettings&searchEngine=".$searchEngine);
- exit();
- }
- /**
- * addLink
- */
- function admin_addLink() {
- global $cfg;
- $newLink = tfb_getRequestVarRaw('newLink');
- $newSite = tfb_getRequestVarRaw('newSite');
- if (!empty($newLink)){
- if (strpos($newLink, "http://" ) !== 0 && strpos($newLink, "https://" ) !== 0 && strpos($newLink, "ftp://" ) !== 0)
- $newLink = "http://".$newLink;
- empty($newSite) && $newSite = $newLink;
- addNewLink($newLink, $newSite);
- AuditAction($cfg["constants"]["admin"], "New ".$cfg['_LINKS_MENU'].": ".addslashes($newSite)." [".addslashes($newLink)."]");
- }
- @header("location: admin.php?op=editLinks");
- exit();
- }
- /**
- * editLink
- */
- function admin_editLink() {
- global $cfg;
- $lid = tfb_getRequestVar('lid');
- $newLink = tfb_getRequestVarRaw('editLink');
- $newSite = tfb_getRequestVarRaw('editSite');
- if (!empty($newLink)){
- if(strpos($newLink, "http://" ) !== 0 && strpos($newLink, "https://" ) !== 0 && strpos($newLink, "ftp://" ) !== 0)
- $newLink = "http://".$newLink;
- empty($newSite) && $newSite = $newLink;
- $oldLink = getLink($lid);
- $oldSite = getSite($lid);
- alterLink($lid, $newLink, $newSite);
- AuditAction($cfg["constants"]["admin"], "Change Link: ".addslashes($oldSite)." [".addslashes($oldLink)."] -> ".addslashes($newSite)." [".addslashes($newLink)."]");
- }
- @header("location: admin.php?op=editLinks");
- exit();
- }
- /**
- * moveLink
- */
- function admin_moveLink() {
- global $db;
- $lid = tfb_getRequestVar('lid');
- $direction = tfb_getRequestVar('direction');
- if (!isset($lid) && !isset($direction) && $direction !== "up" && $direction !== "down") {
- @header("location: admin.php?op=editLinks");
- exit();
- }
- $idx = getLinkSortOrder($lid);
- $position = array("up"=>-1, "down"=>1);
- $new_idx = $idx + $position[$direction];
- $sql = "UPDATE tf_links SET sort_order = ".$db->qstr($idx)." WHERE sort_order = ".$db->qstr($new_idx);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $sql = "UPDATE tf_links SET sort_order = ".$db->qstr($new_idx)." WHERE lid = ".$db->qstr($lid);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // flush session-cache
- cacheFlush();
- @header("Location: admin.php?op=editLinks");
- exit();
- }
- /**
- * deleteLink
- */
- function admin_deleteLink() {
- global $cfg;
- $lid = tfb_getRequestVar('lid');
- AuditAction($cfg["constants"]["admin"], $cfg['_DELETE']." Link: ".getSite($lid)." [".getLink($lid)."]");
- deleteOldLink($lid);
- // flush session-cache
- cacheFlush();
- @header("location: admin.php?op=editLinks");
- exit();
- }
- /**
- * addRSS
- */
- function admin_addRSS() {
- global $cfg;
- $newRSS = tfb_getRequestVarRaw('newRSS');
- if(!empty($newRSS)){
- addNewRSS($newRSS);
- AuditAction($cfg["constants"]["admin"], "New RSS: ".addslashes($newRSS));
- }
- @header("location: admin.php?op=editRSS");
- exit();
- }
- /**
- * deleteRSS
- */
- function admin_deleteRSS() {
- global $cfg;
- $rid = tfb_getRequestVar('rid');
- AuditAction($cfg["constants"]["admin"], $cfg['_DELETE']." RSS: ".getRSS($rid));
- deleteOldRSS($rid);
- @header("location: admin.php?op=editRSS");
- exit();
- }
- /**
- * deleteUser
- */
- function admin_deleteUser() {
- global $cfg;
- $user_id = tfb_getRequestVar('user_id');
- if (!IsSuperAdmin($user_id)) {
- DeleteThisUser($user_id);
- AuditAction($cfg["constants"]["admin"], $cfg['_DELETE']." ".$cfg['_USER'].": ".$user_id);
- }
- @header("location: admin.php");
- exit();
- }
- /**
- * setUserState
- */
- function admin_setUserState() {
- setUserState();
- @header("location: admin.php?op=showUsers");
- exit();
- }
- /**
- * admin menu
- */
- function tmplSetAdminMenu() {
- global $cfg, $tmpl;
- $tmpl->setvar('_SETTINGS_MENU', $cfg['_SETTINGS_MENU']);
- $tmpl->setvar('_FLUXD_MENU', $cfg['_FLUXD_MENU']);
- $tmpl->setvar('_SEARCHSETTINGS_MENU', $cfg['_SEARCHSETTINGS_MENU']);
- $tmpl->setvar('_LINKS_MENU', $cfg['_LINKS_MENU']);
- $tmpl->setvar('_ACTIVITY_MENU', $cfg['_ACTIVITY_MENU']);
- $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
- // superadmin
- if (IsSuperAdmin()) {
- $tmpl->setvar('is_superadmin', 1);
- $tmpl->setvar('adminmenu_superAdminLink', getSuperAdminLink('','<font class="adminlink">superadmin</font></a>'));
- }
- }
- /**
- * get Activity
- *
- * @param $min
- * @param $user
- * @param $srchFile
- * @param $srchAction
- */
- function tmplSetActivity($min = 0, $user = "", $srchFile = "", $srchAction = "") {
- global $cfg, $db, $tmpl;
- $sqlForSearch = "";
- $userdisplay = $user;
- if ($user != "")
- $sqlForSearch .= "user_id=".$db->qstr($user)." AND ";
- else
- $userdisplay = $cfg['_ALLUSERS'];
- if ($srchFile != "")
- $sqlForSearch .= "file like ".$db->qstr("%".$srchFile."%")." AND ";
- if ($srchAction != "")
- $sqlForSearch .= "action like ".$db->qstr("%".$srchAction."%")." AND ";
- $offset = 50;
- $inx = 0;
- if (!isset($min))
- $min=0;
- $max = $min + $offset;
- $sql = "SELECT user_id, file, action, ip, ip_resolved, user_agent, time FROM tf_log WHERE ".$sqlForSearch."action!=".$db->qstr($cfg["constants"]["hit"])." ORDER BY time desc";
- $result = $db->SelectLimit($sql, $offset, $min);
- if ($db->ErrorNo() != 0) dbError($sql);
- $act_list = array();
- while (list($user_id, $file, $action, $ip, $ip_resolved, $user_agent, $time) = $result->FetchRow()) {
- $user_icon = (IsOnline($user_id))
- ? "themes/".$cfg['theme']."/images/user.gif"
- : "themes/".$cfg['theme']."/images/user_offline.gif";
- $is_superuser = (IsUser($user_id)) ? 1 : 0;
- array_push($act_list, array(
- 'is_superuser' => $is_superuser,
- 'user_id' => $user_id,
- 'user_icon' => $user_icon,
- 'action' => htmlentities($action, ENT_QUOTES),
- 'file' => htmlentities($file, ENT_QUOTES),
- 'ip_resolved' => htmlentities($ip_resolved, ENT_QUOTES),
- 'user_agent' => htmlentities($user_agent, ENT_QUOTES),
- 'ip' => htmlentities($ip, ENT_QUOTES),
- 'date' => date($cfg['_DATETIMEFORMAT'], $time)
- )
- );
- $inx++;
- }
- $prev = ($min - $offset);
- $selected = "";
- $action_list = array();
- foreach ($cfg["constants"] as $action) {
- if ($action != $cfg["constants"]["hit"]) {
- array_push($action_list, array(
- 'action' => htmlentities($action, ENT_QUOTES),
- 'selected' => ($srchAction == $action) ? "selected" : ""
- )
- );
- }
- }
- $user_list = array();
- $selected = "";
- for ($inx2 = 0; $inx2 < sizeof($cfg['users']); $inx2++) {
- array_push($user_list, array(
- 'user' => htmlentities($cfg['users'][$inx2], ENT_QUOTES),
- 'selected' => ($user == $cfg['users'][$inx2]) ? "selected" : ""
- )
- );
- }
- // set vars
- $tmpl->setvar('_USER', $cfg['_USER']);
- $tmpl->setvar('_ACTION', $cfg['_ACTION']);
- $tmpl->setvar('_FILE', $cfg['_FILE']);
- $tmpl->setvar('_IP', $cfg['_IP']);
- $tmpl->setvar('_TIMESTAMP', $cfg['_TIMESTAMP']);
- $tmpl->setvar('_NORECORDSFOUND', $cfg['_NORECORDSFOUND']);
- $tmpl->setvar('_SENDMESSAGETO', $cfg['_SENDMESSAGETO']);
- $tmpl->setvar('_ACTIVITYSEARCH', $cfg['_ACTIVITYSEARCH']);
- $tmpl->setvar('_FILE', $cfg['_FILE']);
- $tmpl->setvar('_SHOWPREVIOUS', $cfg['_SHOWPREVIOUS']);
- $tmpl->setvar('_SHOWMORE', $cfg['_SHOWMORE']);
- $tmpl->setvar('_ALL', $cfg['_ALL']);
- $tmpl->setvar('_DAYS', $cfg['_DAYS']);
- $tmpl->setvar('_SEARCH', $cfg['_SEARCH']);
- $tmpl->setvar('_ACTIVITYLOG', $cfg['_ACTIVITYLOG']);
- $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
- $tmpl->setloop('activity_act_list', $act_list);
- $tmpl->setloop('activity_action_list', $action_list);
- $tmpl->setloop('activity_user_list', $user_list);
- $tmpl->setvar('activity_srchFile', $srchFile);
- $tmpl->setvar('activity_srchAction', $srchAction);
- $tmpl->setvar('activity_prev', $prev);
- $tmpl->setvar('activity_user', $user);
- $tmpl->setvar('activity_min', $min);
- $tmpl->setvar('activity_max', $max);
- $tmpl->setvar('activity_days_to_keep', $cfg["days_to_keep"]);
- $tmpl->setvar('activity_userdisplay', $userdisplay);
- if ($prev >= 0)
- $tmpl->setvar('activity_is_prev', 1);
- if ($inx>=$offset)
- $tmpl->setvar('activity_is_more', 1);
- if ($prev >= 0 || $inx>=$offset)
- $tmpl->setvar('activity_both_set', 1);
- }
- /**
- * sets vars for the user section
- */
- function tmplSetUserSection() {
- global $cfg, $db, $tmpl;
- // xfer-prepare
- $tmpl->setvar('enable_xfer', $cfg["enable_xfer"]);
- if ($cfg['enable_xfer'] == 1) {
- $tmpl->setvar('userSection_colspan', 8);
- // getTransferListArray to update xfer-stats
- // xfer-init
- if ($cfg['xfer_realtime'] == 0) {
- $cfg['xfer_realtime'] = 1;
- // set xfer-newday
- Xfer::setNewday();
- }
- @getTransferListArray();
- } else {
- $tmpl->setvar('userSection_colspan', 7);
- }
- // activity-prepare
- $total_activity = GetActivityCount();
- $sql = "SELECT user_id, hits, last_visit, time_created, user_level, state FROM tf_users ORDER BY user_id";
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // user-details
- $user_details_list = array();
- while (list($user_id, $hits, $last_visit, $time_created, $user_level, $user_state) = $result->FetchRow()) {
- // disk-usage
- $disk_usage = "0";
- $tDir = $cfg["path"].$user_id."/";
- if (is_dir($tDir)) {
- switch ($cfg["_OS"]) {
- case 1: //Linux
- $dudir = shell_exec($cfg['bin_du']." -sk -h -D ".tfb_shellencode($tDir));
- break;
- case 2: //BSD
- $dudir = shell_exec($cfg['bin_du']." -sk -h -L ".tfb_shellencode($tDir));
- break;
- }
- $dusize = explode("\t", $dudir);
- $disk_usage = array_shift($dusize);
- }
- // xfer-usage
- $xfer_usage = ($cfg['enable_xfer'] == 1)
- ? Xfer::getUsage($user_id)
- : 0;
- // activity
- $user_activity = GetActivityCount($user_id);
- $user_percent = ($user_activity == 0)
- ? 0
- : number_format(($user_activity / $total_activity) * 100);
- // online
- $user_icon = "themes/".$cfg['theme']."/images/user_offline.gif";
- if (IsOnline($user_id))
- $user_icon = "themes/".$cfg['theme']."/images/user.gif";
- // level
- $user_image = "themes/".$cfg['theme']."/images/user.gif";
- $type_user = $cfg['_NORMALUSER'];
- if ($user_level == 1) {
- $user_image = "themes/".$cfg['theme']."/images/admin_user.gif";
- $type_user = $cfg['_ADMINISTRATOR'];
- }
- if ($user_level == 2) {
- $user_image = "themes/".$cfg['theme']."/images/superadmin.gif";
- $type_user = $cfg['_SUPERADMIN'];
- }
- $is_superadmin = ($user_level <= 1 || IsSuperAdmin()) ? 1 : 0;
- // add to list
- array_push($user_details_list, array(
- 'is_user' => IsUser($user_id),
- 'user_id' => $user_id,
- 'user_icon' => $user_icon,
- 'hits' => $hits,
- 'disk_usage' => $disk_usage,
- 'xfer_usage' => $xfer_usage,
- 'user_percent' => $user_percent,
- 'user_percent2' => $user_percent*2,
- 'user_percent3' => (200 - ($user_percent*2)),
- 'time_created' => date($cfg['_DATEFORMAT'], $time_created),
- 'last_visit' => date($cfg['_DATETIMEFORMAT'], $last_visit),
- 'user_image' => $user_image,
- 'type_user' => $type_user,
- 'user_level' => $user_level,
- 'user_state' => $user_state,
- 'is_superadmin' => $is_superadmin
- )
- );
- }
- // set vars
- $tmpl->setvar('_USERDETAILS', $cfg['_USERDETAILS']);
- $tmpl->setvar('_USER', $cfg['_USER']);
- $tmpl->setvar('_HITS', $cfg['_HITS']);
- $tmpl->setvar('_UPLOADACTIVITY', $cfg['_UPLOADACTIVITY']);
- $tmpl->setvar('_JOINED', $cfg['_JOINED']);
- $tmpl->setvar('_LASTVISIT', $cfg['_LASTVISIT']);
- $tmpl->setvar('_ADMIN', $cfg['_ADMIN']);
- $tmpl->setvar('_DAYS', $cfg['_DAYS']);
- $tmpl->setvar('_SENDMESSAGETO', $cfg['_SENDMESSAGETO']);
- $tmpl->setvar('_WARNING', $cfg['_WARNING']);
- $tmpl->setvar('_ABOUTTODELETE', $cfg['_ABOUTTODELETE']);
- $tmpl->setvar('_USERSACTIVITY', $cfg['_USERSACTIVITY']);
- $tmpl->setvar('_EDIT', $cfg['_EDIT']);
- $tmpl->setvar('_DELETE', $cfg['_DELETE']);
- $tmpl->setvar('table_admin_border', $cfg["table_admin_border"]);
- $tmpl->setvar('days_to_keep', $cfg["days_to_keep"]);
- $tmpl->setloop('user_details_list', $user_details_list);
- }
- /**
- * shell_exec php binary with given command-line,
- * taking necessary precautions in case binary
- * it is not really a php-cli
- *
- * @param $php string
- * @param $args string
- * @return string
- */
- function safePhpCli($php, $args) {
- # Need to be careful in order to avoid problems with cgi-fcgi SAPI php's:
- # - they detect whether they are in fcgi mode by testing whether their stdin is
- # a socket -- so if this code is run by a fcgi php (whose stdin is a socket),
- # child will inherit the same stdin and thus believe it is invoked in fcgi mode
- # => '< /dev/null'
- # - they detect whether they are in cgi mode by testing the presence of environment
- # variables -- so if this code is run by a cgi php (with those env. vars set),
- # child will inherit those and thus believe it is invoked in cgi mode
- # => 'unset ...'
- $cmd = 'unset SERVER_SOFTWARE SERVER_NAME GATEWAY_INTERFACE REQUEST_METHOD ; ';
- $cmd .= $php . ' ' . $args . ' < /dev/null';
- return shell_exec($cmd);
- }
- /**
- * Returns the status image after a validation
- *
- * @param $ok bool
- * @param $msg string
- * @return string
- */
- function validationMsg($ok, $msg = null) {
- global $cfg;
- return
- '<img src="themes/'.$cfg['theme'].'/images/'.($ok ? 'green.gif' : 'red.gif').
- '" align="absmiddle" title="'.(!empty($msg) ? $msg : ($ok ? 'Valid' : 'Invalid')).'">'.
- (empty($msg) ? '' : ('<br><font color="'.($ok ? '#008000' : '#ff0000').'">'.$msg.'</font>'));
- }
- /**
- * Validates the existence of a file and returns the status image
- *
- * @param $the_file
- * @return string
- */
- function validateFile($the_file) {
- if (!isFile($the_file))
- return validationMsg(false, 'Path is not valid');
- return validationMsg(true);
- }
- /**
- * Validates existence + exec of a file and returns the status image
- *
- * @param $the_file
- * @return string
- */
- function validateBinary($the_file) {
- if (!isFile($the_file))
- return validationMsg(false, 'Path is not valid');
- if (!is_executable($the_file))
- return validationMsg(false, 'File exists but is not executable');
- return validationMsg(true);
- }
- /**
- * Validates existence + exec + valid version of PHP-cli and returns the status image
- *
- * @param $the_file
- * @return string
- */
- function validatePhpCli($the_file) {
- if (!isFile($the_file))
- return validationMsg(false, 'Path is not valid');
- if (!is_executable($the_file))
- return validationMsg(false, 'File exists but is not executable');
- $phpVersion = safePhpCli($the_file, '-v');
- if ((strpos($phpVersion, 'PHP')) === false || (strpos($phpVersion, '(cli)')) === false)
- return validationMsg(false, 'Executable is not PHP-CLI');
- return validationMsg(true);
- }
- /**
- * Validates existence + exec + valid version of transmissioncli and returns the status image
- *
- * @param $the_file
- * @return string
- */
- function validateTransmissionCli($the_file) {
- global $cfg;
- if (!isFile($the_file))
- return validationMsg(false, 'Path is not valid');
- if (!is_executable($the_file))
- return validationMsg(false, 'File exists but is not executable');
- $transmissionHelp = strtolower(shell_exec("HOME=".tfb_shellencode($cfg["path"])."; export HOME; ".$the_file.' --help'));
- return (
- strpos($transmissionHelp, 'transmission') === false ||
- ((strpos($transmissionHelp, 'tfcli') === false) &&
- (strpos($transmissionHelp, 'torrentflux') === false))
- )
- ? validationMsg(false, 'Executable is not TorrentFlux-bundled transmissioncli')
- : validationMsg(true);
- }
- /**
- * setUserState
- */
- function setUserState() {
- global $cfg, $db;
- $user_id = tfb_getRequestVar('user_id');
- $user_state = tfb_getRequestVar('state');
- // check params
- if (!(isset($user_id)) && (isset($user_state)))
- return false;
- // sanity-check, don't allow setting state of superadmin to 0
- if (($user_state == 0) && (IsSuperAdmin($user_id))) {
- AuditAction($cfg["constants"]["error"], "Invalid try to deactivate superadmin account.");
- return false;
- }
- // set new state
- $sql = "SELECT * FROM tf_users WHERE user_id = ".$db->qstr($user_id);
- $rs = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $rec = array('state'=>$user_state);
- $sql = $db->GetUpdateSQL($rs, $rec);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- switch ($user_state) {
- case 0:
- AuditAction($cfg["constants"]["admin"], "User ".$user_id." deactivated.");
- break;
- case 1:
- AuditAction($cfg["constants"]["admin"], "User ".$user_id." activated.");
- break;
- }
- return true;
- }
- /**
- * Add New Link
- *
- * @param $newLink
- * @param $newSite
- */
- function addNewLink($newLink,$newSite) {
- global $db;
- //$rec = array('url'=>$newLink);
- // Link sort order index:
- $idx = -1;
- // Get current highest link index:
- $sql = "SELECT sort_order FROM tf_links ORDER BY sort_order DESC";
- $result = $db->SelectLimit($sql, 1);
- if ($db->ErrorNo() != 0) dbError($sql);
- $idx = ($result->fields === false)
- ? 0 /* No links currently in db */
- : $result->fields["sort_order"] + 1;
- $rec = array(
- 'url' => $newLink,
- 'sitename' => $newSite,
- 'sort_order' => $idx
- );
- $sTable = 'tf_links';
- $sql = $db->GetInsertSql($sTable, $rec);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // flush session-cache
- cacheFlush();
- }
- /**
- * This function updates the database and alters the selected links values
- *
- * @param $lid
- * @param $newLink
- * @param $newSite
- */
- function alterLink($lid,$newLink,$newSite) {
- global $cfg, $db;
- $sql = "UPDATE tf_links SET url=".$db->qstr($newLink).",sitename=".$db->qstr($newSite)." WHERE lid = ".$db->qstr($lid);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // flush session-cache
- cacheFlush();
- }
- /**
- * get link
- *
- * @param $lid
- * @return string
- */
- function getLink($lid) {
- global $cfg, $db;
- $rtnValue = "";
- $sql = "SELECT url FROM tf_links WHERE lid=".$db->qstr($lid);
- $rtnValue = $db->GetOne($sql);
- return $rtnValue;
- }
- /**
- * Delete Link
- *
- * @param $lid
- */
- function deleteOldLink($lid) {
- global $db;
- // Link Mod
- //$sql = "delete from tf_links where lid=".$lid;
- // Get Current sort order index of link with this link id:
- $idx = getLinkSortOrder($lid);
- // Fetch all link ids and their sort orders where the sort order is greater
- // than the one we're removing - we need to shuffle each sort order down
- // one:
- $sql = "SELECT sort_order, lid FROM tf_links ";
- $sql .= "WHERE sort_order > ".$db->qstr($idx)." ORDER BY sort_order ASC";
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $arLinks = $result->GetAssoc();
- // Decrement the sort order of each link:
- foreach ($arLinks as $sid=>$this_lid) {
- $sql = "UPDATE tf_links SET sort_order=sort_order-1 WHERE lid=".$db->qstr($this_lid);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- // Finally delete the link:
- $sql = "DELETE FROM tf_links WHERE lid=".$db->qstr($lid);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // flush session-cache
- cacheFlush();
- }
- /**
- * get Link Sort Order
- *
- * @param $lid
- * @return string
- */
- function getLinkSortOrder($lid) {
- global $db;
- // Get Current sort order index of link with this link id:
- $sql="SELECT sort_order FROM tf_links WHERE lid=".$db->qstr($lid);
- $rtnValue=$db->GetOne($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- return $rtnValue;
- }
- /**
- * get Site
- *
- * @param $lid
- * @return string
- */
- function getSite($lid) {
- global $cfg, $db;
- $rtnValue = "";
- $sql = "SELECT sitename FROM tf_links WHERE lid=".$db->qstr($lid);
- $rtnValue = $db->GetOne($sql);
- return $rtnValue;
- }
- /**
- * Add New RSS Link
- *
- * @param $newRSS
- */
- function addNewRSS($newRSS) {
- global $db;
- $rec = array('url'=>$newRSS);
- $sTable = 'tf_rss';
- $sql = $db->GetInsertSql($sTable, $rec);
- $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- /**
- * Delete RSS
- *
- * @param $rid
- */
- function deleteOldRSS($rid) {
- global $db;
- $sql = "delete from tf_rss where rid=".$db->qstr($rid);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- /**
- * get RSS
- *
- * @param $rid
- * @return string
- */
- function getRSS($rid) {
- global $cfg, $db;
- $rtnValue = "";
- $sql = "SELECT url FROM tf_rss WHERE rid=".$db->qstr($rid);
- $rtnValue = $db->GetOne($sql);
- return $rtnValue;
- }
- /**
- * Delete User
- *
- * @param $user_id
- */
- function DeleteThisUser($user_id) {
- global $db;
- $sql = "SELECT uid FROM tf_users WHERE user_id = ".$db->qstr($user_id);
- $uid = $db->GetOne( $sql );
- if ($db->ErrorNo() != 0) dbError($sql);
- // delete any cookies this user may have had
- //$sql = "DELETE tf_cookies FROM tf_cookies, tf_users WHERE (tf_users.uid = tf_cookies.uid) AND tf_users.user_id=".$db->qstr($user_id);
- $sql = "DELETE FROM tf_cookies WHERE uid=".$db->qstr($uid);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // Now cleanup any message this person may have had
- $sql = "DELETE FROM tf_messages WHERE to_user=".$db->qstr($user_id);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // now delete the user from the table
- $sql = "DELETE FROM tf_users WHERE user_id=".$db->qstr($user_id);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // flush session-cache
- cacheFlush();
- }
- /**
- * Update User -- used by admin
- *
- * @param $user_id
- * @param $org_user_id
- * @param $pass1
- * @param $userType
- * @param $hideOffline
- */
- function updateThisUser($user_id, $org_user_id, $pass1, $userType, $hideOffline) {
- global $db;
- $user_id = strtolower($user_id);
- if ($hideOffline == "")
- $hideOffline = 0;
- $sql = "select * from tf_users where user_id = ".$db->qstr($org_user_id);
- $rs = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $rec = array();
- $rec['user_id'] = $user_id;
- $rec['user_level'] = $userType;
- $rec['hide_offline'] = $hideOffline;
- if ($pass1 != "")
- $rec['password'] = md5($pass1);
- $sql = $db->GetUpdateSQL($rs, $rec);
- if ($sql != "") {
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- // if the original user id and the new id do not match, we need to update messages and log
- if ($user_id != $org_user_id) {
- $sql = "UPDATE tf_messages SET to_user=".$db->qstr($user_id)." WHERE to_user=".$db->qstr($org_user_id);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $sql = "UPDATE tf_messages SET from_user=".$db->qstr($user_id)." WHERE from_user=".$db->qstr($org_user_id);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $sql = "UPDATE tf_log SET user_id=".$db->qstr($user_id)." WHERE user_id=".$db->qstr($org_user_id);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- // flush session-cache
- cacheFlush();
- }
- }
- /**
- * Change User Level
- *
- * @param $user_id
- * @param $level
- */
- function changeUserLevel($user_id, $level) {
- global $db;
- $sql = "select * from tf_users where user_id = ".$db->qstr($user_id);
- $rs = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- $rec = array('user_level'=>$level);
- $sql = $db->GetUpdateSQL($rs, $rec);
- $result = $db->Execute($sql);
- if ($db->ErrorNo() != 0) dbError($sql);
- }
- /**
- * 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();
- }
- /**
- * reset transfer-Totals
- *
- * @return true or function exits with error
- */
- function resetAllTransferTotals() {
- global $db;
- $db->Execute("DELETE FROM tf_transfer_totals");
- // set transfers-cache
- cacheTransfersSet();
- return ($db->ErrorNo() == 0)
- ? true
- : $db->ErrorMsg();
- }
- ?>
|