-
Notifications
You must be signed in to change notification settings - Fork 106
/
profile.php
215 lines (177 loc) · 6.59 KB
/
profile.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
<?php
/*
* Paste <https://github.com/jordansamuel/PASTE>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* 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 in GPL.txt for more details.
*/
// PHP <5.5 compatibility
require_once('includes/password.php');
session_start();
require_once('config.php');
require_once('includes/functions.php');
// UTF-8
header('Content-Type: text/html; charset=utf-8');
$date = date('jS F Y');
$ip = $_SERVER['REMOTE_ADDR'];
$data_ip = file_get_contents('tmp/temp.tdata');
$con = mysqli_connect($dbhost, $dbuser, $dbpassword, $dbname);
if (mysqli_connect_errno()) {
die("Unable to connect to database");
}
$query = "SELECT * FROM site_info";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$title = Trim($row['title']);
$des = Trim($row['des']);
$baseurl = Trim($row['baseurl']);
$keyword = Trim($row['keyword']);
$site_name = Trim($row['site_name']);
$email = Trim($row['email']);
$twit = Trim($row['twit']);
$face = Trim($row['face']);
$gplus = Trim($row['gplus']);
$ga = Trim($row['ga']);
$additional_scripts = Trim($row['additional_scripts']);
}
// Set theme and language
$query = "SELECT * FROM interface";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$default_lang = Trim($row['lang']);
$default_theme = Trim($row['theme']);
}
require_once("langs/$default_lang");
$p_title = $lang['myprofile']; //"My Profile";
// Check if IP is banned
if ( is_banned($con, $ip) ) die($lang['banned']); // "You have been banned from ".$site_name;
// Site permissions
$query = "SELECT * FROM site_permissions where id='1'";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$siteprivate = Trim($row['siteprivate']);
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
} else {
if ($siteprivate =="on") {
$privatesite = "on";
}
}
// Check if already logged in
if (isset($_SESSION['token'])) {
} else {
header("Location: ./login.php");
}
// Logout
if (isset($_GET['logout'])) {
header('Location: ' . $_SERVER['HTTP_REFERER']);
unset($_SESSION['token']);
unset($_SESSION['oauth_uid']);
unset($_SESSION['username']);
session_destroy();
}
$user_username = htmlentities(Trim($_SESSION['username']));
$query = "SELECT * FROM users WHERE username='$user_username'";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$user_oauth_uid = $row['oauth_uid'];
$user_id = $row['id'];
$user_email_id = $row['email_id'];
$user_full_name = $row['full_name'];
$user_platform = Trim($row['platform']);
$user_verified = $row['verified'];
$user_date = $row['date'];
$user_ip = $row['ip'];
$user_password = $row['password'];
}
if ($user_oauth_uid == '0') {
$user_oauth_uid = "None";
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['cpassword'])) {
$user_new_full = Trim(htmlspecialchars($_POST['full']));
$user_old_pass = $_POST['old_password'];
$user_new_cpass = password_hash($_POST['password'], PASSWORD_DEFAULT);
if (password_verify($user_old_pass, $user_password)) {
$query = "UPDATE users SET full_name='$user_new_full', password='$user_new_cpass' WHERE username='$user_username'";
$result = mysqli_query($con, $query);
if (mysqli_errno($con)) {
$success = $lang['profileerror']; //" Unable to update the profile information ";
} else {
$success = $lang['profileupdated']; //" Your profile information is updated ";
}
} else {
$error = $lang['oldpasswrong']; // " Your old password is wrong.";
}
} else {
$error = $lang['error']; //"Something went wrong.";
}
}
// Page views
$query = "SELECT @last_id := MAX(id) FROM page_view";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$last_id = $row['@last_id := MAX(id)'];
}
if ($last_id) {
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$last_date = $row['date'];
}
}
if ($last_date == $date) {
if (str_contains($data_ip, $ip)) {
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$last_tpage = Trim($row['tpage']);
}
$last_tpage = $last_tpage + 1;
// IP already exists, update page views.
$query = "UPDATE page_view SET tpage=$last_tpage WHERE id=" . Trim($last_id);
mysqli_query($con, $query);
} else {
$query = "SELECT * FROM page_view WHERE id=" . Trim($last_id);
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$last_tpage = Trim($row['tpage']);
$last_tvisit = Trim($row['tvisit']);
}
$last_tpage = $last_tpage + 1;
$last_tvisit = $last_tvisit + 1;
// Update both tpage and tvisit.
$query = "UPDATE page_view SET tpage=$last_tpage,tvisit=$last_tvisit WHERE id=" . Trim($last_id);
mysqli_query($con, $query);
file_put_contents('tmp/temp.tdata', $data_ip . "\r\n" . $ip);
}
} else {
// Delete the file and clear data_ip
unlink("tmp/temp.tdata");
$data_ip = "";
// New date is created
$query = "INSERT INTO page_view (date,tpage,tvisit) VALUES ('$date','1','1')";
mysqli_query($con, $query);
// Update the IP
file_put_contents('tmp/temp.tdata', $data_ip . "\r\n" . $ip);
}
$total_pastes = getTotalPastes($con, $user_username);
$query = "SELECT * FROM ads WHERE id='1'";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$text_ads = Trim($row['text_ads']);
$ads_1 = Trim($row['ads_1']);
$ads_2 = Trim($row['ads_2']);
}
// Theme
require_once('theme/' . $default_theme . '/header.php');
require_once('theme/' . $default_theme . '/profile.php');
require_once('theme/' . $default_theme . '/footer.php');
?>