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
// ADODB support.
26
include_once('db.php');
27
include_once("settingsfunctions.php");
28
 
29
// Create Connection.
30
$db = getdb();
31
 
32
loadSettings();
33
 
34
session_start("TorrentFlux");
35
include_once("config.php");
36
include("themes/".$cfg["default_theme"]."/index.php");
37
global $cfg;
38
if(isset($_SESSION['user']))
39
{
40
    header("location: index.php");
41
    exit;
42
}
43
ob_start();
44
?>
45
<!DOCTYPE html
46
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
47
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
48
<html xmlns="http://www.w3.org/1999/xhtml">
49
<head>
50
        <title><?php echo $cfg["pagetitle"] ?></title>
51
        <link rel="StyleSheet" href="themes/<?php echo $cfg["default_theme"] ?>/style.css" type="text/css" />
52
    <meta http-equiv="pragma" content="no-cache" />
53
    <meta content="charset=iso-8859-1" />
54
 
55
</head>
56
<body bgcolor="<?php echo $cfg["main_bgcolor"] ?>">
57
 
58
<script type="text/javascript">
59
<!--
60
function loginvalidate()
61
{
62
    msg = "";
63
    pass = document.theForm.iamhim.value;
64
    user = document.theForm.username.value;
65
    if (user.length < 1)
66
    {
67
        msg = msg + "* Username is required\n";
68
        document.theForm.username.focus();
69
    }
70
    if(pass.length<1)
71
    {
72
        msg = msg + "* Password is required\n";
73
        if (user.length > 0)
74
        {
75
            document.theForm.iamhim.focus();
76
        }
77
    }
78
 
79
    if (msg != "")
80
    {
81
        alert("Check the following:\n\n" + msg);
82
        return false;
83
    }
84
}
85
-->
86
</script>
87
 
88
 
89
<br /><br /><br />
90
<div align="center">
91
    <table border="1" bordercolor="<?php echo $cfg["table_border_dk"] ?>" cellpadding="0" cellspacing="0">
92
    <tr>
93
        <td>
94
        <table border="0" cellpadding="4" cellspacing="0" width="100%">
95
            <tr>
96
                    <td align="left" background="themes/<?php echo $cfg["default_theme"] ?>/images/bar.gif" bgcolor="<?php echo $cfg["main_bgcolor"] ?>">
97
                    <font class="title"><?php echo $cfg["pagetitle"] ?> Login</font>
98
                    </td>
99
            </tr>
100
        </table>
101
        </td>
102
    </tr>
103
    <tr>
104
        <td bgcolor="<?php echo $cfg["table_header_bg"] ?>">
105
        <div align="center">
106
        <table width="100%" bgcolor="<?php echo $cfg["body_data_bg"] ?>">
107
         <tr>
108
             <td>
109
             <table bgcolor="<?php echo $cfg["body_data_bg"] ?>" width="352 pixels" cellpadding="1">
110
             <tr>
111
                 <td>
112
                    <div align="center">
113
                     <table border="0" cellpadding="4" cellspacing="0">
114
                     <tr>
115
                     <td>
116
<?php
117
 
118
$user = strtolower(getRequestVar('username'));
119
 
120
$iamhim = addslashes(getRequestVar('iamhim'));
121
 
122
$create_time = time();
123
 
