Ajaxplorer integration on SME Server. Not maintained anymore
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.8 KiB

#!/usr/bin/perl -w
use strict;
use esmith::ConfigDB;
use esmith::AccountsDB;
use File::stat;
my $c = esmith::ConfigDB->open_ro || die "Couldn't open ConfigDB\n";
my $a = esmith::AccountsDB->open_ro || die "Couldn't open AccountsDB\n";
my $ajaxplorer = $c->get('ajaxplorer') || die "ajaxplorer entry is missing in the configuration database\n";
my $status = $ajaxplorer->prop('status') || 'disabled';
my $indexer = $ajaxplorer->prop('Indexer') || 'enabled';
exit(0) if ($status ne 'enabled' || $indexer ne 'enabled');
# Generate a random ID for our requests
my @chars = ('a'..'z','A..Z','0'..'9');
my $id = '';
foreach (0..32){
$id .= $chars[rand @chars];
}
foreach my $share ($a->get_all_by_prop(type => 'share')){
$ajaxplorer = $share->prop('Ajaxplorer') || 'disabled';
$indexer = $share->prop('AjaxplorerIndexer') || 'enabled';
next if ($ajaxplorer ne 'enabled' || $indexer ne 'enabled');
my $name = $share->key;
# Check if the lock file is present and if it's too old (last index crashed ?)
if (-e "/var/cache/ajaxplorer/indexes/.ajxp_lock-$name"){
my $mtime = stat("/var/cache/ajaxplorer/indexes/.ajxp_lock-$name")->mtime;
unlink </var/cache/ajaxplorer/indexes/.ajxp_lock-$name>
if (time() - $mtime > 18000);
}
system('/usr/bin/sudo -u www /usr/bin/php /usr/share/ajaxplorer/cmd.php ' .
'-u=RDiin175M40T0cYvXLARpAi+1TsSVkbksEDZ4KvwBuY= '.
'-t=e71479ebc4365176d9f09fe957780024 -a=index '.
'-r='.$name.' --secure_token='.$id.' --dir=/ --_method=put >/dev/null 2>&1');
# In some cases, the lock file is not removed, make sure it's unlocked
unlink </var/cache/ajaxplorer/indexes/.ajxp_lock-$name>;
}
# We should now restart OOo to release memory
if (-d '/var/service/ooo'){
system('/usr/bin/sv t /service/ooo');
}