php script for sispmctl (power supply switching) 
#> apt-get install sispmctl

Switch Socket on with sispmctl -o 1, off with sispmctl -f 1 and get status with sispmctl -m all

To have premission for a webserver to execute the command:

/etc/udev/rules.d/90-local.rules:
ACTION=="add", SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", \
ATTRS{idVendor}=="04b4", ATTRS{idProduct}=="fd13", \
GROUP="www-data", MODE="0660"
Because sometimes a wrong status came back i read it twice and compare it
<?php

function sispm_status() {
$pins1=array(0=>'0'); $pins2=array(0=>'1');
while ($pins1 !== $pins2) {
unset($pins1);
unset($pins2);
exec("/usr/bin/sispmctl -qnm all", $pins1);
exec("/usr/bin/sispmctl -qnm all", $pins2);
}
return $pins1;
}
$pins = sispm_status();

if (isset($_POST['update']))
for ($i = 0; $i <= 3; $i++)
if (isset($_POST["pin$i"])) {
if (!$pins[$i]) exec("/usr/bin/sispmctl -qno ".($i+1)); }
else if ($pins[$i]) exec("/usr/bin/sispmctl -qnf ".($i+1));

$pins = sispm_status();

?>
<html>
<body>
<form method="post">
<input type="checkbox" name="pin0" value="1" <?= ($pins[0]?'checked':'') ?>> Socket 1<br>
<input type="checkbox" name="pin1" value="1" <?= ($pins[1]?'checked':'') ?>> Socket 2<br>
<input type="checkbox" name="pin2" value="1" <?= ($pins[2]?'checked':'') ?>> Socket 3<br>
<input type="checkbox" name="pin3" value="1" <?= ($pins[3]?'checked':'') ?>> Socket 4<br>
<input type="submit" name="update">
</form>
</body>
</html>

perl:
#!/usr/bin/perl

use strict;
use warnings;
use CGI;

my $cgi = CGI->new();

my @ports=("PC","Printer","-","-");

print "Content-type: text/html\n";

print "\n";

print "<HTML><HEAD><TITLE>USB Steckdosenleiste</TITLE><META http-equiv=\"refresh\" content=\"60;steckdose.cgi\"></HEAD>\n\n";

print "<BODY>\n";

for my $port ($cgi->param()) {
if ($cgi->param($port) eq "on") { system "/usr/bin/sispmctl -q -o $port"; }
elsif ($cgi->param($port) eq "off") { system "/usr/bin/sispmctl -q -f $port"; }
}

print "<H1>USB Steckdosenleiste</H1><UL>\n";
my @states = `/usr/bin/sispmctl -q -g all`;
my $cnt = 1;
for my $state (@states) {
if ($ports[$cnt-1] ne "-") {
if ($state eq "off\n") { print "<LI>".$ports[$cnt-1]." ist ausgeschaltet [<A href=\"steckdose.cgi?$cnt=on\">einschalten</A>]\n"; }
else { print "<LI>".$ports[$cnt-1]." ist eingeschaltet [<A href=\"steckdose.cgi?$cnt=off\">ausschalten</A>]\n"; }
}
$cnt++;
}
print "</UL>\n";

print "</BODY></HTML>"


[ view entry ] ( 801 views )   |  print article
bluetooth network with bluez4 and udev 
Many things changed for bluez4. Now everything is made through dbus commands.

apt-get install bluetooth bluez (on server and client)

First check for bdaddr on server and client:

Server:> hcitool dev
Devices:
hci0 00:01:1A:63:49:33

Client:> hcitool dev
Devices:
hci0 00:02:6E:53:42:78

Pairing:

Server:> /usr/share/doc/bluez/examples/test-adapter discoverable on
Server:> /usr/share/doc/bluez/examples/simple-agent

Client:> /usr/share/doc/bluez/examples/simple-agent 00:02:6E:53:42:78 00:01:1A:63:49:33

Hint: On newer systems use /usr/bin/bluez-test-adapter, /usr/bin/bluez-simple-agent and bluez-test-network

On Server:
Agent registered
RequestPinCode (/org/bluez/25897/hci0/dev_00_02_6E_53_42_78)
Enter PIN Code: 1234
(keep simple-agent running)

On Client:
RequestPinCode (/org/bluez/4078/hci0/dev_00_01_1A_63_49_33)
Enter PIN Code: 1234
Release
New device (/org/bluez/4078/hci0/dev_00_01_1A_63_49_33)

Pairing keys are stored hashed in /var/lib/bluetooth/<local bdaddr>/linkkeys

Network:
--- /usr/share/doc/bluez/examples/test-network
+++ /usr/share/doc/bluez/examples/test-network.sh
@@ -35,9 +35,10 @@
print "Press CTRL-C to disconnect"

try:
- time.sleep(1000)
- print "Terminating connection"
+ while 1:
+ time.sleep(1000)
except:
pass

+print "Terminating connection"
network.Disconnect()
Client:> /usr/share/doc/bluez/examples/test-network.sh 00:01:1A:63:49:33
(keep test-network running)

On Server:
Authorize (/org/bluez/25897/hci0/dev_00_02_6E_53_42_78, 0000000f-0000-1000-8000-00803f9b24fa)
Authorize connection (yes/no): yes

Now you can stop simple-agent.

Server:> ifconfig ifconfig bnep0 192.168.0.1 netmask 255.255.255.0 up
Client:> ifconfig ifconfig bnep0 192.168.0.2 netmask 255.255.255.0 up

Now you can ping each other.

