Skip to content
Snippets Groups Projects
Commit 9255a112 authored by Hakkel Tamás's avatar Hakkel Tamás
Browse files

bring admin site back to life

parent 52c618f8
No related branches found
No related tags found
No related merge requests found
AuthType shibboleth
ShibRequireSession On
Require user hakta@login.ppke.hu
Require user botcs@login.ppke.hu
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
\ No newline at end of file
<?php <?php
if ( ! isset($_SERVER['uid']) AND ! in_array($_SERVER['uid'],array('hakta','botcs'))) die('Permission denied'); if ( ! isset($_SERVER['uid']) OR ! in_array($_SERVER['uid'],array('hakta','botcs')))
die('Permission denied');
// Tömörítőhöz kell require('../core/engine.php');
ob_start("ob_gzhandler");
// Header-ök function photo_number($data) {
header('Vary: Accept-Encoding'); return $data === NULL ? 0 : $data;
header('Pragma: no-cache'); }
header('Cache-Control: no-cache');
header('Accept-Ranges: bytes');
header('Content-Encoding: gzip');
$db = new PDO("mysql:dbname=sam;host=10.3.19.208", 'hakkelt', 'RFTGzhujD7_'); function site_content() {
$db->exec("set names utf8"); require('../core/db.php');
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
$result = $db->prepare(' $result = $db->prepare('
SELECT name,shibboleth,s, w as waiting,a as accepted, r as rejected FROM SELECT name, shibboleth, a as all_photos, v as verified, u as unverified FROM
user user
LEFT JOIN ( LEFT JOIN (
SELECT user_ID,count(*) s FROM suggestion GROUP BY user_ID SELECT user_ID,count(*) a FROM photo JOIN user USING(card_ID) GROUP BY user_ID
) all_suggestion USING(user_ID) ) all_photos USING(user_ID)
LEFT JOIN (
SELECT user_ID,count(*) w FROM suggestion LEFT JOIN annotation using(thumbnail_ID,user_ID) WHERE accepted IS NULL GROUP BY user_ID
) waiting_suggestion USING(user_ID)
LEFT JOIN ( LEFT JOIN (
SELECT user_ID,count(*) a FROM suggestion LEFT JOIN annotation using(thumbnail_ID,user_ID) WHERE accepted = 1 GROUP BY user_ID SELECT user_ID,count(*) v FROM photo JOIN user USING(card_ID) WHERE is_it_sure = 1 GROUP BY user_ID
) accepted_suggestion USING(user_ID) ) verified USING(user_ID)
LEFT JOIN ( LEFT JOIN (
SELECT user_ID,count(*) r FROM suggestion LEFT JOIN annotation using(thumbnail_ID,user_ID) WHERE accepted = 0 GROUP BY user_ID SELECT user_ID,count(*) u FROM photo JOIN user USING(card_ID) WHERE is_it_sure = 0 GROUP BY user_ID
) rejected_suggestion USING(user_ID) ) unverified USING(user_ID)
ORDER BY name ASC ORDER BY name ASC
'); ');
$result->execute(); $result->execute();
$result = $result->fetchAll(PDO::FETCH_ASSOC); $result = $result->fetchAll(PDO::FETCH_ASSOC); ?>
?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="PPKE ITK beléptető kapu">
<meta name="author" content="Hakkel Tamás">
<title>Sam</title>
<link rel="shortcut icon" href="../logo.ico">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4"
crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Quicksand:400,500" rel="stylesheet">
<script defer src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script defer src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ"
crossorigin="anonymous"></script>
<script defer src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm"
crossorigin="anonymous"></script>
<style>
body {
font-family: 'Quicksand', sans-serif;
font-weight: 300;
}
nav {
font-size: 25px;
box-shadow: 0px 3px 5px lightgrey;
font-weight: 500;
position: fixed;
}
#logo {
height: 2.5rem;
padding: 0rem 1rem 0rem 0rem;
}
</style>
</head>
<body>
<nav class="navbar fixed-top navbar-expand-sm navbar-light bg-light">
<a class="navbar-brand" href="#">
<img src="../logo.svg" width="30" height="30" class="d-inline-block align-top" alt="logo">
</a>
<div class="collapse navbar-collapse" id="navbarToggle">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="../">
<span class="text">Admin area</span>
<span class="text" style="display:none">Admin felület</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="https://users.itk.ppke.hu/~hakta/belepteto/selection/">
<span class="text">Selection</span>
<span class="text" style="display:none">Válogatás</span>
</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#">
<span class="text">Profile</span>
<span class="text" style="display:none">Profil</span>
</a>
</li>
</ul>
</div>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarToggle" aria-controls="navbarToggle"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
</nav>
<div class="container" style="margin-top:6em">
<div class="row"> <div class="row">
<div class="col-sm-10 offset-sm-1 col-lg-8 offset-lg-2"> <div class="col-sm-10 offset-sm-1 col-lg-8 offset-lg-2">
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead class="thead-light"> <thead class="thead-light">
<tr> <tr>
<th rowspan="2" style="vertical-align: middle;">Name</th> <th>Name</th>
<th rowspan="2" style="vertical-align: middle;">All</th> <th>All</th>
<th colspan="3" style="text-align: center;">suggestion</th> <th>Verified</th>
</tr> <th>Unverified</th>
<tr>
<th>Waiting</th>
<th>Accepted</th>
<th>Rejected</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($result as $row): ?> <?php foreach ($result as $row): ?>
<tr> <tr>
<td><a href="https://users.itk.ppke.hu/~hakta/belepteto/selection/?<?=$row['shibboleth']?>" target="_blank"><?=$row['name']?></a></td> <td><?=$row['name']?></td>
<td><?=is_null($row['s']) ? 0 : $row['s']?></td> <td><?=photo_number($row['all_photos'])?></td>
<td><?=is_null($row['waiting']) ? 0 : $row['waiting']?></td> <td>
<td><?=is_null($row['accepted']) ? 0 : $row['accepted']?></td> <a href="<?=BASE_URL?>verified/?<?=$row['shibboleth']?>" target="_blank">
<td><?=is_null($row['rejected']) ? 0 : $row['rejected']?></td> <?=photo_number($row['verified'])?>
</a>
</td>
<td>
<a href="<?=BASE_URL?>unverified/?<?=$row['shibboleth']?>" target="_blank">
<?=photo_number($row['unverified'])?>
</a>
</td>
</tr> </tr>
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
</div> </div>
</div> </div>
</div> <?php }
</body> $config = array(
'includes' => array(),
'navbar-active' => 'admin',
);
</html> render(array('admin' => 'Administration'));
\ No newline at end of file \ No newline at end of file
...@@ -10,13 +10,4 @@ if (! defined('CACHE')) { ...@@ -10,13 +10,4 @@ if (! defined('CACHE')) {
header('Accept-Ranges: bytes'); header('Accept-Ranges: bytes');
header('Vary: Accept-Encoding'); header('Vary: Accept-Encoding');
define(CORE_PATH,__DIR__.DIRECTORY_SEPARATOR); require('db.php');
\ No newline at end of file
$path = CORE_PATH.'credentials.txt';
$myfile = fopen($path, "r") or die("Unable to open file!");
$credentials = explode(PHP_EOL,fread($myfile,filesize($path)));
fclose($myfile);
$db = new PDO("mysql:dbname={$credentials[3]};host=".$credentials[0], $credentials[1], $credentials[2]);
$db->exec("set names utf8");
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
\ No newline at end of file
<?php
define(CORE_PATH,__DIR__.DIRECTORY_SEPARATOR);
$path = CORE_PATH.'credentials.txt';
$myfile = fopen($path, "r") or die("Unable to open file!");
$credentials = explode(PHP_EOL,fread($myfile,filesize($path)));
fclose($myfile);
$db = new PDO("mysql:dbname={$credentials[3]};host=".$credentials[0], $credentials[1], $credentials[2]);
$db->exec("set names utf8");
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING );
\ No newline at end of file
...@@ -116,9 +116,10 @@ function isAlreadyRegistered() { ...@@ -116,9 +116,10 @@ function isAlreadyRegistered() {
return IS_ALREADY_REGISTERED; return IS_ALREADY_REGISTERED;
} }
function render() { function render($menu = NULL) {
global $config; global $config;
$html = read_file('template.html'); $html = read_file('template.html');
if (!isset($menu))
$menu = (isAlreadyRegistered() ? $menu = (isAlreadyRegistered() ?
array( array(
'verified' => array('Verified', 'Hitelesített'), 'verified' => array('Verified', 'Hitelesített'),
......
...@@ -24,7 +24,7 @@ $result = $db->prepare(" ...@@ -24,7 +24,7 @@ $result = $db->prepare("
WHERE photo_ID=:picid"); WHERE photo_ID=:picid");
$result->execute(array('picid' => $pic_ID)); $result->execute(array('picid' => $pic_ID));
$result = $result->fetch(PDO::FETCH_NUM); $result = $result->fetch(PDO::FETCH_NUM);
if($result AND ($result[1] === $shibboleth OR $result[1] === 'hakta' OR $result[1] === 'botcs')) { if($result AND ($result[1] === $shibboleth OR $shibboleth === 'hakta' OR $shibboleth === 'botcs')) {
header('Content-type: image/jpeg'); header('Content-type: image/jpeg');
die($result[0]); die($result[0]);
} else { } else {
......
...@@ -3,13 +3,25 @@ function navbar($active,$menu) { ?> ...@@ -3,13 +3,25 @@ function navbar($active,$menu) { ?>
<nav class="navbar fixed-top navbar-expand-sm navbar-light bg-light"> <nav class="navbar fixed-top navbar-expand-sm navbar-light bg-light">
<a class="navbar-brand" href="https://sam.itk.ppke.hu"> <a class="navbar-brand" href="https://sam.itk.ppke.hu">
<img src="../logo.svg" width="30" height="30" class="d-inline-block align-top" alt="logo"> <img src="../logo.svg" width="30" height="30" class="d-inline-block align-top" alt="logo">
<span id="page-name" class="d-sm-none">{<?=$menu[$active][0]?>|<?=$menu[$active][1]?>}</span> <span id="page-name" class="d-sm-none">
<?php if (is_array($menu[$active])): ?>
{<?=$menu[$active][0]?>|<?=$menu[$active][1]?>}
<?php else: ?>
<?=$menu[$active]?>
<?php endif; ?>
</span>
</a> </a>
<div class="collapse navbar-collapse" id="navbarToggle"> <div class="collapse navbar-collapse" id="navbarToggle">
<ul class="navbar-nav"><?php <ul class="navbar-nav"><?php
foreach($menu as $key => $value): ?> foreach($menu as $key => $value): ?>
<li class="nav-item<?= $key===$active ? ' active' : ''?>"> <li class="nav-item<?= $key===$active ? ' active' : ''?>">
<a class="nav-link" href="<?=BASE_URL.$key?>">{<?=$value[0]?>|<?=$value[1]?>}</a> <?php if (is_array($value)): ?>
<a class="nav-link" href="<?=BASE_URL.$key?>">
{<?=$value[0]?>|<?=$value[1]?>}
</a>
<?php else: ?>
<a class="nav-link" href="<?=BASE_URL.$key?>"><?=$value?></a>
<?php endif; ?>
</li> <?php </li> <?php
endforeach; ?> endforeach; ?>
</ul> </ul>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment