| 9 |
9 |
use Libs::ReadF;
|
| 10 |
10 |
use Libs::Image;
|
| 11 |
11 |
|
|
12 |
|
| 12 |
13 |
$VERSION = "0.1.0-dev"; # Версия движка и API
|
| 13 |
14 |
$DIRECTORY_SEPARATOR='/';
|
| 14 |
15 |
|
| 15 |
16 |
|
| 16 |
17 |
|
|
18 |
sub _hash{
|
|
19 |
my ($str)=@_;
|
|
20 |
#return Libs::Others::GenMD5($str);
|
|
21 |
return $str;
|
|
22 |
}
|
|
23 |
|
|
24 |
sub _unhash{
|
|
25 |
my ($str)=@_;
|
|
26 |
#return Libs::Others::GenMD5($str);
|
|
27 |
return $str;
|
|
28 |
}
|
|
29 |
|
|
30 |
|
|
31 |
|
| 17 |
32 |
sub new{ # Создание нового класса. Отсюда начинается класс
|
| 18 |
33 |
my ($class,%cfg)=@_; #Mod - список модулей для загрузки
|
| 19 |
34 |
my $self = bless {}, $class;
|
| ... | ... | |
| 51 |
66 |
'perms' => [], # individual folders/files permisions
|
| 52 |
67 |
'debug' => 'false', # send debug to client
|
| 53 |
68 |
'archiveMimes' => [], # allowed archive's mimetypes to create. Leave empty for all available types.
|
| 54 |
|
'archivers' => [] # info about archivers to use. See example below. Leave empty for auto detect
|
|
69 |
'archivers' => [], # info about archivers to use. See example below. Leave empty for auto detect
|
|
70 |
'WebCharset' => 'WINDOWS-1251',
|
|
71 |
'UTF' => 'true'
|
| 55 |
72 |
);
|
| 56 |
73 |
$self->{CONF} = { %{$self->{CONF}},%cfg }; # Чтение файла конфигурации
|
| 57 |
74 |
# { %{$self->{CONF}},Libs::ReadF::LoadCfgDB($self,'') }
|
| ... | ... | |
| 68 |
85 |
}
|
| 69 |
86 |
|
| 70 |
87 |
%{$self->{CMD}} = (
|
| 71 |
|
'open' => '_open',
|
| 72 |
|
'reload' => '_reload',
|
| 73 |
|
'mkdir' => '_mkdir',
|
| 74 |
|
'mkfile' => '_mkfile',
|
| 75 |
|
'rename' => '_rename',
|
| 76 |
|
'upload' => '_upload',
|
| 77 |
|
'paste' => '_paste',
|
| 78 |
|
'rm' => '_rm',
|
| 79 |
|
'duplicate' => '_duplicate',
|
| 80 |
|
'read' => '_fread',
|
| 81 |
|
'edit' => '_edit',
|
| 82 |
|
'archive' => '_archive',
|
| 83 |
|
'extract' => '_extract',
|
| 84 |
|
'resize' => '_resize',
|
| 85 |
|
'tmb' => '_thumbnails',
|
| 86 |
|
'ping' => '_ping'
|
| 87 |
|
);
|
|
88 |
'open' => '_open',
|
|
89 |
'reload' => '_reload',
|
|
90 |
'mkdir' => '_mkdir',
|
|
91 |
'mkfile' => '_mkfile',
|
|
92 |
'rename' => '_rename',
|
|
93 |
'upload' => '_upload',
|
|
94 |
'paste' => '_paste',
|
|
95 |
'rm' => '_rm',
|
|
96 |
'duplicate' => '_duplicate',
|
|
97 |
'read' => '_fread',
|
|
98 |
'edit' => '_edit',
|
|
99 |
'archive' => '_archive',
|
|
100 |
'extract' => '_extract',
|
|
101 |
'resize' => '_resize',
|
|
102 |
'tmb' => '_thumbnails',
|
|
103 |
'ping' => '_ping'
|
|
104 |
);
|
|
105 |
|
|
106 |
#$ctr = Text::Iconv->new($self->{CONF}->{'WebCharset'},'UTF-8');
|
| 88 |
107 |
|
| 89 |
108 |
return $self;
|
| 90 |
109 |
}
|
| ... | ... | |
| 92 |
111 |
|
| 93 |
112 |
|
| 94 |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
| 95 |
117 |
sub _run {
|
| 96 |
118 |
my ($self)=@_;
|
| 97 |
119 |
|
| ... | ... | |
| 140 |
162 |
if ($cmd ne '') {
|
| 141 |
163 |
my $func=$self->{CMD}->{$cmd};
|
| 142 |
164 |
$self->$func($self);
|
| 143 |
|
#$self->{RES}->{'error'} .= ' '.'cmd:'.$cmd." $self->{CMD}->{$cmd} <br>Targ - $self->{URL}->{'target'}<br>Cur - $self->{URL}->{'current'}";
|
| 144 |
165 |
} else {
|
| 145 |
|
#$self->{RES}->{'error'} .= ' '.'1 cmd:'.$cmd;
|
| 146 |
166 |
$self->_open();
|
| 147 |
167 |
}
|
| 148 |
168 |
}
|
| ... | ... | |
| 177 |
197 |
}
|
| 178 |
198 |
|
| 179 |
199 |
|
|
200 |
|
| 180 |
201 |
sub _basename{
|
| 181 |
202 |
my ($path)=@_;
|
| 182 |
203 |
if (rindex($path,$DIRECTORY_SEPARATOR)==-1){return $path}
|
| 183 |
|
return substr($path,rindex($path,$DIRECTORY_SEPARATOR)+1);
|
|
204 |
#my $str=$ctr->convert(substr($path,rindex($path,$DIRECTORY_SEPARATOR)+1));
|
|
205 |
|
|
206 |
return substr($path,rindex($path,$DIRECTORY_SEPARATOR)+1)
|
| 184 |
207 |
}
|
| 185 |
208 |
|
| 186 |
209 |
sub is_dir{
|
| ... | ... | |
| 201 |
224 |
sub _tree{
|
| 202 |
225 |
my ($self,$path) = @_;
|
| 203 |
226 |
my %dir = (
|
| 204 |
|
'hash' => Libs::Others::GenMD5("$path"),
|
|
227 |
'hash' => _hash("$path"),
|
| 205 |
228 |
'name' => $path eq $self->{CONF}->{'root'} && $self->{CONF}->{'rootAlias'} ne '' ? $self->{CONF}->{'rootAlias'} : _basename($path),
|
| 206 |
229 |
'read' => _isAllowed($self,$path, 'read'),
|
| 207 |
230 |
'write' => _isAllowed($self,$path, 'write'),
|
| ... | ... | |
| 229 |
252 |
$rel .= $DIRECTORY_SEPARATOR.substr($path, length($self->{CONF}->{'root'})+1);
|
| 230 |
253 |
}
|
| 231 |
254 |
%{$self->{RES}->{'cwd'}} = (
|
| 232 |
|
'hash' => Libs::Others::GenMD5("$path"),
|
| 233 |
|
'name' => $name,
|
| 234 |
|
'mime' => 'directory',
|
| 235 |
|
'rel' => $rel,
|
| 236 |
|
'size' => 0,
|
| 237 |
|
'date' => Libs::Others::LocalDate($self,$self->{CONF}->{'DateTimeFormat'},'',int(-M "$path")),
|
| 238 |
|
'read' => 'true',
|
| 239 |
|
'write' => _isAllowed($self,$path, 'write'),
|
| 240 |
|
'rm' => $path eq $self->{CONF}->{'root'} ? 'false' : _isAllowed($self,$path, 'rm')
|
| 241 |
|
);
|
|
255 |
'hash' => _hash("$path"),
|
|
256 |
'name' => $name,
|
|
257 |
'mime' => 'directory',
|
|
258 |
'rel' => $rel,
|
|
259 |
'size' => 0,
|
|
260 |
'date' => Libs::Others::LocalDate($self,$self->{CONF}->{'DateTimeFormat'},'',int(-M "$path")),
|
|
261 |
'read' => 'true',
|
|
262 |
'write' => _isAllowed($self,$path, 'write'),
|
|
263 |
'rm' => $path eq $self->{CONF}->{'root'} ? 'false' : _isAllowed($self,$path, 'rm')
|
|
264 |
);
|
| 242 |
265 |
}
|
| 243 |
266 |
|
| 244 |
267 |
|
| ... | ... | |
| 247 |
270 |
opendir(DIR,$path);
|
| 248 |
271 |
my @content = grep {!/^\.{1,2}$/} sort readdir(DIR);
|
| 249 |
272 |
closedir(DIR);
|
| 250 |
|
|
| 251 |
273 |
foreach my $subdir ( grep {_isAccepted($self,"$path/$_") eq 'true'} sort {-f "$path/$a" cmp -f "$path/$b"} @content)
|
| 252 |
274 |
{push @{$self->{RES}->{'cdc'}},{_info($self,"$path/$subdir")};}
|
| 253 |
275 |
}
|
| ... | ... | |
| 257 |
279 |
my ($self,$path)=@_;
|
| 258 |
280 |
my @info=(-l "$path") ? lstat("$path") : stat("$path");
|
| 259 |
281 |
my %info= (
|
| 260 |
|
'hash' => Libs::Others::GenMD5("$path"),
|
|
282 |
'hash' => _hash("$path"),
|
| 261 |
283 |
'mime' => -d "$path" ? 'directory' : $self->_mimetype("$path"),
|
| 262 |
284 |
'name' => _basename("$path"), # Сделать замену двойных кавычек
|
| 263 |
285 |
'date' => Libs::Others::LocalDate($self,$self->{CONF}->{'DateTimeFormat'},'',$info[9]),
|
| ... | ... | |
| 302 |
324 |
}
|
| 303 |
325 |
|
| 304 |
326 |
sub _content{
|
| 305 |
|
my ($self,$path)=@_;
|
|
327 |
my ($self,$path,$flag)=@_;
|
| 306 |
328 |
_cwd($self,$path);
|
| 307 |
329 |
_cdc($self,$path);
|
| 308 |
|
if (exists $self->{URL}->{tree}) { $self->{RES}->{'tree'} = {_tree($self,$self->{CONF}->{'root'})};}
|
|
330 |
if ($self->{RES}->{'cdc'} eq '') {push @{$self->{RES}->{'cdc'}},;}
|
|
331 |
if (exists $self->{URL}->{tree} || lc($flag) eq 'true') { $self->{RES}->{'tree'} = {_tree($self,$self->{CONF}->{'root'})};}
|
| 309 |
332 |
}
|
| 310 |
333 |
|
| 311 |
334 |
|
| ... | ... | |
| 313 |
336 |
sub _open{
|
| 314 |
337 |
my ($self)=@_;
|
| 315 |
338 |
my $path = $self->{CONF}->{'root'};
|
| 316 |
|
my $p;
|
| 317 |
339 |
|
| 318 |
|
if (exists $self->{URL}->{'target'}) {
|
| 319 |
|
$p=_findDir($self,Libs::Others::SpaceTrim($self->{URL}->{'target'}));
|
| 320 |
|
if ('false' eq $p) {
|
| 321 |
|
if (! exists $self->{URL}->{'init'}) {$self->{RES}->{'error'} .= 'Invalid parameters'. $p;}
|
|
340 |
if ($self->{URL}->{'target'} ne '' ){
|
|
341 |
my $p=_unhash($self->{URL}->{'target'});
|
|
342 |
if (-r ($self->{URL}->{'target'})==0){
|
|
343 |
if (! exists $self->{URL}->{'init'}) {$self->{RES}->{'error'} .= 'Invalid parameters';}
|
| 322 |
344 |
} elsif (_isAllowed($self,$p, 'read') eq 'false') {
|
| 323 |
345 |
if (! exists $self->{URL}->{'init'}) {$self->{RES}->{'error'} .= 'Access denied';}
|
| 324 |
346 |
} else {$path = $p;}
|
| ... | ... | |
| 329 |
351 |
_content($self,$path);
|
| 330 |
352 |
}
|
| 331 |
353 |
|
|
354 |
sub _rm{
|
|
355 |
my ($self)=@_;
|
|
356 |
if (($self->{URL}->{'current'} eq '')
|
|
357 |
|| (-r (Libs::Others::SpaceTrim(_unhash($self->{URL}->{'current'})))==0)
|
|
358 |
|| ($self->{URL}->{'targets[]'} eq '')) { # || !is_array($_GET['targets'])
|
|
359 |
return $self->{RES}->{'error'}.= 'Invalid parameters '. $self->{URL}->{'targets[]'};
|
|
360 |
}
|
|
361 |
|
|
362 |
foreach my $hash (split(',',$self->{URL}->{'targets[]'})) {
|
|
363 |
$hash=_unhash($hash);
|
|
364 |
if (-d $hash) {system("rm -r $hash")}
|
|
365 |
else {unlink($hash);}
|
|
366 |
}
|
|
367 |
_content($self,_unhash($self->{URL}->{'current'}),'true');
|
|
368 |
}
|
|
369 |
|
|
370 |
|
|
371 |
sub _mkdir{
|
|
372 |
my ($self)=@_;
|
|
373 |
if (($self->{URL}->{'current'} eq '') || (-r (Libs::Others::SpaceTrim(_unhash($self->{URL}->{'current'})))==0)){
|
|
374 |
return $self->{RES}->{'error'}.= 'Invalid parameters ';
|
|
375 |
}
|
|
376 |
my $dir=$self->{URL}->{'current'};
|
|
377 |
my $name;
|
|
378 |
if (_isAllowed($self,$dir, 'write') eq 'false') {
|
|
379 |
$self->{RES}->{'error'} = 'Access denied';
|
|
380 |
} elsif ('false' eq ($name = _checkName($self,$self->{URL}->{'name'})) ) {
|
|
381 |
$self->{RES}->{'error'} = 'Invalid name';
|
|
382 |
} elsif (-r ($dir.$DIRECTORY_SEPARATOR.$name)) {
|
|
383 |
$self->{RES}->{'error'} = 'File or folder with the same name already exists';
|
|
384 |
} elsif (! mkdir($dir.$DIRECTORY_SEPARATOR.$name, $self->{CONF}->{'dirMode'})) {
|
|
385 |
$self->{RES}->{'error'} = 'Unable to create folder';
|
|
386 |
} else {
|
|
387 |
$self->{RES}->{'select'} =(_hash($dir.$DIRECTORY_SEPARATOR.$name));
|
|
388 |
_content($self,_unhash($self->{URL}->{'current'}),'true');
|
|
389 |
}
|
|
390 |
}
|
| 332 |
391 |
|
| 333 |
392 |
|
| 334 |
393 |
sub _utime{
|
| ... | ... | |
| 336 |
395 |
return time().'0';
|
| 337 |
396 |
}
|
| 338 |
397 |
|
| 339 |
|
|
| 340 |
|
sub _findDir{
|
| 341 |
|
my ($self,$hash, $path)=@_;
|
| 342 |
|
my $p='false';
|
| 343 |
|
if ($path eq '') {
|
| 344 |
|
$path = $self->{CONF}->{'root'};
|
| 345 |
|
if (Libs::Others::GenMD5("$path") eq $hash) {return $path;}
|
|
398 |
sub _checkName{
|
|
399 |
my ($self,$n)=@_;
|
|
400 |
#$n = strip_tags(trim($n));
|
|
401 |
if ($self->{CONF}->{'dotFiles'} eq 'false' && '.' eq substr($n, 0, 1)) {
|
|
402 |
return 'false';
|
| 346 |
403 |
}
|
| 347 |
|
opendir(DIR,$path);
|
| 348 |
|
my @content = grep {!/^\.{1,2}$/} sort readdir(DIR);
|
| 349 |
|
closedir(DIR);
|
| 350 |
|
foreach my $subdir (grep {-d "$path/$_" } @content){
|
| 351 |
|
$p = $path.'/'.$subdir;
|
| 352 |
|
if (Libs::Others::GenMD5("$p") eq $hash || ($p=_findDir($self,$hash,"$p")) ne 'false'){ last }
|
| 353 |
|
}
|
| 354 |
|
return $p;
|
|
404 |
return ($n =~ /[>|<|\/|:]+/) ? 'false' : $n;
|
| 355 |
405 |
}
|
| 356 |
406 |
|
| 357 |
407 |
|
| 358 |
|
|
| 359 |
408 |
1;
|