Subversion Repositories svnkaklik

Rev

Details | Last modification | View Log

Rev Author Line No. Line
36 kaklik 1
<?php
2
 
3
/*************************************************************
4
*  TorrentFlux PHP Torrent Manager
5
*  www.torrentflux.com
6
**************************************************************/
7
/*
8
    This file is part of TorrentFlux.
9
 
10
    TorrentFlux is free software; you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation; either version 2 of the License, or
13
    (at your option) any later version.
14
 
15
    TorrentFlux is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with TorrentFlux; if not, write to the Free Software
22
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
*/
24
 
25
//*************************************************************
26
// This file contains methods used by both the login.php and the
27
// main application
28
//*************************************************************
29
function getRequestVar($varName)
30
{
31
    if (array_key_exists($varName,$_REQUEST))
32
    {
33
	return trim($_REQUEST[$varName]);
34
    }
35
    else
36
    {
37
        return '';
38
    }
39
}
40
 
41
 
42
//*********************************************************
43
// AuditAction
44
function AuditAction($action, $file="")
45
{
46
    global $_SERVER, $cfg, $db;
47
 
48
    $host_resolved = gethostbyaddr($cfg['ip']);
49
    $create_time = time();
50
 
51
    $rec = array(
52
                    'user_id' => $cfg['user'],
53
                    'file' => $file,
54
                    'action' => $action,
55
                    'ip' => $cfg['ip'],
56
                    'ip_resolved' => $host_resolved,
57
                    'user_agent' => $_SERVER['HTTP_USER_AGENT'],
58
                    'time' => $create_time
59
                );
60
 
61
    $sTable = 'tf_log';
62
    $sql = $db->GetInsertSql($sTable, $rec);
63
 
64
    // add record to the log
65
    $result = $db->Execute($sql);
66
    showError($db,$sql);
67
}
68
 
69
//*********************************************************
70
function loadSettings()
71
{
72
    global $cfg, $db;
73
 
74
    // pull the config params out of the db
75
    $sql = "SELECT tf_key, tf_value FROM tf_settings";
76
    $recordset = $db->Execute($sql);
77
    showError($db, $sql);
78
 
79
    while(list($key, $value) = $recordset->FetchRow())
80
    {
81
        $tmpValue = '';
82
	    if(strpos($key,"Filter")>0)
83
        {
84
	        $tmpValue = unserialize($value);
85
	    }
86
	    elseif($key == 'searchEngineLinks')
87
	    {
88
	        $tmpValue = unserialize($value);
89
	    }
90
	    if(is_array($tmpValue))
91
        {
92
            $value = $tmpValue;
93
        }
94
        $cfg[$key] = $value;
95
    }
96
}
97
 
98
//*********************************************************
99
function insertSetting($key,$value)
100
{
101
    global $cfg, $db;
102
 
103
    $update_value = $value;
104
    if (is_array($value))
105
    {
106
        $update_value = serialize($value);
107
    }
108
 
109
    $sql = "INSERT INTO tf_settings VALUES ('".$key."', '".$update_value."')";
110
 
111
    if ( $sql != "" )
112
    {
113
        $result = $db->Execute($sql);
114
        showError($db,$sql);
115
        // update the Config.
116
        $cfg[$key] = $value;
117
    }
118
}
119
 
120
//*********************************************************
121
function updateSetting($key,$value)
122
{
123
    global $cfg, $db;
124
    $update_value = $value;
125
	if (is_array($value))
126
    {
127
        $update_value = serialize($value);
128
    }
129
 
130
    $sql = "UPDATE tf_settings SET tf_value = '".$update_value."' WHERE tf_key = '".$key."'";
131
 
132
    if ( $sql != "" )
133
    {
134
        $result = $db->Execute($sql);
135
        showError($db,$sql);
136
        // update the Config.
137
        $cfg[$key] = $value;
138
    }
139
}
140
 
141
//*********************************************************
142
function saveSettings($settings)
143
{
144
    global $cfg, $db;
145
 
146
    foreach ($settings as $key => $value)
147
    {
148
        if (array_key_exists($key, $cfg))
149
        {
150
            if(is_array($cfg[$key]) || is_array($value))
151
            {
152
                if(serialize($cfg[$key]) != serialize($value))
153
                {
154
                    updateSetting($key, $value);
155
                }
156
 
157
            }elseif ($cfg[$key] != $value)
158
            {
159
                updateSetting($key, $value);
160
            }
161
            else
162
            {
163
                // Nothing has Changed..
164
            }
165
        }else{
166
            insertSetting($key,$value);
167
        }
168
    }
169
}
170
 
171
//*********************************************************
172
function isFile($file)
173
{
174
    $rtnValue = False;
175
 
176
    if (is_file($file))
177
    {
178
        $rtnValue = True;
179
    }
180
    else
181
    {
182
        if ($file == trim(shell_exec("ls ".$file)))
183
        {
184
            $rtnValue = True;
185
        }
186
    }
187
    return $rtnValue;
188
}
189
 
190
?>