<?php
//CONFIG START
//Recaptcha Config
define("RECAPTCHA_PUBLIC","xxxx");
define("RECAPTCHA_PRIVATE","yyyy");
//Time interval to keep track of users in seconds
define("IP_THROTTLE_TIME",60*60*24);
//Amount of sent messages per time interval
define("IP_THROTTLE_COUNT",2);
//Database path
define("SQLITE_PATH",dirname(__FILE__).'/tracking.sqlite');
//Your SMS number including country prefix!
define("SMSTRADE_TO","003526917890XX");
//Length in SMS's (153 char par SMS unless single SMS = 160char)
define("SMSTRADE_MAXSMS",2);
//SMSTRADE private key
define("SMSTRADE_KEY","xxxxx");
//SMSTRADE Route to use (basic, gold or direct)
define("SMSTRADE_ROUTE","basic");
//SMSTRADE from
define("SMSTRADE_FROM","003523694xx");
//CONFIG END
require_once('recaptchalib.php');
$error = false;
if(isset($_POST['message']) && isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) {
//Check ReCaptcha first
if(!recaptcha_check_answer($privatekey,$_SERVER["REMOTE_ADDR"],$_POST["recaptcha_challenge_field"],$_POST["recaptcha_response_field"])->is_valid) {
$error = "Sicherheitscode inkorrekt";
}
//Open SQLite DB
if(!$error) {
$db_existed = file_exists(SQLITE_PATH);
if($sqlite = sqlite_open(SQLITE_PATH,0666,$sqliteerror)) {
if(!$db_existed) {
sqlite_query($sqlite,"CREATE TABLE messages (from,content,timestamp)");
}
else $error = "Fehler beim Öffnen der Datenbank: ".$sqliteerror;
}
//Check if user is throttled
if(!$error) {
$query = sqlite_query("SELECT ROWID FROM messages WHERE from = '".$_SERVER['REMOTE_ADDR']."' AND timestamp > '".(time()-IP_THROTTLE_TIME)."' LIMIT ".IP_THROTTLE_COUNT);
if(sqlite_num_rows($query) == IP_THROTTLE_COUNT) $error = "Sie haben bereits Ihr Anfragelimit erreicht!";
}
//Akismet
//- not implemented -
//SMS Laenge
if(!$error) {
$maxchar = (SMSTRADE_MAXSMS == 1) ? 160 : 153 * SMSTRADE_MAXSMS;
if(strlen($_POST['message']) > $maxchar) $error = "Sie haben die maximale Zeichenzahl überschritten!";
$multisms = (strlen($_POST['message']) > 160) ? true : false;
}
//Versenden der Nachricht
if(!$error) {
$check = @file_get_contents("http://gateway.smstrade.de/?key=".SMSTRADE_KEY."&to=".SMSTRADE_TO."&from=".SMSTRADE_FROM."&message".urlencode($_POST['message'])."&route=".SMSTRADE_ROUTE."&from=".urlencode(SMSTRADE_FROM).($multisms?"&concat=1":""));
if(!$check) $error = "Konnte keine Verbindung zum SMS-Gateway herstellen!";
if(trim($check) != 100) $error = "SMS konnte nicht versandt werden! (Code: ".$check.")";
}
//Eintragen in die DB
if(!$error) {
sqlite_query("INSERT INTO messages (from,content,timestamp) VALUES ('".$_SERVER['REMOTE_ADDR']."','".sqlite_escape_string($_POST['message'])."','".time()."')");
}
}
?>
<html>
<head>
<title>Test</title>
</head>
<body>
<? if($error) { ?>
<div style="border:1px solid;"><?=$error;?></div>
<? } ?>
<form method="POST" action="">
<textarea id="message" name="message" style="width:400px; height:100px;" onKeyUp="document.getElementById('message_counter').innerHTML = this.value.length;"><?=isset($_POST['message'])?$_POST['message']:'';?></textarea>
<div id="message_counter"><noscript>Aktivieren Sie Javascript!</noscript><script type="text/javascript">document.getElementById('message_counter').innerHTML = document.getElementById('message').value.length;</script></div>
<br>
<?=recaptcha_get_html(RECAPTCHA_PUBLIC);?>
<br>
<input type="submit" value="Absenden">
</form>
</body>
</html>