|
@@ -1,10 +1,9 @@
|
|
|
<?php
|
|
<?php
|
|
|
- //include("../functions.php");
|
|
|
|
|
- //$con = startdb('rw');
|
|
|
|
|
|
|
+ // Gasteizko Margolariak API v3 //
|
|
|
|
|
|
|
|
- // $_GET valid parameters
|
|
|
|
|
- define('GET_USER', 'user');
|
|
|
|
|
- define('GET_PASS', 'pass');
|
|
|
|
|
|
|
+ // $_GET and $_POST valid parameters
|
|
|
|
|
+ define('POST_USER', 'user');
|
|
|
|
|
+ define('POST_PASS', 'pass');
|
|
|
define('GET_TITLE_ES', 'title_es');
|
|
define('GET_TITLE_ES', 'title_es');
|
|
|
define('GET_TITLE_EN', 'title_en');
|
|
define('GET_TITLE_EN', 'title_en');
|
|
|
define('GET_TITLE_EU', 'title_eu');
|
|
define('GET_TITLE_EU', 'title_eu');
|
|
@@ -18,16 +17,16 @@
|
|
|
define('GET_GM', 'gm');
|
|
define('GET_GM', 'gm');
|
|
|
|
|
|
|
|
// Valid values
|
|
// Valid values
|
|
|
- define('ACTION_TEXT', 'mensaje');
|
|
|
|
|
|
|
+ define('ACTION_TEXT', 'text');
|
|
|
define('ACTION_BLOG', 'blog');
|
|
define('ACTION_BLOG', 'blog');
|
|
|
- define('ACTION_ACTIVITIES', 'actividades');
|
|
|
|
|
- define('ACTION_GALLERY', 'galeria');
|
|
|
|
|
- define('ACTION_LOCALIZATION', 'localizacion');
|
|
|
|
|
|
|
+ define('ACTION_ACTIVITIES', 'activities');
|
|
|
|
|
+ define('ACTION_GALLERY', 'gallery');
|
|
|
|
|
+ define('ACTION_LOCATION', 'location');
|
|
|
define('ACTION_LABLANCA', 'lablanca');
|
|
define('ACTION_LABLANCA', 'lablanca');
|
|
|
- define('ACTION_SCHEDULE', 'programa');
|
|
|
|
|
- define('ACTION_GM_SCHEDULE', 'gprograma');
|
|
|
|
|
- define('ACTION_US', 'nosotros');
|
|
|
|
|
- $actions = [ACTION_TEXT, ACTION_BLOG, ACTION_ACTIVITIES, ACTION_GALLERY, ACTION_LOCALIZATION, ACTION_LABLANCA, ACTION_SCHEDULE, ACTION_GM_SCHEDULE, ACTION_US];
|
|
|
|
|
|
|
+ define('ACTION_SCHEDULE_CITY', 'schedule_city');
|
|
|
|
|
+ define('ACTION_SCHEDULE_GM', 'schedule_gm');
|
|
|
|
|
+ define('ACTION_US', 'us');
|
|
|
|
|
+ $actions = [ACTION_TEXT, ACTION_BLOG, ACTION_ACTIVITIES, ACTION_GALLERY, ACTION_LOCATION, ACTION_LABLANCA, ACTION_SCHEDULE_CITY, ACTION_SCHEDULE_GM, ACTION_US];
|
|
|
|
|
|
|
|
// Default values
|
|
// Default values
|
|
|
define('DEF_GM', 0);
|
|
define('DEF_GM', 0);
|
|
@@ -43,47 +42,13 @@
|
|
|
define('ERR_PERM', '-PERM:');
|
|
define('ERR_PERM', '-PERM:');
|
|
|
define('ERR_ID', '-ID:');
|
|
define('ERR_ID', '-ID:');
|
|
|
|
|
|
|
|
- /****************************************************
|
|
|
|
|
- * This function is called from almost everywhere at *
|
|
|
|
|
- * the beggining of the page. It initializes the *
|
|
|
|
|
- * session variables, connect to the db, enabling *
|
|
|
|
|
- * the variable $con for futher use everywhere in *
|
|
|
|
|
- * the php code, and populates the arrays $user *
|
|
|
|
|
- * and $permission, with info about the user. *
|
|
|
|
|
- * *
|
|
|
|
|
- * @return: (db connection): The connection handler. *
|
|
|
|
|
- ****************************************************/
|
|
|
|
|
- function startdb(){
|
|
|
|
|
- //Include the db configuration file. It's somehow like this
|
|
|
|
|
- /*
|
|
|
|
|
- <?php
|
|
|
|
|
- $host = 'XXXX';
|
|
|
|
|
- $db_name = 'XXXX';
|
|
|
|
|
- $username_ro = 'XXXX';
|
|
|
|
|
- $username_rw = 'XXXX';
|
|
|
|
|
- $pass_ro = 'XXXX';
|
|
|
|
|
- $pass_rw = 'XXXX';
|
|
|
|
|
- ?>
|
|
|
|
|
- */
|
|
|
|
|
- include('../../.htpasswd');
|
|
|
|
|
|
|
+ include('functions.php');
|
|
|
|
|
|
|
|
- //Connect to to database
|
|
|
|
|
- $con = mysqli_connect($host, $username_rw, $pass_rw, $db_name);
|
|
|
|
|
-
|
|
|
|
|
- //Set encoding options
|
|
|
|
|
- mysqli_set_charset($con, 'utf-8');
|
|
|
|
|
- header('Content-Type: text/html; charset=utf8');
|
|
|
|
|
- mysqli_query($con, 'SET NAMES utf8;');
|
|
|
|
|
-
|
|
|
|
|
- //Return the db connection
|
|
|
|
|
- return $con;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $con = startdb();
|
|
|
|
|
|
|
+ $con = startdb('rw');
|
|
|
|
|
|
|
|
// Get fields
|
|
// Get fields
|
|
|
- $user = mysqli_real_escape_string($con, $_GET[GET_USER]);
|
|
|
|
|
- $pass = mysqli_real_escape_string($con, $_GET[GET_PASS]);
|
|
|
|
|
|
|
+ $user = mysqli_real_escape_string($con, $_POST[POST_USER]);
|
|
|
|
|
+ $pass = mysqli_real_escape_string($con, $_POST[POST_PASS]);
|
|
|
$title_es = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_ES]));
|
|
$title_es = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_ES]));
|
|
|
$title_en = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_EN]));
|
|
$title_en = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_EN]));
|
|
|
$title_eu = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_EU]));
|
|
$title_eu = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_EU]));
|
|
@@ -100,16 +65,14 @@
|
|
|
$error = "";
|
|
$error = "";
|
|
|
|
|
|
|
|
// Validate user/pass
|
|
// Validate user/pass
|
|
|
- $q = mysqli_query($con, "SELECT id FROM user WHERE (lower(username) = lower('$user') OR lower(email) = lower('$user')) AND password = sha1(concat('$pass', sha1(salt)))");
|
|
|
|
|
- if (mysqli_num_rows($q) == 0){
|
|
|
|
|
|
|
+ $uid = login($con, $user, $pass);
|
|
|
|
|
+ if ($uid == -1){
|
|
|
error_log(":SECURITY: Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
|
|
error_log(":SECURITY: Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
|
|
|
- http_response_code(403); // Forbidden
|
|
|
|
|
- $error = $error . ERR_USER . mysqli_real_escape_string($con, $_GET[GET_USER]);
|
|
|
|
|
|
|
+ $error = $error . ERR_USER . mysqli_real_escape_string($con, $_POST[POST_USER]);
|
|
|
error_log($error);
|
|
error_log($error);
|
|
|
|
|
+ http_response_code(403); // Forbidden
|
|
|
exit(-1);
|
|
exit(-1);
|
|
|
}
|
|
}
|
|
|
- $r = mysqli_fetch_array($q);
|
|
|
|
|
- $uid = $r['id'];
|
|
|
|
|
|
|
|
|
|
//Validate fields
|
|
//Validate fields
|
|
|
if (strlen($title_es) == 0){
|
|
if (strlen($title_es) == 0){
|
|
@@ -156,12 +119,13 @@
|
|
|
|
|
|
|
|
//Insert
|
|
//Insert
|
|
|
if (strlen($error) == 0){
|
|
if (strlen($error) == 0){
|
|
|
- error_log("INSERT INTO notification (user, title_es, title_en, title_eu, text_es, text_en, text_eu, action, duration) VALUES ($uid, '$title_es', '$title_en', '$title_eu', '$text_es', '$text_en', '$text_eu', '$action', $duration);");
|
|
|
|
|
- mysqli_query($con, "INSERT INTO notification (user, title_es, title_en, title_eu, text_es, text_en, text_eu, action, duration) VALUES ($uid, '$title_es', '$title_en', '$title_eu', '$text_es', '$text_en', '$text_eu', '$action', $duration);");
|
|
|
|
|
|
|
+ mysqli_query($con, "INSERT INTO notification (user, title_es, title_en, title_eu, text_es, text_en, text_eu, action, duration) VALUES ($_SESSION[id], '$title_es', '$title_en', '$title_eu', '$text_es', '$text_en', '$text_eu', '$action', $duration);");
|
|
|
|
|
+ error_log("INSERT INTO notification (user, title_es, title_en, title_eu, text_es, text_en, text_eu, action, duration) VALUES ($_SESSION[id], '$title_es', '$title_en', '$title_eu', '$text_es', '$text_en', '$text_eu', '$action', $duration);");
|
|
|
http_response_code(204); // No content;
|
|
http_response_code(204); // No content;
|
|
|
exit(0);
|
|
exit(0);
|
|
|
}
|
|
}
|
|
|
else{
|
|
else{
|
|
|
|
|
+ http_response_code(400); // Bad request
|
|
|
error_log($error);
|
|
error_log($error);
|
|
|
exit(-6);
|
|
exit(-6);
|
|
|
}
|
|
}
|