-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathindex.php
More file actions
executable file
·189 lines (150 loc) · 4.19 KB
/
index.php
File metadata and controls
executable file
·189 lines (150 loc) · 4.19 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<?php // %protect%
/**
* PadEdit
*
* Copyright (c) 2010 Honest Code.
* Licensed under the GPL license.
* http://www.gnu.org/licenses/gpl.txt
*
* Date: 2010-12-25
* Version: 1.3
*
*/
//check for PHP 5
$phpversion = floatval(phpversion());
if ($phpversion < 5) {
die("Sorry, but PHP version 5 or above is required to use PadEdit.");
}
//define a version, we can also use this to prevent direct access to componant scripts.
define('PADEDIT_VERSION', '1.3');
$version = PADEDIT_VERSION;
//set some values to avoid undefined notices
$editfile = null;
$safety = false;
//Start session
session_set_cookie_params('0','/', null , false, true);
session_start();
require_once("system/functions.php"); // core system object
$p = new padedit;
//are we logged in?
if (@$_SESSION["authorised"] === true ) {
//yes we are, but....
//have they timed out?
$lastActive = $_SESSION['lastActive'];
// time limit in which they must log in again.
$timeLimit = 1800; // 30 minutes.
//if they havent used the app in 30 minutes, make them log in again
if (time() > ($lastActive + $timeLimit) ){
$loggedin = false;
}else {
$loggedin = true;
//update the last active time
$_SESSION['lastActive'] = time();
}
}else {
$loggedin = false;
}
if (!$loggedin) {
//checks to see if we need to run the setup, and runs it if we do.
$setup = $p->checkSetup();
if ($setup == true){
//true, we need to run the setup
$action = 'setup';
} else {
//otherwise make the user login.
$p->login();
$action = 'login';
}
}
//controller section. works out what the user is trying to do and performs the necessary functions
// things we can only do if we are logged in
if ($loggedin){
// save file
if (isset($_GET['save'])) {
$message = $p->saveFile();
}
// restore file from a backup
if (isset($_GET['restore'])) {
$message = $p->restoreBackup();
}
// delete a file.
if (isset($_GET['delete'])) {
$message = $p->deleteFile();
}
// create a new blank file.
if (isset($_GET['newfile'])) {
$message = $p->createFile();
}
// create a new empty folder.
if (isset($_GET['newfolder'])) {
$message = $p->createFolder();
}
// rename a file.
if (isset($_GET['rename'])) {
$message = $p->renameFile();
}
// upload a file.
if (isset($_GET['upload'])) {
$message = $p->uploadFile();
}
// logout
if (isset($_GET['logout'])) {
$p->logout();
}
// confirmation messages
if (isset($_GET['saved'])) {
$message = "File saved. <a href='".$_GET['path'].$_GET['file']."' target='_blank'>View file.</a>";
}
if (isset($_GET['deleted'])) {
$message = "File deleted.";
}
if (isset($_GET['renamed'])) {
$message = "File renamed. <a href='".$_GET['path'].$_GET['file']."' target='_blank'>View file.</a>";
}
if (isset($_GET['foldered'])) {
$message = "Folder created.";
}
if (isset($_GET['restored'])) {
$message = "Backup restored.";
}
// end confirmation messages
//display editor
$action = 'editor';
//make sure we have a path
if (isset($_GET['path'])) {
$path = $_GET['path'];
} else {
$path = "../";
}
if (!$p->checkPath($path)) {
header("Location: index.php?path=../");
exit;
}
//if the user wants to load a file
if (isset($_GET['file']) and isset($_GET['path'])) {
//get file details
$fileDetails = $p->getFileDetails($_GET['path'],$_GET['file']);
}
//check if they should be editing this file
if ($fileDetails['protected'] == true ) {
$safety = true;
$fileLoaded = false;
} else {
$safety = false;
$fileLoaded = true;
$editfile = $fileDetails['source'];
}
if ($fileDetails['is_file'] && $fileDetails['is_writable']){
//Need to check the type of file and only allow files that can be edited to be loaded in editor.
$fileEditable = $p->canEdit($fileDetails['extension']);
if (!$fileEditable){
//$safety = true;
$fileLoaded = false;
$editfile = '';
$message = "Sorry, You can't edit this type of file";
}
}
}
// load the template
require_once("system/templates/padedit.tpl.php");
?>