-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·142 lines (134 loc) · 4.76 KB
/
index.php
File metadata and controls
executable file
·142 lines (134 loc) · 4.76 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset=utf-8>
<title>Open-Capture</title>
<link rel="icon" type="image/x-icon" href="src/assets/imgs/favicon.ico">
</head>
<style>
.instances_title h2 {
margin: 40px;
text-align: center;
}
.instances_title hr {
width: 30%;
color: #97BF3D;
margin-bottom: 40px;
}
.customs_list {
text-align: center;
}
.customs_list a {
color: #97BF3D;
text-decoration: none;
}
.customs_list button {
background-color: #4C4A4E;
color: #97BF3D;
border-radius: 0;
padding: 20px;
border: 0;
cursor: pointer;
margin: 10px;
}
</style>
<body>
<?php
$customsDir = 'custom/';
$customs = array_values(array_diff(scandir($customsDir), array('..', '.', 'custom.ini', 'custom.ini.default', '.htaccess')));
if (in_array('.noindex', $customs)) {
header('HTTP/1.0 403 Forbidden', true, 403);
die('403 Forbidden');
}
if (count($customs) == 1) {
?>
<script>
function isValidFQDN(str) {
return /(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/g.test(str);
}
let currentUrl = window.location.href.replaceAll('http:', '').replaceAll('https:', '').split("/").filter(elem => elem);
const currentCustom = '<?php echo $customs[0]; ?>';
if (isValidFQDN(currentUrl[0])) {
const fqdn = currentUrl[0].replaceAll('.', '_').replaceAll('-','_');
if (fqdn === currentCustom) {
location.href = "dist";
exit(0);
}
}
let lastUrlElement = currentUrl[currentUrl.length - 1];
if (lastUrlElement !== currentCustom) {
location.href = currentCustom + '/dist';
exit(0);
} else {
location.href = "dist";
exit(0);
}
</script>
<?php
}
?>
<div class="instances_title">
<h2>Liste des instances installées :</h2>
<hr>
</div>
<div class="customs_list">
<?php
function isValidDomainName($domain) {
return preg_match('/(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)/', $domain);
}
$current_url = sprintf(
'%s://%s/%s',
isset($_SERVER['HTTPS']) ? 'https' : 'http',
$_SERVER['HTTP_HOST'],
$_SERVER['REQUEST_URI']
);
$current_url = str_replace('http://', '', $current_url);
$current_url = str_replace('https://', '', $current_url);
$current_url = preg_replace('~/+~', '/', $current_url);
$exploded_fqdn = explode('/', $current_url);
$current_fqdn = $exploded_fqdn[0];
$customCpt = 0;
foreach ($customs as $custom) {
if (is_dir($custom)) {
if ($custom == $exploded_fqdn[count($exploded_fqdn) - 2]) {
?>
<script>
location.href = "dist";
</script>
<?php
}
$customCpt += 1;
$current_fqdn_clean = str_replace('.', '_', $current_fqdn);
$current_fqdn_clean = str_replace('-', '_', $current_fqdn_clean);
if (isValidDomainName($current_fqdn) && $current_fqdn_clean == $custom) {
?>
<a href="dist">
<button>
<?php echo $custom; ?>
</button>
</a>
<?php
} else {
?>
<a href="<?php echo $custom; ?>/dist">
<button>
<?php echo $custom; ?>
</button>
</a>
<?php
}
}
}
if ($customCpt == 0) {
?>
<span>
Aucune instance n'est configurée. Merci de vous référer à la
<a target="_blank" rel="noopener" href="https://kutt.it/DocumentationCreateInstance">documentation officielle</a>
pour en créer une.
</span>
<?php
}
?>
</div>
</body>
</html>