-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass.FileDrive.php
213 lines (179 loc) · 6.94 KB
/
class.FileDrive.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
require_once INCLUDE_DIR . 'class.plugin.php';
//require_once INCLUDE_DIR . 'class.signal.php';
require_once INCLUDE_DIR . 'class.app.php';
//require_once INCLUDE_DIR . 'class.dispatcher.php';
//require_once INCLUDE_DIR . 'class.dynamic_forms.php';
//require_once INCLUDE_DIR . 'class.osticket.php';
require_once 'config.php';
define('FileDrive_PLUGIN_VERSION', '0.1');
define('FileDrive_TABLE', TABLE_PREFIX . 'equipment');
define('FileDrive_CLIENTINC_DIR', FileDrive_INCLUDE_DIR . 'client/');
class FileDrive extends Plugin
{
public $config_class = 'FileDriveConfig'; // Tell the plugin system how to find our config
public function bootstrap()
{
// echo "<script></script>";
if ($this->firstRun()) {
if (!$this->configureFirstRun()) {
return false;
}
} else if ($this->needUpgrade()) {
$this->configureUpgrade();
}
$config = $this->getConfig();
if ($config->get('FileDrive_Admin_enable')) {
$this->createAdminMenu();
}
if ($config->get('FileDrive_Staff_enable')) {
$this->createStaffMenu();
}
if ($config->get('FileDrive_Client_enable')) {
$this->createclientMenu();
}
//This will run after everything else, empties the buffer and runs our code over the HTML
//Then we send it to the browser as though nothing changed..
if($config->get('FileDrive_guest_enable')){
register_shutdown_function(
function () {
FileDrive::shutdownHandler();
});
}
}
/**
* Wrapper around register_shutdown_function to avoid making $this calls from
* anonymous functions.. Hopefully the Singleton factory pattern works
* properly..
*/
public static function shutdownHandler()
{
if (preg_match("/\bscp\b/", $_SERVER["REQUEST_URI"])) {
return;
}
$page = ob_get_clean();
$page = $page . " <script>
var str = document.getElementById(\"nav\").innerHTML;
var newstr = \"Home</a></li><li><a "
."style=\\\"background-image:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAEnMAABJzAYwiuQcAAAGgSURBVDhPpVI9TwJBEJ3bO4+EBEyURDkM/wELkVpttMAGC/kddGBIsKLESn8DIQEqSmw0akeUHgyEBBJJPL5h3BlPwC+M+pJ3Nzs7b2Z2ZxVEhP9AWP+/gzp4Yyx2Qu0sZPg4LENnmqmRz+dR15aw/dTGy2IRH6tVrFQqWC6X8eH+ntloNFBXNTxNJKTkQ4K9nV3cMDy0wZVsNhsWCgVez2PT50P32jqZ7xOQ6DAYpA2MRCKchCiEwFwux35CLBplv8TnBHSMecTj8WkiYqlUwlqtxnY2m6UQacnPwf4+rq6skONLJJNJFqXTaV77t/xouN1kAr8DRVEwsB2A0FEIzGdTxs6gqio4nQ7JZWi1mjAajeDq+hoymQwVl0orgaoIGOPEki0GPR6KvLg4B3GWSlF7MJqMp/fxkYPBAORI2W42m7IQgpwE3N7cgVA1jfTfol6vg67r4PV6weFwgMvl4mPI6YAmtT8+ZapKsNvt3AmJiHKD/aLX7bHxHQzD4CSmaUK/34fhcMj+Tq8L3U7ntYLHbfCYfkPB92+N8e8AeAG4Mn7bHv/bxAAAAABJRU5ErkJggg==');\\\""
. "href=\\\"".
ROOT_PATH
."fd/FileDrive.php\\\">FileDrive</a></li>\";
var res = str.replace(\"Support Center Home</a></li>\", newstr );
document.getElementById(\"nav\").innerHTML = res;
</script> ";
print $page;
}
/**
* Creates menu links in the Admin backend.
*/
public function createAdminMenu()
{
Application::registerAdminApp('FileDrive', ROOT_PATH."fd/", array(
iconclass => 'logs',
));
Application::registerAdminApp('FileDrive - Embebed', ROOT_PATH."fd/FileDrive.php?p=", array(
iconclass => 'faq-categories ',
));
}
/**
* Creates menu links in the staff backend.
*/
public function createStaffMenu()
{
/* Application::registerStaffApp('FileDrive', ROOT_PATH."fd/", array(
iconclass => 'logs',
));*/
Application::registerStaffApp('FileDrive - Embebed', ROOT_PATH."fd/FileDrive.php", array(
iconclass => 'faq-categories',
));
}
/**
* Creates menu link in the client frontend.
* Useless as of OSTicket version 1.9.2.
*/
public function createClientMenu()
{
/* Application::registerClientApp('FileDrive',ROOT_PATH.'fd/', array(
iconclass => 'logs',
));*/
Application::registerClientApp('FileDrive - Embebed', ROOT_PATH."fd/FileDrive.php", array(
iconclass => 'faq-categories',
));
}
/**
* Checks if this is the first run of our plugin.
*
* @return boolean
*/
public function firstRun()
{
return ((!file_exists(ROOT_DIR."fd/index.php"))==1);
}
public function needUpgrade()
{
return false;
}
public function configureUpgrade()
{
}
/**
* Necessary functionality to configure first run of the application
*/
public function configureFirstRun()
{
// if (!file_exists(ROOT_DIR."fd/index.php")){
// die("<br>FD Dir do not exist<br>");
// }
//echo "____--___".dirname(__DIR__)."/FileDrive/_copy_to_root/fd/index.php"."____--____";
if (!file_exists(dirname(__DIR__)."/FileDrive/_copy_to_root/fd/index.php")){
die("<strong>File Drive :</strong>".
"<br><br>please make sure that the Plugin folder is named \"FileDrive\"".
"<br>if you still need help please contact auther <strong><a href=\"https://github.com/akshaynikhare\" target=\"_blank\">Akshay Nikhare<a></strong>".
"<br>or Create an issue at Github <a href=\"https://github.com/akshaynikhare/FileDrive/issues\" target=\"_blank\">FileDrive/issues<a><strong>".
"<br>");
}
$page = ob_get_clean();
echo "<br> Setting up first use of plugin FileDrive<br>";
echo " reload this page if see this<br><br>";
$this->recurse_copy(dirname(__DIR__)."/FileDrive/_copy_to_root/fd/",ROOT_DIR."fd/");
header("Location: ".ROOT_DIR."fd/index.php");
exit();
return true;
}
/**
* copy root files to OSticket root
*/
function recurse_copy($src,$dst) {
$dir = opendir($src);
@mkdir($dst);
while(false !== ( $file = readdir($dir)) ) {
if (( $file != '.' ) && ( $file != '..' )) {
if ( is_dir($src . '/' . $file) ) {
$this->recurse_copy($src . '/' . $file,$dst . '/' . $file);
}
else {
copy($src . '/' . $file,$dst . '/' . $file);
}
}
}
closedir($dir);
}
/**
* Kicks off database installation scripts
*
* @return boolean
*/
public function createDBTables()
{
}
/**
* Uninstall hook.
*
* @param type $errors
* @return boolean
*/
public function pre_uninstall(&$errors)
{
}
}