This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.php
94 lines (78 loc) · 2.66 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
# Shared-Secrets v0.8b0
#
# Copyright (c) 2016, SysEleven GmbH
# All rights reserved.
#
# This page allows you to share a secret through a secret sharing link.
# The secret is stored in the secret sharing link and not on the server.
# A secret sharing link can only be used once.
#
# The actions can be found in ./actions/<name>.php
#
# The configuration can be found in ./config.php
#
# The pages can be found in ./pages/<name>/get.php and ./pages/<name>/post.php
#
# The template can be found in ./template/header.php and ./template/footer.php
# prevent direct access
define("SYS11_SECRETS", true);
# store the __DIR__ constant in an additional constant
# so that is does not change between script files
define("ROOT_DIR", __DIR__);
# include required configuration
require_once(ROOT_DIR."/config.php");
# include required defines
require_once(ROOT_DIR."/libs/shared-secrets.def.php");
# include required execution functions
require_once(ROOT_DIR."/libs/shared-secrets.exec.php");
# set default timezone because PHP dislikes to use system defaults
date_default_timezone_set(DEFAULT_TIMEZONE);
# prepare client IP
$client_ip = null;
if (LOG_IP_ADDRESS) {
$client_ip = $_SERVER["REMOTE_ADDR"];
}
define("CLIENT_IP", $client_ip);
# prepare request method
define("REQUEST_METHOD", strtolower($_SERVER["REQUEST_METHOD"]));
# prepare param
$param = null;
if (isset($_POST[PARAM_NAME])) {
if (!empty($_POST[PARAM_NAME])) {
$param = $_POST[PARAM_NAME];
}
}
define("SECRET_PARAM", $param);
# prepare URI
$uri = $_SERVER["REQUEST_URI"];
if (0 === stripos($uri, "/")) {
$uri = substr($uri, 1);
}
# handle URL encoded URIs
if (false !== strpos($uri, URL_ENCODE_MARKER)) {
$uri = urldecode($uri);
}
define("SECRET_URI", $uri);
# prepare action name, show read page by default
$action = READ_PAGE_NAME;
# show share page if no URI is given
if (empty(SECRET_URI)) {
$action = SHARE_PAGE_NAME;
} else {
# show pages based on page URI
if (in_array(SECRET_URI, array(HOW_PAGE_NAME, IMPRINT_PAGE_NAME))) {
$action = SECRET_URI;
}
}
define("SECRET_ACTION", $action);
# check if the GnuPG PECL package is available
define("GNUPG_PECL", (extension_loaded("gnupg") && is_dir(GPG_HOME_DIR)));
# only proceed when a GET or POST request is encountered
if (in_array(REQUEST_METHOD, array("get", "post"))) {
# import actions based on action name
require_once(ROOT_DIR."/actions/".SECRET_ACTION.".php");
# import pages based on action name and request method
require_once(ROOT_DIR."/pages/".SECRET_ACTION."/".REQUEST_METHOD.".php");
}
?>