Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added files of main directory

  • Loading branch information...
commit aeb85bd15c53701e67abedb613e0e5d10676c18b 1 parent 1c7a47c
@DerWaldschrat authored
View
100 coreconfig.online.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * This config file prepares everything for DEVELOPMENT.
+ * You should change this in a productive area to the coreconfig.production.php, make sure you rename it after deleting this file!
+ * */
+defined("__EXEC") or die;
+// Start a session
+if (!defined("SESSION_INIT")) {
+ require IN . "session" . PHP_EX;
+}
+error_reporting(0);
+// do not call the mail function directly, because we cant be sure to use it on localhost
+$mail = "mail";
+
+
+/**
+ * Create Url to path, needs configuration
+ * */
+function getUrlToPath($path)
+{
+ return "%%ROOT%%" . $path;
+}
+
+
+
+/**
+ * Get connection to the database
+ * */
+$__DB = null;
+function db()
+{
+ global $__DB;
+ if($__DB === null) {
+ $__DB = new mysqli("localhost", "%%DB_USER%%", "%%DB_PASS%%", "%%DB_NAME%%");
+ $__DB->set_charset("utf8");
+ }
+ return $__DB;
+}
+
+$pre = "abi_";
+define("USER", $pre . "user");
+define("USER_DATA", $pre . "user_data");
+define("QUOTE", $pre . "quote");
+define("COMMENT", $pre . "comment");
+define("AWARD", $pre . "award");
+define("CATEGORY", $pre . "category");
+
+
+/**
+ * Executes a query and tells if it was successful.
+ * */
+function exQuery($query, $affected = 0) {
+ return $query->execute() && $query->affected_rows > $affected;
+}
+/**
+ * Shorthand for header("HTTP/1.1 404 Not Found");
+ * */
+function h404($json = null)
+{
+ header("HTTP/1.1 404 Not Found");
+ if ($json !== null) {
+ header("Content-Type: application/json");
+ echo json_encode($json);
+ }
+}
+
+/**
+ * Fails with a little message
+ * */
+function fail ($message = null) {
+ if ($message !== null && !is_array($message)) {
+ $message = array("message" => $message);
+ }
+ h404($message);
+ exit;
+}
+
+function hJSON($json = null)
+{
+ header("Content-Type: application/json");
+ if ($json !== null) {
+ echo json_encode($json);
+ }
+}
+
+function dateChangeFromISO($date) {
+ if (strlen($date) !== 10) return "00.00.0000";
+ $date = explode("-", $date);
+ return $date[2].".".$date[1].".".$date[0];
+}
+
+function dateChangeToISO($date) {
+ if(strlen($date) !== 10) return "0000-00-00";
+ $date = explode(".", $date);
+ return $date[2].".".$date[1].".".$date[0];
+}
+
+
+
+?>
View
122 coreconfig.php
@@ -0,0 +1,122 @@
+<?php
+/**
+ * This config file prepares everything for DEVELOPMENT.
+ * You should change this in a productive area to the coreconfig.production.php, make sure you rename it after deleting this file!
+ * */
+defined("__EXEC") or die;
+// Start a session
+if (!defined("SESSION_INIT")) {
+ require IN . "session" . PHP_EX;
+}
+error_reporting(E_ALL | E_STRICT);
+// do not call the mail function directly, because we cant be sure to use it on localhost
+$mail = "mail_hooking";
+require IN . "developer/mailhook" . PHP_EX;
+
+
+/**
+ * Create Url to path, needs configuration
+ * */
+function getUrlToPath($path)
+{
+ return "http://localhost/abi/" . $path;
+}
+
+
+
+/**
+ * Get connection to the database
+ * */
+
+//Only for testing purposes
+class mysqltest extends mysqli {
+ public function __construct() {
+ parent::__construct("localhost", "root", "", "abi");
+ }
+
+ /*public function prepare($query) {
+ $this->_log($query);
+ return parent::prepare($query);
+ }
+
+ public function query($query, $resultmode = MYSQLI_STORE_RESULT ) {
+ $this->_log($query);
+ return parent::query($query, $resultmode);
+ }
+
+ private function _log($query) {
+ file_put_contents(__DIR__ . "/__queries.sql", $query . "\n", FILE_APPEND);
+ } */
+}
+$__DB = null;
+function db()
+{
+ global $__DB;
+ if($__DB === null) {
+ $__DB = new mysqltest();
+ $__DB->set_charset("utf8");
+ }
+ return $__DB;
+}
+
+$pre = "abi_";
+define("USER", $pre . "user");
+define("USER_DATA", $pre . "user_data");
+define("QUOTE", $pre . "quote");
+define("COMMENT", $pre . "comment");
+define("AWARD", $pre . "award");
+define("CATEGORY", $pre . "category");
+
+
+/**
+ * Executes a query and tells if it was successful.
+ * */
+function exQuery($query, $affected = 0) {
+ return $query->execute() && $query->affected_rows > $affected;
+}
+/**
+ * Shorthand for header("HTTP/1.1 404 Not Found");
+ * */
+function h404($json = null)
+{
+ header("HTTP/1.1 404 Not Found");
+ if ($json !== null) {
+ header("Content-Type: application/json");
+ echo json_encode($json);
+ }
+}
+
+/**
+ * Fails with a little message
+ * */
+function fail ($message = null) {
+ if ($message !== null && !is_array($message)) {
+ $message = array("message" => $message);
+ }
+ h404($message);
+ exit;
+}
+
+function hJSON($json = null)
+{
+ header("Content-Type: application/json");
+ if ($json !== null) {
+ echo json_encode($json);
+ }
+}
+
+function dateChangeFromISO($date) {
+ if (strlen($date) !== 10) return "00.00.0000";
+ $date = explode("-", $date);
+ return $date[2].".".$date[1].".".$date[0];
+}
+
+function dateChangeToISO($date) {
+ if(strlen($date) !== 10) return "0000-00-00";
+ $date = explode(".", $date);
+ return $date[2].".".$date[1].".".$date[0];
+}
+
+
+
+?>
View
10 hasher.php
@@ -0,0 +1,10 @@
+<?php
+function hashme($pass, $nick)
+{
+ return sha1($pass . $nick . "realLife");
+}
+
+
+
+
+?>
View
66 mapper.php
@@ -0,0 +1,66 @@
+<?php
+defined("__EXEC") or die;
+$__METHOD = strtolower($_SERVER["REQUEST_METHOD"]);
+$__BODY = null;
+$__BODYASJSON = null;
+function body() {
+ global $__BODY, $__METHOD;
+ if($__BODY === null) {
+ $__BODY = file_get_contents("php://input");
+ }
+ return $__BODY;
+}
+
+function bodyAsJSON($assoc = false) {
+ global $__BODYASJSON;
+ if ($__BODYASJSON === null) {
+ $__BODYASJSON = json_decode(body(), $assoc);
+ }
+ return $__BODYASJSON;
+}
+
+function get($file) {
+ global $__METHOD;
+ if($__METHOD === "get") {
+ if (is_callable($file)) {
+ $file();
+ } else {
+ require $file;
+ }
+ }
+}
+
+function post($file) {
+ global $__METHOD;
+ if ($__METHOD === "post") {
+ if (is_callable($file)) {
+ $file();
+ } else {
+ require $file;
+ }
+ }
+}
+
+function put($file) {
+ global $__METHOD;
+ if ($__METHOD === "put") {
+ if (is_callable($file)) {
+ $file();
+ } else {
+ require $file;
+ }
+ }
+}
+
+function delete($file) {
+ global $__METHOD;
+ if ($__METHOD === "delete") {
+ if (is_callable($file)) {
+ $file();
+ } else {
+ require $file;
+ }
+ }
+}
+
+?>
View
38 registerconfirm.php
@@ -0,0 +1,38 @@
+<?php
+define("__EXEC", true);
+define("IN", "./");
+define("PHP_EX", ".php");
+
+require IN . "coreconfig" . PHP_EX;
+
+$query = $_SERVER["QUERY_STRING"];
+if (preg_match("/^[a-z0-9]{96,96}$/", $query) == 0) {
+ h404();
+} else {
+ $file = "__registered/" . $query . ".json";
+ if (!file_exists($file)) {
+ h404();
+ } else {
+ $user = json_decode(file_get_contents($file));
+ require IN . "validator" . PHP_EX;
+ if (!hasAllSet($user, array("nickname", "vorname", "nachname", "passwort", "email", "userid", "geschlecht"))) {
+ h404();
+ } else {
+ // Jetzt können wir den User eintragen
+ $db = db();
+ $query = $db->prepare("UPDATE " . USER . " SET nickname = ?, vorname = ?, nachname = ?, passwort = ?, email = ?, geschlecht = ? WHERE userid = ?");
+ $query->bind_param("ssssssi", $user->nickname, $user->vorname, $user->nachname, $user->passwort, $user->email, $user->geschlecht, $user->userid);
+ if (exQuery($query)) {
+ unlink($file);
+ header("Location: ".getUrlToPath("succeedRegister.html#" . $user->nickname));
+ } else {
+ header("Location: ".getUrlToPath("failRegister.html#" . $user->nickname));
+ }
+ }
+ }
+}
+
+
+
+
+?>
View
10 session.php
@@ -0,0 +1,10 @@
+<?php
+session_start();
+define("SESSION_INIT", true);
+function isLoggedin($required = 0) {
+ return isset($_SESSION["user"]["loggedin"]) && $_SESSION["user"]["loggedin"] === true && $_SESSION["user"]["rights"] >= $required;
+}
+function userField($field) {
+ return $_SESSION["user"][$field];
+}
+?>
View
39 validator.php
@@ -0,0 +1,39 @@
+<?php
+defined("__EXEC") or die;
+
+
+// Checks if all values of the object exist: EMPTY-check
+function hasAllSet($obj, array $keys) {
+ foreach ($keys as $key) {
+ if (empty($obj->{$key})) return false;
+ }
+ return true;
+}
+// Checks if all values of the object exist: !ISSET-check
+function hasAllSetIsset($obj, array $keys) {
+ foreach ($keys as $key) {
+ if (!isset($obj->{$key})) return false;
+ }
+ return true;
+}
+
+// Checks for a valid email-address
+function isEmail($value)
+{
+ // TODO
+ return preg_match("/^[a-zA-Z0-9-_]+(\.[a-zA-Z0-9-_]*)*@([a-zA-Z0-9-_]+\.)+[a-zA-Z]{2,4}$/", $value) != 0;
+}
+// Checks for a valid link
+function isLink($value)
+{
+ // TODO
+ return true;
+}
+// Checks for a valid length
+function hasRightLength($value, $min, $max = -1) {
+ $len = strlen($value);
+ return ($min === -1 || $len >= $min) && ($max === -1 || $len <= $max);
+}
+
+
+?>
Please sign in to comment.
Something went wrong with that request. Please try again.