-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
153 lines (134 loc) · 4.45 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
<?php
/**
* index.php
* Author: Federico Mestrone
* Created: 14/12/2012 13:51
* Copyright: 2012, Moodsdesign Ltd
*/
$CUR_PAGE = 'signin';
unset($PLUGIN);
unset($PLUGIN_ID);
unset($error_message);
unset($warn_message);
session_start();
if ( $_SESSION['PluginErr'] == 'invalid' ) {
$warn_message = 'Invalid Plugin ID for this session';
} else if ( !empty($_SESSION['PluginID']) ) {
$warn_message = 'You have been logged out';
}
session_unset();
session_destroy();
if ( ($pluginid = $_SERVER['QUERY_STRING']) ) {
/*
* Handle application requests from the Version Checker plugin
*/
$results = array('status' => 0);
$filename = "data/$pluginid";
if ( is_readable($filename) ) {
$raw = file_get_contents($filename);
if ( ($data = unserialize($raw)) ) {
$results['status'] = 1;
unset($data['password']);
$data['plugin_id'] = $pluginid;
$results['versions'] = array(
$pluginid => $data
);
}
}
header('Content-type: application/json');
echo json_encode($results);
die;
} else if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
/*
* Handle sign-in attempts
*/
$pluginid = $_POST['pluginid'];
$password = $_POST['password'];
if ( !$pluginid || !$password ) {
$error_message = '<li>You must provide both your Plugin ID and a password for it</li>';
} else if ( $pluginid[0] == '.' ) {
$warn_message = 'Plugin IDs cannot start with a dot.';
} else if ( is_readable("data/.$pluginid") ) {
$warn_message = 'This Plugin ID exists but has not been activated yet.';
} else {
$filename = "data/$pluginid";
if ( is_readable($filename) ) {
$raw = file_get_contents($filename);
if ( ($data = unserialize($raw)) ) {
if ( $data['password'] == md5($password) ) {
session_start();
$_SESSION['PluginID'] = $pluginid;
header('Location: manage.php');
} else {
$error_message = '<li>Your Plugin ID and password are not valid</li>';
}
} else {
$error_message = '<li>The Plugin ID and password you provided are not valid</li>';
}
} else {
$error_message = '<li>Invalid Plugin ID or password</li>';
}
}
}
/*
* Handle end user requests from a web browser
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Html Head -->
<?php require('elements/head.inc'); ?>
<!--/ Html Head -->
</head>
<body>
<!-- Navigation Bar -->
<?php require('elements/navbar.inc'); ?>
<!--/ Navigation Bar -->
<div id="wrap">
<div class="container">
<!-- Page Content -->
<div id="signin-form">
<form class="form-signin" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<input type="text" class="input-block-level" placeholder="Plugin ID" name="pluginid">
<input type="password" class="input-block-level" placeholder="Password" name="password">
<button class="btn btn-large btn-primary" type="submit">Sign in</button>
<a class="btn btn-large btn-info" href="#registerModal" role="button" data-toggle="modal">Register</a>
<a class="btn btn-large btn-info" href="#helpModal" role="button" data-toggle="modal"> Help </a>
</form>
</div>
<?php if ( $error_message ) { ?>
<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>An error has occurred</h4>
<ul>
<?php echo $error_message; ?>
</ul>
</div>
<?php } ?>
<?php if ( $warn_message ) { ?>
<div class="alert alert-info">
<button type="button" class="close" data-dismiss="alert">×</button>
<h4>Info</h4>
<?php echo $warn_message; ?>
</div>
<?php } ?>
<!--/ Page Content -->
</div>
<div id="push"></div>
</div>
<!-- About Modal -->
<?php require('elements/about.inc'); ?>
<!--/ About Modal -->
<!-- Help Modal -->
<?php require('elements/help-signin.inc'); ?>
<!--/ Help Modal -->
<!-- Register Modal -->
<?php require('elements/register.inc'); ?>
<!--/ Register Modal -->
<!-- Page Footer -->
<?php require('elements/footer.inc'); ?>
<!--/ Page Footer -->
</body>
</html>