-
-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #376 from causefx/develop
Develop
- Loading branch information
Showing
19 changed files
with
1,179 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
$user = $_POST["user"]; | ||
|
||
if( $db = new SQLite3("../chatpack.db") ) | ||
{ | ||
if( $db->busyTimeout(5000) ) | ||
{ | ||
if( $db->exec("PRAGMA journal_mode = wal;") ) | ||
{ | ||
if( $result = @$db->query("SELECT timestamp, user FROM chatpack_log | ||
WHERE LOWER(user)= LOWER('$user') ORDER BY id DESC") ) | ||
{ | ||
if( $row = $result->fetchArray() ) | ||
{ | ||
$timestamp = $row["timestamp"]; | ||
$timenow = time(); | ||
|
||
if( $timestamp < $timenow - 2700 ) // user's last message too old means user offline | ||
{ | ||
echo "success"; | ||
} | ||
else // user's last message young enough means user still online | ||
{ | ||
echo "usernametaken"; | ||
} | ||
} | ||
else // username available | ||
{ | ||
echo "success"; | ||
} | ||
} | ||
else | ||
{ | ||
errormessage("querying database while checking user"); | ||
} | ||
|
||
if( !@$db->close() ) | ||
{ | ||
errormessage("closing database connection after checking user"); | ||
} | ||
} | ||
else | ||
{ | ||
errormessage("setting journal mode"); | ||
} | ||
} | ||
else | ||
{ | ||
errormessage("setting busy timeout"); | ||
} | ||
} | ||
else | ||
{ | ||
errormessage("using SQLite"); | ||
} | ||
|
||
function errormessage($msg) | ||
{ | ||
echo "<div style=\"margin-top: 50px;\">"; | ||
echo "<span style=\"color:#d89334;\">error </span>"; | ||
echo $msg; | ||
echo "</div>"; | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
$db = new SQLite3("../chatpack.db"); | ||
$db->busyTimeout(5000); | ||
$db->exec("PRAGMA journal_mode = wal;"); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
include("connect.php"); | ||
|
||
$likedmessages = array(); | ||
$unlikedmessages = array(); | ||
|
||
if( $result = $db->query("SELECT id, liked FROM chatpack_log") ) | ||
{ | ||
while( $row = $result->fetchArray() ) | ||
{ | ||
$messageid = $row["id"]; | ||
$liked = $row["liked"]; | ||
|
||
if( $liked == 1 ) | ||
{ | ||
array_push($likedmessages, $messageid); | ||
} | ||
else if( $liked == 0 ) | ||
{ | ||
array_push($unlikedmessages, $messageid); | ||
} | ||
} | ||
} | ||
|
||
$db->close(); | ||
|
||
// pass likes and unlikes back to chat.js | ||
|
||
$likes = json_encode($likedmessages); | ||
$unlikes = json_encode($unlikedmessages); | ||
$likesandunlikes = $likes . "#" . $unlikes; | ||
|
||
echo $likesandunlikes; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
include("connect.php"); | ||
|
||
$typingusers = array(); | ||
|
||
if( $result = $db->query("SELECT user FROM chatpack_typing") ) | ||
{ | ||
while( $row = $result->fetchArray() ) | ||
{ | ||
$user = $row["user"]; | ||
|
||
array_push($typingusers, $user); | ||
} | ||
} | ||
|
||
$db->close(); | ||
|
||
// pass typing users as JSON back to chat.js | ||
|
||
echo json_encode($typingusers); | ||
|
||
?> |
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
$data = $_POST["messagedata"]; | ||
$dataarray = explode("###", $data); | ||
$message = $dataarray[0]; | ||
$user = $dataarray[1]; | ||
$avatar = $dataarray[2]; | ||
|
||
include("connect.php"); | ||
|
||
if( strlen($message) > 0 ) | ||
{ | ||
$timestamp = time(); | ||
$message = utf8_decode($message); | ||
|
||
if( !stristr($message, "specialcharemoticon") ) // only encrypt text message | ||
{ | ||
$message = encryptmessage($message); | ||
} | ||
|
||
// log message | ||
|
||
$db->exec("INSERT INTO chatpack_log (timestamp, user, avatar, message) | ||
VALUES ('$timestamp', '$user', '$avatar', '$message')"); | ||
} | ||
|
||
function encryptmessage($msg) | ||
{ | ||
$key = "OEFKSjczdG5JWkFITHZNUmFLT1I4aWRWaVVWY3l1SXdJZ285V2R3Ri90QjF4NUU1VG9mNnM | ||
wcDRYWTQ1dEtRRXRYNlFWZE01QW1WS0hTNXZzaEtRbEdkcXY4cWpEOVRBYjBzSGJlRXVPWW | ||
9aWUtzNGZtK1BnRzRPeXk4ZWY0VUphUjc5VzRGQ2s0UXRrNENOWERJWmM3SWNFSEtpM0hpcT | ||
l2UVRET2UrMkxQR29ONVpOVDRnSHArTGVwQU15NXg4YzdNSWZQTlBOd2FlWmY2aWRQOUdSZVh | ||
3VXQ4a1JlNDkwMWZIVE42cmpIMkRrUkg1VnF1NC9zMmhTZFROVnNleVlSTnVvcWtDYlB3TEJU | ||
eDlRT3ZPZVQ2N0psT0NFNW5nekFCdG9xLzZ6K0Qva1V5UzNoVlAxWGt1ZittZnE5ek10Q2x4Q1 | ||
QrdHVRdEVoYUIxc2V1UjgrZDZyK1Zzem9LOEtpSG9halczNEpmem5nRWllSDBaRzNERHBTbUxB | ||
MGlodTZsclFEVzZLcjVBNEtYRUpxQXVNaEcycGN4U2VzT01NRlljM3pHL3Q1az0"; | ||
$initvector = "aC92eG1PdGhuMXN6"; | ||
$encryptedmessage = openssl_encrypt($msg, "AES-256-CBC", $key, 0, $initvector); | ||
$encryptedmessage = utf8_decode($encryptedmessage); | ||
|
||
return $encryptedmessage; | ||
} | ||
|
||
$db->close(); | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
post_max_size = 15M | ||
upload_max_filesize = 10M |
Oops, something went wrong.