124
// Check for user
125
if(!empty($user) && !empty($iamhim))
126
{
127
    /* First User check */
128
    $next_loc = "index.php";
129
    $sql = "SELECT count(*) FROM tf_users";
130
    $user_count = $db->GetOne($sql);
131
    if($user_count == 0)
132
    {
133
        // This user is first in DB.  Make them super admin.
134
        // this is The Super USER, add them to the user table
135
 
136
        $record = array(
137
                        'user_id'=>$user,
138
                        'password'=>md5($iamhim),
139
                        'hits'=>1,
140
                        'last_visit'=>$create_time,
141
                        'time_created'=>$create_time,
142
                        'user_level'=>2,
143
                        'hide_offline'=>0,
144
                        'theme'=>$cfg["default_theme"],
145
                        'language_file'=>$cfg["default_language"]
146
                        );
147
        $sTable = 'tf_users';
148
        $sql = $db->GetInsertSql($sTable, $record);
149
 
150
        $result = $db->Execute($sql);
151
        showError($db,$sql);
152
 
153
        // Test and setup some paths for the TF settings
154
        $pythonCmd = $cfg["pythonCmd"];
155
        $btphpbin = getcwd() . "/TF_BitTornado/btphptornado.py";
156
        $tfQManager = getcwd() . "/TF_BitTornado/tfQManager.py";
157
        $maketorrent = getcwd() . "/TF_BitTornado/btmakemetafile.py";
158
        $btshowmetainfo = getcwd() . "/TF_BitTornado/btshowmetainfo.py";
159
        $tfPath = getcwd() . "/downloads/";
160
 
161
        if (!isFile($cfg["pythonCmd"]))
162
        {
163
            $pythonCmd = trim(shell_exec("which python"));
164
            if ($pythonCmd == "")
165
            {
166
                $pythonCmd = $cfg["pythonCmd"];
167
            }
168
        }
169
 
170
        $settings = array(
171
                            "pythonCmd" => $pythonCmd,
172
                            "btphpbin" => $btphpbin,
173
                            "tfQManager" => $tfQManager,
174
                            "btmakemetafile" => $maketorrent,
175
                            "btshowmetainfo" => $btshowmetainfo,
176
                            "path" => $tfPath
177
                        );
178
 
179
        saveSettings($settings);
180
        AuditAction($cfg["constants"]["update"], "Initial Settings Updated for first login.");
181
        $next_loc = "admin.php?op=configSettings";
182
    }
183
 
184
    $sql = "SELECT uid, hits, hide_offline, theme, language_file FROM tf_users WHERE user_id=".$db->qstr($user)." AND password=".$db->qstr(md5($iamhim));
185
    $result = $db->Execute($sql);
186
    showError($db,$sql);
187
 
188
    list(
189
    $uid,
190
    $hits,
191
    $cfg["hide_offline"],
192
    $cfg["theme"],
193
    $cfg["language_file"]) = $result->FetchRow();
194
 
195
    if(!array_key_exists("shutdown",$cfg))
196
        $cfg['shutdown'] = '';
197
    if(!array_key_exists("upload_rate",$cfg))
198
        $cfg['upload_rate'] = '';
199
 
200
    if($result->RecordCount()==1)
201
    {
202
        // Add a hit to the user
203
        $hits++;
204
 
205
        $sql = 'select * from tf_users where uid = '.$uid;
206
        $rs = $db->Execute($sql);
207
        showError($db, $sql);
208
 
209
        $rec = array(
210
                        'hits'=>$hits,
211
                        'last_visit'=>$db->DBDate($create_time),
212
                        'theme'=>$cfg['theme'],
213
                        'language_file'=>$cfg['language_file'],
214
                        'shutdown'=>$cfg['shutdown'],
215
                        'upload_rate'=>$cfg['upload_rate']
216
                    );
217
        $sql = $db->GetUpdateSQL($rs, $rec);
218
 
219
        $result = $db->Execute($sql);
220
        showError($db, $sql);
221
 
222
        $_SESSION['user'] = $user;
223
        session_write_close();
224
 
225
        header("location: ".$next_loc);
226
        exit();
227
    }
228
    else
229
    {
230
        AuditAction($cfg["constants"]["access_denied"], "FAILED AUTH: ".$user);
231
        echo "<div align=\"center\">Login failed.<br>Please try again.</div>";
232
    }
233
}
234
?>
235
 
236
                        <form name="theForm" action="login.php" method="post" onsubmit="return loginvalidate()">
237
                        <table width="100%" cellpadding="5" cellspacing="0" border="0">
238
                            <tr>
239
                                <td align="right">Username: </td>
240
                                <td><input type="text" name="username" value="" size="15" style="font-family:verdana,helvetica,sans-serif; font-size:9px; color:#000;" /></td>
241
                            </tr>
242
                            <tr>
243
                                <td align="right">Password:</td>
244
                                <td><input type="password" name="iamhim" value="" size="15" style="font-family:verdana,helvetica,sans-serif; font-size:9px; color:#000" /></td>
245
                            </tr>
246
                            <tr>
247
                                <td colspan="2" align="center"><input class="button" type="submit" value="Login"  /></td>
248
                            </tr>
249
                        </table>
250
                        </form>
251
                    </td>
252
                    </tr>
253
                    </table>
254
                    </div>
255
                </td>
256
            </tr>
257
            </table>
258
            </td>
259
        </tr>
260
        </table>
261
        </div>
262
        </td>
263
    </tr>
264
    </table>
265
 
266
</div>
267
 
268
<script language="JavaScript">
269
    document.theForm.username.focus();
270
</script>
271
 
272
</body>
273
</html>
274
 
275
 
276
<?php
277
ob_end_flush();
278
 
279
?>
280