OSDN Git Service

ver0.2
[squarantine/squarantine.git] / package / usr / bin / usbremove2
1 #! /usr/bin/perl
2 use DBI;
3 use File::Path;
4 open(FILE,">>/tmp/usbunplug") or die;
5     print FILE "--------------", "\n";
6 foreach my $key( keys %ENV ){
7     print FILE "$key: $ENV{$key}", "\n";
8 }
9
10 ##UNMOUNT##
11 system("umount ".$ENV{'DEVNAME'});
12
13 ##MOUNTPOINT DELETE##
14 my $dbh = DBI->connect("DBI:mysql:squarantine", "root", "Cab6402!") || die "CONNECT ERROR $DBI::ERRSTR";
15
16 my $sth = $dbh->prepare("select nickname,memo,flags from media where id_serial=\'".$ENV{'ID_SERIAL'}."\'");
17 $sth->execute;
18 $num_rows = $sth->rows;
19 for ($i=0; $i<$num_rows; $i++) {
20     @a = $sth->fetchrow_array;
21     $nickname = $a[0];
22 }
23
24 $dirname=$nickname;
25 $dirname =~ s/[<>:\*\?\|\"\/\\]//g;
26
27         print FILE "dirname: $dirname\n";
28
29 ## directory delete
30
31 # system("/bin/rm -rf  \"/var/squarantine/usbstorages/$ENV{'DEVNAME'}\"");
32 chdir('/var/squarantine/usbstorages/'); 
33 @pathArray = ($dirname);
34
35 if (rmtree(@pathArray,{verbose => 1})) {
36         print FILE "node delete Ok: $!\n";
37 } else {
38 #       print "node delete Error: $!\n";
39         print FILE "node delete Error: $!\n";
40 }
41 $dirname=$ENV{'ID_SERIAL'};
42 $dirname =~ s/[<>:\*\?\|\"\/\\]//g;
43 system("/bin/rm -rf  \"/var/squarantine/usbstorages/$dirname\"");
44
45
46
47 $sth->finish;
48 $dbh->disconnect;
49
50 #  system("mkdir /mnt/$ENV{'DEVNAME'}");
51 #  system("mount $ENV{'DEVNAME'} /mnt/usbshare1");
52 #  system("ln -s /mnt/usbshare1 /mnt/share/ok");
53
54 close(FILE);
55