Created
September 5, 2014 12:48
-
-
Save tdebatty/64030c6f3b6151a2f2dc to your computer and use it in GitHub Desktop.
Allows you to filter which USB devices may be connected to your system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/php | |
<?php | |
// Allows you to filter which USB devices may be connected to your system | |
// To find the ID of devices: | |
// sudo pkill udevd | |
// sudo udevd --debug | |
// Setup: | |
// Save this file to /opt/udev-filter-usb | |
// chmod +x /opt/udev-filter-usb | |
// Add following line in /etc/udev/rules.d/45-filter-usb.rules | |
// ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", RUN+="/bin/sh -c '/opt/udev-filter-usb /sys$DEVPATH'" | |
$allowed = array( | |
// "Add_Your_Device_Id", | |
"Logitech_USB_Optical_Mouse", | |
"Kingston_DataTraveler_3.0_08123456D90434128BA", | |
"Generic_Mass_Storage_7C0SKF7897" | |
); | |
$devpath=$argv[1]; | |
$serial = getenv("ID_SERIAL"); | |
$rule = "DENY"; | |
if (in_array($serial, $allowed)) { | |
$rule = "ALLOW"; | |
} | |
file_put_contents( | |
"/var/log/udev-filter-usb", | |
date("Y-m-d H.i.s") . " : $rule : $devpath : $serial\n", | |
FILE_APPEND); | |
if ($rule == "DENY") { | |
$forbidden = "$devpath/authorized"; | |
exec("echo 0 > $forbidden"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment