Пример #1
0
             $odd = $odd == "odd" ? "even" : "odd";
         }
     } else {
         echo "<tr><td colspan='12' style='text-align:center;font-weight:bold;'>No usb disks present.</td></tr>";
     }
     echo "</tbody></table>";
     $config_file = $GLOBALS["paths"]["config_file"];
     $config = is_file($config_file) ? @parse_ini_file($config_file, true) : array();
     $disks_serials = array();
     foreach ($disks as $disk) {
         $disks_serials[] = $disk['partitions'][0]['serial'];
     }
     $ct = "";
     foreach ($config as $serial => $value) {
         if (!preg_grep("#{$serial}#", $disks_serials)) {
             $ct .= "<tr><td><img src='/webGui/images/green-blink.png'> missing</td><td>{$serial}</td><td><input type='checkbox' class='automount' serial='{$serial}' " . (is_automount($serial) ? 'checked' : '') . "></td><td colspan='7'><a style='cursor:pointer;' onclick='remove_disk_config(\"{$serial}\")'>Remove</a></td></tr>";
         }
     }
     if (strlen($ct)) {
         echo "<table class='tablesorter usb_absent'><thead><tr><th>Device</th><th>Serial Number</th><th>Auto mount</th><th colspan='7'>Remove config</th></tr></thead><tbody>{$ct}</tbody></table>";
     }
     echo '<script type="text/javascript">';
     echo '$(".automount").each(function(){var checked = $(this).is(":checked");$(this).switchButton({labels_placement: "right", checked:checked});});';
     echo '$(".automount").change(function(){$.post("/plugins/' . $plugin . '/update_cfg.php",{action:"automount",serial:$(this).attr("serial"),status:$(this).is(":checked")},function(data){$(this).prop("checked",data.automount);},"json");});';
     echo "\$('.text').click(showInput);\$('.input').blur(hideInput)";
     echo '</script>';
     break;
 case 'detect':
     if (is_file("/var/state/{$plugin}")) {
         echo json_encode(array("reload" => true));
     } else {
Пример #2
0
function get_partition_info($device, $reload = FALSE)
{
    global $_ENV, $paths;
    $disk = array();
    $attrs = isset($_ENV['DEVTYPE']) ? get_udev_info($device, $_ENV, $reload) : get_udev_info($device, NULL, $reload);
    // $GLOBALS["echo"]($attrs);
    $device = realpath($device);
    if ($attrs['DEVTYPE'] == "partition") {
        $disk['serial_short'] = isset($attrs["ID_SCSI_SERIAL"]) ? $attrs["ID_SCSI_SERIAL"] : $attrs['ID_SERIAL_SHORT'];
        $disk['serial'] = "{$attrs[ID_MODEL]}_{$disk[serial_short]}";
        $disk['device'] = $device;
        // Grab partition number
        preg_match_all("#(.*?)(\\d+\$)#", $device, $matches);
        $disk['part'] = $matches[2][0];
        $disk['disk'] = $matches[1][0];
        if (isset($attrs['ID_FS_LABEL'])) {
            $disk['label'] = safe_name($attrs['ID_FS_LABEL_ENC']);
        } else {
            if (isset($attrs['ID_VENDOR']) && isset($attrs['ID_MODEL'])) {
                $disk['label'] = sprintf("%s %s", safe_name($attrs['ID_VENDOR']), safe_name($attrs['ID_MODEL']));
            } else {
                $disk['label'] = safe_name($attrs['ID_SERIAL']);
            }
            $all_disks = array_unique(array_map(function ($ar) {
                return realpath($ar);
            }, listDir("/dev/disk/by-id")));
            $disk['label'] = count(preg_grep("%" . $matches[1][0] . "%i", $all_disks)) > 2 ? $disk['label'] . "-part" . $matches[2][0] : $disk['label'];
        }
        $disk['fstype'] = safe_name($attrs['ID_FS_TYPE']);
        $disk['fstype'] = !$disk['fstype'] && verify_precleared($disk['disk']) ? "precleared" : $disk['fstype'];
        $disk['target'] = str_replace("\\040", " ", trim(shell_exec("/bin/cat /proc/mounts 2>&1|/bin/grep {$device}|/bin/awk '{print \$2}'")));
        $disk['size'] = intval(trim(shell_exec("/sbin/blockdev --getsize64 {$device} 2>/dev/null")));
        $disk['used'] = intval(trim(shell_exec("/bin/df --output=used,source 2>/dev/null|/bin/grep -v 'Filesystem'|/bin/grep {$device}|/bin/awk '{print \$1}'"))) * 1024;
        $disk['avail'] = $disk['size'] - $disk['used'];
        if ($disk['mountpoint'] = get_config($disk['serial'], "mountpoint.{$disk[part]}")) {
            if (!$disk['mountpoint']) {
                goto empty_mountpoint;
            }
        } else {
            empty_mountpoint:
            $disk['mountpoint'] = $disk['target'] ? $disk['target'] : preg_replace("%\\s+%", "_", sprintf("%s/%s", $paths['usb_mountpoint'], $disk['label']));
        }
        $disk['owner'] = isset($_ENV['DEVTYPE']) ? "udev" : "user";
        $disk['automount'] = is_automount($disk['serial'], strpos($attrs['DEVPATH'], "usb"));
        $disk['shared'] = config_shared($disk['serial'], $disk['part'], strpos($attrs['DEVPATH'], "usb"));
        $disk['command'] = get_config($disk['serial'], "command.{$disk[part]}");
        $disk['command_bg'] = get_config($disk['serial'], "command_bg.{$disk[part]}");
        $disk['prog_name'] = basename($disk['command'], ".sh");
        $disk['logfile'] = $paths['device_log'] . $disk['prog_name'] . ".log";
        return $disk;
    }
}