<commit_before><?php
	/* cryptocat */
	/* install directory and domain name */
	$install = 'https://crypto.cat/';
	$domain = "crypto.cat";
	/* https is highly recommended */
	$https = TRUE;
	/* where to store data */
	$data = '/srv/data/';
	/* time limit in seconds before deleting chat */
	$timelimit = 1800;
	/* set to 0 to disable automatic url linking */
	$genurl = 1;
	/* maximum users in a chat. untested above 8 */
	$maxusers = 8;
	/* default nicknames */
	$nicks = array('bunny', 'kitty', 'pony', 'puppy', 'squirrel', 'sparrow', 'kiwi', 'fox', 'owl', 'raccoon', 'koala', 'echidna', 'panther');
?>
<?php
	$maxinput = 256;
	$update = 2500;
	ini_set("session.entropy_file", "/dev/urandom");
	ini_set("session.entropy_length", "1024");
	error_reporting(0);
	session_set_cookie_params(0, '/', $domain, $https, TRUE);
	function getpeople($chat) {
		preg_match_all('/[a-z]{1,12}:/', $chat[0], $people);
		for ($i=0; $i < count($people[0]); $i++) {
			$people[0][$i] = substr($people[0][$i], 0, -1);
		}
		return $people[0];
	}
	if (isset($_GET['redirect']) && preg_match('/((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/i', $_GET['redirect'])) {
		print('<html><head><title>cryptocat</title><link rel="stylesheet" href="css/style.css" type="text/css" /></head>
		<body><div class="redirect"><img src="img/cryptocat.png" alt="" />You are leaving cryptocat to visit: <p><a href="'.htmlspecialchars($_GET['redirect']).'">'.htmlspecialchars($_GET['redirect']).'</a></p>Click the link to continue.</div></body></html>');
		exit;
	}
	else if (preg_match('/^[a-z]{1,12}$/', $_POST['nick']) && strlen($_POST['nick']) <= 12 && preg_match('/^\w+$/', $_POST['name']) && isset($_POST['public'])) {
		$_POST['name'] = strtolower($_POST['name']);
		session_name('s'.$_POST['name']);
		session_start();
		if (file_exists($data.$_POST['name'])) {
			$chat = file($data.$_POST['name']);
			if (time() - filemtime($data.$_POST['name']) > $timelimit) {
				unlink($data.$_POST['name']);
				enterchat($_POST['name'], $_POST['nick'], $_POST['public']);
				exit;
			}
		}
		if ($_POST['public'] == 'get') {
			print(trim($chat[0]));
			exit;
		}
		if (count(getpeople($chat)) >= $maxusers) {
			print("full");
			exit;
		}
		else if (in_array($_POST['nick'], getpeople($chat))) {
			print('inuse');
			exit;
		}
		else if (isset($_SESSION['nick'])) {
			preg_match('/'.$_SESSION['nick'].'\:[^\|]+\|/', $chat[0], $public);
			$chat[count($chat)+1] = "< ".$_SESSION['nick']." has left\n";
			$_SESSION['nick'] = $_POST['nick'];
			$chat[0] = str_replace($public[0], $_POST['nick'].':'.$_POST['public'].'|', $chat[0]);
			$chat[count($chat)+1] = "> ".$_POST['nick']." has arrived\n";
			file_put_contents($data.$_POST['name'], implode('', $chat), LOCK_EX);
		}
		else if (!isset($_SESSION['nick'])) {
			if (file_exists($data.$_POST['name'])) {
				enterchat($_POST['name'], $_POST['nick'], $_POST['public']);
			}
			else {
				enterchat($_POST['name'], $_POST['nick'], $_POST['public']);
				$chat = file($data.$_POST['name']);
			}
		}
		else {
			print('error');
		}
		exit;
	}
	else if (isset($_POST['nick'])) {
		print('error');
		exit;
	}
	else if (isset($_GET['chat']) && preg_match('/^\w+$/', $_GET['chat'])) {
		$_GET['chat'] = strtolower($_GET['chat']);
		session_name('s'.$_GET['chat']);
		session_start();
		if ($_SESSION['check'] == "OK") {
			$chat = file($data.$_GET['chat']);
			if (!$chat) {
				print('NOEXIST');
			}
			else if (isset($_GET['pos']) && $_GET['pos'] >= 0) {
				$_GET['pos'] = $_GET['pos'] + ($_SESSION['pos'] - 1);
				if ($_GET['pos'] <= count($chat) - 1) {
					if (preg_match('/^[a-z]{1,12}:\s\[B-C\].+\[E-C\]$/', $chat[$_GET['pos']])) {
						preg_match_all('/\([a-z]{1,12}\)[^\(|^\[]+/', $chat[$_GET['pos']], $match);
						preg_match('/^[a-z]{1,12}:/', $chat[$_GET['pos']], $nick);
						$nick = substr($nick[0], 0, -1);
						$ki = 0;
						$chat[$_GET['pos']] = preg_replace('/\[B-C\](.*)\[E-C\]/', '[B-C][E-C]', $chat[$_GET['pos']]);
						for ($ki=0; $ki <= count($match[0]); $ki++) {
							if (substr($match[0][$ki], 1, strlen($_SESSION['nick'])) == $_SESSION['nick']) {
								$match = substr($match[0][$ki], strlen($_SESSION['nick']) + 2);
								$chat[$_GET['pos']] = preg_replace('/\[B-C\](.*)\[E-C\]/', '[B-C]'.$match.'[E-C]', $chat[$_GET['pos']]);
								$ki = 9001;
							}
						}
					}
					if (!isset($nick) || ($nick != $_SESSION['nick'])) {
						print(htmlspecialchars($chat[$_GET['pos']]));
					}
					else {
						print("*");
					}
				}
			}
			else {
				print('NOLOGIN');
			}
		}
		exit;
	}
	else if (isset($_POST['name']) && preg_match('/^\w+$/', $_POST['name']) && isset($_POST['input']) && $_POST['input'] != '') {
		$_POST['name'] = strtolower($_POST['name']);
		session_name('s'.$_POST['name']);
		session_start();
		$chat = file($data.$_POST['name']);
		preg_match('/^[a-z]{1,12}:/', $_POST['input'], $thisnick);
		$thisnick = substr($thisnick[0], 0, -1);
		if (preg_match('/^[a-z]{1,12}:\s\[B-C\].+\[E-C\]$/', $_POST['input']) && $_SESSION['nick'] == $thisnick) {
			$chat = $_POST['input']."\n";
			file_put_contents($data.$_POST['name'], $chat, FILE_APPEND | LOCK_EX);
		}
		exit;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
	<meta name="description" content="Cryptocat allows you to instantly set up secure conversations. It's an open source encrypted, private alternative to invasive services such as Facebook chat." /><commit_msg>Fixed bug where messages would get sent multiple times<commit_after><?php
	/* cryptocat */
	/* install directory and domain name */
	$install = 'https://crypto.cat/';
	$domain = "crypto.cat";
	/* https is highly recommended */
	$https = TRUE;
	/* where to store data */
	$data = '/srv/data/';
	/* time limit in seconds before deleting chat */
	$timelimit = 1800;
	/* set to 0 to disable automatic url linking */
	$genurl = 1;
	/* maximum users in a chat. untested above 8 */
	$maxusers = 8;
	/* default nicknames */
	$nicks = array('bunny', 'kitty', 'pony', 'puppy', 'squirrel', 'sparrow', 'kiwi', 'fox', 'owl', 'raccoon', 'koala', 'echidna', 'panther');
?>
<?php
	$maxinput = 256;
	$update = 2500;
	ini_set("session.entropy_file", "/dev/urandom");
	ini_set("session.entropy_length", "1024");
	error_reporting(0);
	session_set_cookie_params(0, '/', $domain, $https, TRUE);
	function getpeople($chat) {
		preg_match_all('/[a-z]{1,12}:/', $chat[0], $people);
		for ($i=0; $i < count($people[0]); $i++) {
			$people[0][$i] = substr($people[0][$i], 0, -1);
		}
		return $people[0];
	}
	if (isset($_GET['redirect']) && preg_match('/((mailto\:|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/i', $_GET['redirect'])) {
		print('<html><head><title>cryptocat</title><link rel="stylesheet" href="css/style.css" type="text/css" /></head>
		<body><div class="redirect"><img src="img/cryptocat.png" alt="" />You are leaving cryptocat to visit: <p><a href="'.htmlspecialchars($_GET['redirect']).'">'.htmlspecialchars($_GET['redirect']).'</a></p>Click the link to continue.</div></body></html>');
		exit;
	}
	else if (preg_match('/^[a-z]{1,12}$/', $_POST['nick']) && strlen($_POST['nick']) <= 12 && preg_match('/^\w+$/', $_POST['name']) && isset($_POST['public'])) {
		$_POST['name'] = strtolower($_POST['name']);
		session_name('s'.$_POST['name']);
		session_start();
		if (file_exists($data.$_POST['name'])) {
			$chat = file($data.$_POST['name']);
			if (time() - filemtime($data.$_POST['name']) > $timelimit) {
				unlink($data.$_POST['name']);
				enterchat($_POST['name'], $_POST['nick'], $_POST['public']);
				exit;
			}
		}
		if ($_POST['public'] == 'get') {
			print(trim($chat[0]));
			exit;
		}
		if (count(getpeople($chat)) >= $maxusers) {
			print("full");
			exit;
		}
		else if (in_array($_POST['nick'], getpeople($chat))) {
			print('inuse');
			exit;
		}
		else if (isset($_SESSION['nick'])) {
			preg_match('/'.$_SESSION['nick'].'\:[^\|]+\|/', $chat[0], $public);
			$chat[count($chat)+1] = "< ".$_SESSION['nick']." has left\n";
			$_SESSION['nick'] = $_POST['nick'];
			$chat[0] = str_replace($public[0], $_POST['nick'].':'.$_POST['public'].'|', $chat[0]);
			$chat[count($chat)+1] = "> ".$_POST['nick']." has arrived\n";
			file_put_contents($data.$_POST['name'], implode('', $chat), LOCK_EX);
		}
		else if (!isset($_SESSION['nick'])) {
			if (file_exists($data.$_POST['name'])) {
				enterchat($_POST['name'], $_POST['nick'], $_POST['public']);
			}
			else {
				enterchat($_POST['name'], $_POST['nick'], $_POST['public']);
				$chat = file($data.$_POST['name']);
			}
		}
		else {
			print('error');
		}
		exit;
	}
	else if (isset($_POST['nick'])) {
		print('error');
		exit;
	}
	else if (isset($_GET['chat']) && preg_match('/^\w+$/', $_GET['chat'])) {
		$_GET['chat'] = strtolower($_GET['chat']);
		session_name('s'.$_GET['chat']);
		session_start();
		if ($_SESSION['check'] == "OK") {
			$chat = file($data.$_GET['chat']);
			if (!$chat) {
				print('NOEXIST');
			}
			else if (isset($_GET['pos']) && $_GET['pos'] >= 0) {
				$_GET['pos'] = $_GET['pos'] + ($_SESSION['pos'] - 1);
				if ($_GET['pos'] <= count($chat) - 1) {
					if (preg_match('/^[a-z]{1,12}:\s\[B-C\].+\[E-C\]$/', $chat[$_GET['pos']])) {
						preg_match_all('/\([a-z]{1,12}\)[^\(|^\[]+/', $chat[$_GET['pos']], $match);
						preg_match('/^[a-z]{1,12}:/', $chat[$_GET['pos']], $nick);
						$nick = substr($nick[0], 0, -1);
						$ki = 0;
						$chat[$_GET['pos']] = preg_replace('/\[B-C\](.*)\[E-C\]/', '[B-C][E-C]', $chat[$_GET['pos']]);
						for ($ki=0; $ki <= count($match[0]); $ki++) {
							if (substr($match[0][$ki], 1, strlen($_SESSION['nick'])) == $_SESSION['nick']) {
								$match = substr($match[0][$ki], strlen($_SESSION['nick']) + 2);
								$chat[$_GET['pos']] = preg_replace('/\[B-C\](.*)\[E-C\]/', '[B-C]'.$match.'[E-C]', $chat[$_GET['pos']]);
								$ki = 9001;
							}
						}
					}
					if ($_SESSION['lastchat'] != $chat[$_GET['pos']]) {
						if (!isset($nick) || ($nick != $_SESSION['nick'])) {
							print(htmlspecialchars($chat[$_GET['pos']]));
						}
						else {
							print("*");
						}
						$_SESSION['lastchat'] =	$chat[$_GET['pos']];
					}
				}
			}
			else {
				print('NOLOGIN');
			}
		}
		exit;
	}
	else if (isset($_POST['name']) && preg_match('/^\w+$/', $_POST['name']) && isset($_POST['input']) && $_POST['input'] != '') {
		$_POST['name'] = strtolower($_POST['name']);
		session_name('s'.$_POST['name']);
		session_start();
		$chat = file($data.$_POST['name']);
		preg_match('/^[a-z]{1,12}:/', $_POST['input'], $thisnick);
		$thisnick = substr($thisnick[0], 0, -1);
		if (preg_match('/^[a-z]{1,12}:\s\[B-C\].+\[E-C\]$/', $_POST['input']) && $_SESSION['nick'] == $thisnick) {
			$chat = $_POST['input']."\n";
			file_put_contents($data.$_POST['name'], $chat, FILE_APPEND | LOCK_EX);
		}
		exit;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xml:lang="en">
<head>
	<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
	<meta name="description" content="Cryptocat allows you to instantly set up secure conversations. It's an open source encrypted, private alternative to invasive services such as Facebook chat." />
{'fraction_non_alphanumeric': 0.2868352223190933, 'fraction_numerical': 0.017262423714036617, 'mean_word_length': 4.181120144534779, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1000701', 'n_tokens_mistral': 5017, 'n_tokens_neox': 4334, 'n_words': 741}