forked from BlackMac/timetrack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.php
81 lines (63 loc) · 1.68 KB
/
action.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
class TT_Action {
private $post;
private $session;
private $hash;
function __construct() {
$this->post = $_POST;
$this->startSession();
$this->dispatch();
}
private function startSession() {
session_start();
$this->session = $_SESSION;
if (isset($this->session['userhash'])) {
$this->hash = $this->session['userhash'];
} else {
echo "No Hash in session given";
exit;
}
}
private function dispatch()
{
if (!isset($this->post) || count($this->post) <= 0) {
echo "Wrong method";
return;
}
if (!isset($this->post['action']) || empty($this->post['action'])) {
echo "No action specified";
return;
}
$method = $this->post['action'] . 'Action';
if(method_exists($this, $method)) {
$this->$method();
} else {
echo "Wrong action specified";
return;
}
return;
}
private function changeuserdataAction()
{
if (!isset($this->post['changeuserdata_user'], $this->post['changeuserdata_pass'])) {
echo __METHOD__ . ': Required fields are missing';
return;
}
$newhash = md5($this->post['changeuserdata_user']."uphashseed".$this->post['changeuserdata_pass']);
$foldpath = realpath('logs/'.$this->hash.'.log');
$fnewpath = dirname($foldpath) . '/'.$newhash.'.log';
$result = rename($foldpath, $fnewpath);
if($result) {
$_SESSION['userhash'] = $newhash;
$this->redirect('show.php');
} else {
echo __METHOD__ . ': Error occurred during renaming.';
return;
}
}
private function redirect($whereTo)
{
header("Location: " . dirname($_SERVER['SCRIPT_NAME']) . '/' . $whereTo);
}
}
$action = new TT_Action();