$docroot ??= ($_SERVER['DOCUMENT_ROOT'] ?: '/usr/local/emhttp'); require_once "$docroot/webGui/include/Helpers.php"; // add translations $_SERVER['REQUEST_URI'] = ''; require_once "$docroot/webGui/include/Translations.php"; function age($number,$time) { return sprintf(_('%s '.($number==1 ? $time : $time.'s').' ago'),$number); } function my_age($time) { if (!is_numeric($time)) $time = time(); $age = new DateTime('@'.$time); $age = date_create('now')->diff($age); if ($age->y > 0) return age($age->y,'year'); if ($age->m > 0) return age($age->m,'month'); if ($age->d > 0) return age($age->d,'day'); if ($age->h > 0) return age($age->h,'hour'); if ($age->i > 0) return age($age->i,'minute'); return age($age->s,'second'); } function validname($name) { $path = realpath(dirname($name)); return in_array(explode('/',$path)[1]??'',['mnt','boot']) ? $path.'/'.basename($name) : ''; } function escape($name) {return escapeshellarg(validname($name));} function quoted($name) {return is_array($name) ? implode(' ',array_map('escape',$name)) : escape($name);} switch ($_POST['mode']) { case 'upload': $file = validname(htmlspecialchars_decode(rawurldecode($_POST['file']))); if (!$file) die('stop'); $local = "/var/tmp/".basename($file).".tmp"; if ($_POST['start']==0) { $my = pathinfo($file); $n = 0; while (file_exists($file)) $file = $my['dirname'].'/'.preg_replace('/ \(\d+\)$/','',$my['filename']).' ('.++$n.')'.($my['extension'] ? '.'.$my['extension'] : ''); file_put_contents($local,$file); // create file with proper permissions and owner touch($file); chgrp($file,'users'); chown($file,'nobody'); chmod($file,0666); } $file = file_get_contents($local); if ($_POST['cancel']==1) { delete_file($file); die('stop'); } if (file_put_contents($file,base64_decode($_POST['data']),FILE_APPEND)===false) { delete_file($file); die('error'); } die(); case 'calc': extract(parse_plugin_cfg('dynamix',true)); $source = explode("\n",htmlspecialchars_decode(rawurldecode($_POST['source']))); [$null,$root,$main,$rest] = my_explode('/',$source[0],4); if ($root=='mnt' && in_array($main,['user','user0'])) { $disks = parse_ini_file('state/disks.ini',true); $tag = implode('|',array_merge(['disk'],pools_filter($disks))); $loc = array_filter(explode(',',preg_replace("/($tag)/",',$1',exec("shopt -s dotglob; getfattr --no-dereference --absolute-names --only-values -n system.LOCATIONS ".quoted($source)."/* 2>/dev/null")))); } else { $loc = []; foreach ($source as $path) { [$null,$root,$main,$rest] = my_explode('/',$path,4); $loc[] = $root=='mnt' ? ($main ?: '---') : ($root=='boot' ? _('flash') : '---'); } } natcasesort($loc); $awk = "awk 'BEGIN{ORS=\" \"}/Number of files|Total file size/{if(\$5==\"(reg:\")print \$4,\$8;if(\$5==\"(dir:\")print \$4,\$6;if(\$3==\"size:\")print \$4}'"; [$files,$dirs,$size] = explode(' ',str_replace([',',')'],'',exec("rsync --stats -naI ".quoted($source)." /var/tmp 2>/dev/null|$awk"))); $dirs = $dirs ?: 0; $files -= $dirs; $calc = []; $calc[] = _('Name').": ".implode(', ',array_map('basename',$source)); $calc[] = _('Location').": ".implode(', ',array_unique($loc)); $calc[] = _('Last modified').': '.my_age(max(array_map('filemtime',$source))); $calc[] = _('Total occupied space').": ".my_scale($size,$unit)." $unit"; $calc[] = sprintf(_("in %s folder".($dirs==1?'':'s')." and %s file".($files==1?'':'s')),my_number($dirs),my_number($files)); $calc = '