To avoid start simple-agent on server for connection authorisation each time you can trust the client with:

Server:> /usr/share/doc/bluez/examples/test-device trusted 00:01:1A:63:49:33 on

Automatisation:

On my server i'm running a bridged network with dhcp support, therefore i use udev to add bnep to my bridge:

/etc/udev/rules.d/local.rules:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="bnep?*", PROGRAM="/usr/sbin/brctl addif br0 %k"

Client:

/etc/udev/rules.d/local.rules:
ACTION=="add", SUBSYSTEM=="net", KERNEL=="bnep?*", PROGRAM="/sbin/dhclient -nw -pf /var/run/dhclient-%k.pid %k"
ACTION=="remove", SUBSYSTEM=="net", KERNEL=="bnep?*", PROGRAM="/usr/bin/pkill -9 dhclient"

maybe you need to reload udev!

On clientside you only have to keep running
/usr/share/doc/bluez/examples/test-network.sh 00:01:1A:63:49:33

Usually this should be done by networkmanager but this is not supported (now)

[ view entry ] ( 2391 views )   |  print article
dnstunnel with iodine and bind9 
Iodine server with public IP:

#> apt-get install iodine

For "good" connection i used a mtu of 256 through my provider DNS.
On local network no mtu change was necessary.

/etc/default/iodine
START_IODINED="true"
IODINED_ARGS="-m 256 -l IODINE_SERVER_IP 10.0.0.1 tunnel.DOMAIN"
IODINED_PASSWORD="mypassword"
#> sysctl -e net.ipv4.ip_forward=1
#> iptables -t nat -A POSTROUTING -s 10.0.0.0/255.255.255.0 -o eth0 -j MASQUERADE

Bind9 server:

zonesfile:
zone "DOMAIN" in {
type master;
file "/etc/bind/zones/DOMAIN";
allow-query { any; };
};

zone "tunnel.DOMAIN" in {
type forward;
forward only;
forwarders {
IODINE_SERVER_IP;
};
};
zonefile:
tunnel      1D   IN   NS    tunnelhost
tunnelhost 1D IN A IODINE_SERVER_IP

Client:

#> apt-get install iodine
#> iodine -m 256 -P mypassword tunnel.DOMAIN
#> route add default gw 10.0.0.1


Well it seams that my provider drop's packets with some payload in it:

#> ping -c1 -s 109 10.0.0.1 fails

but

#> ping -c1 -s 109 -p ff 10.0.0.1 succeeds


[ view entry ] ( 1212 views )   |  print article
Automount and autounmount of usb sticks / discs 
Each partition of plugged in usb stick's should be accessible with automount.

My mountpoints will be /media/usb/part0, /media/usb/part1, ...

Example:

The fist plugged stick has two partitions. The second only one.

/media/usb/part0 ... first stick partition one
/media/usb/part1 ... first stick partition two
/media/usb/part2 ... second stick partition one

If the second stick is plugged in first:

/media/usb/part0 ... first stick partition one
/media/usb/part1 ... second stick partition one
/media/usb/part2 ... second stick partition two

/etc/udev/rules.d/90-local.rules
ACTION=="add", BUS=="usb", SUBSYSTEM=="block", KERNEL=="sd?[0-9]*", \
NAME="%k", PROGRAM="get_usbdisc_symlink", SYMLINK+="%c", OPTIONS+="nowatch"
OPTIONS+="nowatch" avoids removal by udev of the symlink after unmounting

/lib/udev/get_usbdisc_symlink
#!/bin/sh -e

. /lib/udev/rule_generator.functions

[ -h /dev/usbpart0 ] && \
echo usbpart$(raw_find_next_available $(ls /dev/usbpart[0-9]*)) || \
echo "usbpart0"

exit 0
#> apt-get install autofs5

/etc/auto.master
#+auto.master
/media/usb /etc/auto.usb --timeout=5 --ghost

My usb sticks will be unmounted after 5 seconds not being in use.
With "--ghost" /media/usb/partX will automatically created.

/etc/auto.usb
part0 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart0
part1 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart1
part2 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart2
part3 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart3
part4 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart4
part5 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart5
part6 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart6
part7 -fstype=auto,noexec,nodev,nodiratime,noatime,nosuid :/dev/usbpart7
To have readwrite access for users add ",uid=$UID,gid=$GID"

For more partitions extend the lines.



[ view entry ] ( 1788 views )   |  print article
chrooted sftp only 
useradd -s /bin/false -m SFTPUSER
mkdir /home/SFTPUSER/.ssh
ssh-keygen -t rsa -b 2048 -N '' -f /home/SFTPUSER/.ssh/id_rsa
chown -R SFTPUSER:SFTPUSER /home/SFTPUSER/.ssh
chmod 600 /home/SFTPUSER/.ssh/id_rsa

/etc/ssh/sshd_config:
Subsystem       sftp    internal-sftp

Match user SFTPUSER
PasswordAuthentication no
AllowTcpForwarding no
X11Forwarding no
ForceCommand internal-sftp
ChrootDirectory /chroot
chown root:root /chroot
mkdir /chroot/SFTPUSERDIR
chown SFTPUSER:SFTPUSER /chroot/SFTPUSERDIR

echo "put FILENAME" | \
sftp -oIdentityFile=/home/SFTPUSER/.ssh/id_rsa \
-oTCPKeepAlive=no -oServerAliveInterval=15 \
SFTPUSER@localhost:SFTPUSERDIR


[ view entry ] ( 2159 views )   |  print article

<<First <Back | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | Next> Last>>