-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
executable file
·157 lines (153 loc) · 5.49 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<?php
require_once './include/page.php';
$page = new Page("index");
function endsWith($haystack, $needle) {
$length = strlen($needle);
if(!$length)
return true;
return substr($haystack, -$length) === $needle;
}
function execPrint($command) {
$result = array();
exec($command, $result);
return $result;
/*print("<pre>");
foreach ($result as $line) {
print($line . "\n");
}
print("</pre>");*/
}
if(isset($_SESSION["is_admin"]) && $_SESSION["is_admin"] == 1) {
if(isset($_POST["action"])) {
$action = $_POST["action"];
if($action == "pull") {
// Print the exec output inside of a pre element
$pullResult = execPrint("git pull");
//execPrint("git status");
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<?php $page->print_common_head(); ?>
<title>Positivity - Index</title>
</head>
<body>
<?php
$page->show_topbar();
?>
<div class="page-wrapper">
<?php
$page->show_header();
?>
<div class="content-wrapper">
<div class="content">
<div class="container">
<br/>
<h2><?php echo str_replace("%server%", $page->settings["server_name"], $page->msg("index.main")); ?></h2>
<p><?php echo $page->msg("index.sub"); ?></p>
<br/>
</div>
<?php
if(isset($pullResult)) {
?>
<div class="container" action="./index.php" method="POST">
<br>
<?php
foreach ($pullResult as $line) {
print("<p>" . $line . "</p>");
}
?>
<br>
</div>
<?php
}
if(isset($_SESSION["is_admin"]) && $_SESSION["is_admin"] == 1) {
$context = stream_context_create(array('http' => array(
'method' => "GET",
'header' => "User-Agent: " . $_SERVER['HTTP_USER_AGENT']
)
));
$actualVersion = file_get_contents("./include/version.txt");
$snapshot = endsWith($actualVersion, "-SNAPSHOT");
$latest = json_decode(@file_get_contents("https://api.github.com/repos/Elikill58/Positivity/releases/latest", false, $context));
$isGit = is_dir("./.git"); // check if using git
if($isGit) {
$commitVersion = @file_get_contents("https://raw.githubusercontent.com/Elikill58/Positivity/master/include/version.txt", false, $context);
$commitSnapshot = endsWith($commitVersion, "-SNAPSHOT");
if($snapshot && $commitSnapshot) { // using snapshot everywhere
if($actualVersion == $commitVersion) { // exact same version, with snapshot
?>
<form class="container" action="./index.php" method="POST">
<br/>
<h2><?php echo $page->msg("index.version.snapshot.title"); ?></h2>
<p><?php echo str_replace("%actual_version%", $actualVersion, str_replace("%version%", $latest->{"tag_name"}, $page->msg("index.version.snapshot.snapshot_too"))); ?></p>
<button class="btn-outline" name="action" value="pull"><?php echo $page->msg("index.version.pull.try"); ?></button>
<br/>
</form>
<?php
} else { // not exact same version
?>
<form class="container" action="./index.php" method="POST">
<br/>
<h2><?php echo $page->msg("index.version.snapshot.title"); ?></h2>
<p><?php echo str_replace("%actual_version%", $actualVersion, str_replace("%version%", $latest->{"tag_name"}, $page->msg("index.version.snapshot.upgrade"))); ?></p>
<button class="btn-outline" name="action" value="pull"><?php echo $page->msg("index.version.pull.try"); ?></button>
<br/>
</form>
<?php
}
} else if($snapshot && !$commitSnapshot) { // using snapshot but full release available
?>
<form class="container" action="./index.php" method="POST">
<br/>
<h2><?php echo $page->msg("index.version.snapshot.title"); ?></h2>
<p><?php echo str_replace("%actual_version%", $actualVersion, str_replace("%version%", $latest->{"tag_name"}, $page->msg("index.version.snapshot.release"))); ?></p>
<button class="btn-outline" name="action" value="pull"><?php echo $page->msg("index.version.pull.try"); ?></button>
<br/>
</form>
<?php
} else { // not using snapshot
?>
<form class="container" action="./index.php" method="POST">
<br/>
<h2><?php echo $page->msg("index.version.snapshot.title"); ?></h2>
<p><?php echo str_replace("%actual_version%", $actualVersion, str_replace("%version%", $latest->{"tag_name"}, $page->msg("index.version.snapshot.upgrade"))); ?></p>
<button class="btn-outline" name="action" value="pull"><?php echo $page->msg("index.version.pull.try"); ?></button>
<br/>
</form>
<?php
}
} else {
if($latest->{"draft"} == 0 && $latest->{"prerelease"} == 0 && $latest->{"tag_name"} != $actualVersion) { // version different from latest github release
?>
<div class="container">
<br/>
<h2><?php echo $page->msg("index.version.yes.title"); ?></h2>
<p><?php echo str_replace("%actual_version%", $actualVersion, str_replace("%version%", $latest->{"tag_name"}, $page->msg("index.version.yes.sub"))); ?></p>
<br/>
</div>
<?php
} else { // same as github release
?>
<div class="container">
<br/>
<h2><?php echo $page->msg("index.version.no.title"); ?></h2>
<p><?php echo $page->msg("index.version.no.sub"); ?></p>
<br/>
</div>
<?php
}
}
}
?>
</div>
<?php
$page->show_footer();
?>
</div>
</div>
</body>
</html>