Read database connection from config file

This commit is contained in:
root 2019-02-27 17:39:20 +01:00
parent 1e0cec945c
commit 2040b7be39
5 changed files with 31 additions and 14 deletions

View File

@ -23,6 +23,7 @@ require_once 'vendor/autoload.php';
die(); die();
} }
$cfg = include('accred_config.php');
$uname = $_SESSION['name']; $uname = $_SESSION['name'];
if($_POST['btncancel']) { if($_POST['btncancel']) {
@ -71,8 +72,8 @@ require_once 'vendor/autoload.php';
$mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']);
$mysqli = new mysqli("localhost", "caribanaaccred", "welcome99", "caribanaaccred");
if ($mysqli->connect_errno) { if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} }

View File

@ -1,8 +1,9 @@
<?php <?php
ini_set('display_errors', 0);
ini_set('display_startup_errors', 0);
error_reporting(E_ALL & ~E_NOTICE );
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL & ~E_NOTICE );
$cfg = include('accred_config.php');
// start session // start session
if (session_status() == PHP_SESSION_NONE) { if (session_status() == PHP_SESSION_NONE) {
session_start(); session_start();
@ -45,7 +46,7 @@ $objPHPExcel->getProperties()->setDescription("Accréditations 2017.");
$objPHPExcel->setActiveSheetIndex(0); $objPHPExcel->setActiveSheetIndex(0);
$query = "select * from submissions"; $query = "select * from submissions";
$mysqli = new mysqli("localhost", "caribanaaccred", "welcome99", "caribanaaccred"); $mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']);
if ($mysqli->connect_errno) { if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} }
@ -232,8 +233,7 @@ readfile($filename);
<?php <?php
$mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']);
$mysqli = new mysqli("localhost", "caribanaaccred", "welcome99", "caribanaaccred");
if ($mysqli->connect_errno) { if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} }

View File

@ -5,12 +5,19 @@
error_reporting(E_ALL & ~E_NOTICE ); error_reporting(E_ALL & ~E_NOTICE );
// Returns data to display list of entries to authenticated user // Returns data to display list of entries to authenticated user
$uid = $_SESSION['uid']; $uid = $_SESSION['uid'];
if(!$uid) { // if(!$uid) {
// die("User not authenticated!"); // die("User not authenticated!");
// }
try {
$cfg = include($_SERVER['DOCUMENT_ROOT'].'/accred_config.php');
}
catch(Exception $e) {
die("Unable to load configuration file!");
} }
$aid = $_GET['aid']; $aid = $_GET['aid'];
$isAdmin = $_SESSION['admin']==1; $isAdmin = $_SESSION['admin']==1;
$mysqli = new mysqli("localhost", "caribanaaccred", "welcome99", "caribanaaccred");
$mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']);
if ($mysqli->connect_errno) { if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} }

View File

@ -3,12 +3,11 @@ ini_set('display_errors', 1);
ini_set('display_startup_errors', 1); ini_set('display_startup_errors', 1);
error_reporting(E_ALL & ~E_NOTICE ); error_reporting(E_ALL & ~E_NOTICE );
// start session // start session
$cfg = include('accred_config.php');
if (session_status() == PHP_SESSION_NONE) { if (session_status() == PHP_SESSION_NONE) {
session_start(); session_start();
$userid = $_SESSION['uid']; $userid = $_SESSION['uid'];
} }
// If we are logged-in, redirect to the list page. // If we are logged-in, redirect to the list page.
if($userid) { if($userid) {
header("location: accred_list"); header("location: accred_list");
@ -58,13 +57,20 @@ function onSignIn(googleUser) {
console.log('Image URL: ' + profile.getImageUrl()); console.log('Image URL: ' + profile.getImageUrl());
console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present. console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present.
console.log('Token: ' + id_token); console.log('Token: ' + id_token);
console.log("Preparing to call tokensignin");
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest();
xhr.open('POST', 'https://ml.caribana.ch/accred/tokensignin');
xhr.open('POST', 'https://accred.caribana-festival.ch/tokensignin');
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.onload = function() { xhr.onload = function() {
console.log('Signed in as: ' + xhr.responseText); console.log('Signed in as: ' + xhr.responseText);
self.location = 'accred_list'; self.location = 'accred_list';
}; };
xhr.onerror = function() {
console.log("ERROR");
alert("Error");
};
console.log(xhr);
xhr.send('idtoken=' + id_token); xhr.send('idtoken=' + id_token);
} }
</script> </script>

View File

@ -1,10 +1,13 @@
<?php <?php
require_once 'vendor/autoload.php'; require_once 'vendor/autoload.php';
$cfg = include('accred_config.php');
session_start(); session_start();
$mode = $_POST['mode']; $mode = $_POST['mode'];
openlog('ACCRED', LOG_PID, LOG_LOCAL0); openlog('ACCRED', LOG_PID, LOG_LOCAL0);
if($mode=='logout') { if($mode=='logout') {
$mysqli = new mysqli("localhost", "caribanaaccred", "welcome99", "caribanaaccred");
$mysqli = new mysqli($cfg['host'], $cfg['user'],$cfg['pass'], $cfg['name']);
if ($mysqli->connect_errno) { if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} }
@ -42,7 +45,7 @@ if ($payload) {
// Is this user admin // Is this user admin
$_SESSION['admin'] = ''; $_SESSION['admin'] = '';
// Set to 1 to allow normal users to add new entries en edit existing // Set to 1 to allow normal users to add new entries en edit existing
// $_SESSION['allowedit'] = 1; $_SESSION['allowedit'] = 1;
if( array_key_exists($userid, $admins)) { if( array_key_exists($userid, $admins)) {
$_SESSION['admin'] = 1; $_SESSION['admin'] = 1;
} }