Zobrazují se příspěvky se štítkemredhat. Zobrazit všechny příspěvky
Zobrazují se příspěvky se štítkemredhat. Zobrazit všechny příspěvky

středa 9. března 2016

Remote web monitoring of 3D printers through Pronterface

I have recently dug into Pronterface code and realized that there is simple RPC server built-in. It listens on localhost and it's really cool feature for remote monitoring, so I hacked KISS (Keep It Simple and Stupid) PHP code that allows querying the RPC server through the web. The code can query multiple running Pronterfaces and it's no problem to monitor multiple 3D printers which are connected to the same host. Running instances of Pronterface are automatically detected. It also queries all connected V4L compatible webcameras, which means that you can check progress of printers visually. With the current code you can check temperatures (bed, extruder), Z position, status of the current print task including task/file name, ETA, finished percentage.

The code with instructions is available from github: https://github.com/yarda/printrun-webmon/. Feel free to pull request patches.

pátek 29. srpna 2014

Firefox: Re-enable prompt asking you whether you want to save your tabs on exit

Firefox usually asks whether you want to save your tabs on exit if you have browser.showQuitWarning = true in your about:config. If you check "Do not ask next time" it will not ask you again. The question is how to re-enable this prompt. You already set the following:

browser.showQuitWarning = true
browser.tabs.warnOnClose = true
browser.tabs.warnOnCloseOtherTabs = true
browser.warnOnQuit = true

But it still doesn't show the prompt. The corresponding setting is hidden behind browser.startup.page. Just locate it in about:config, right click on it and select "Reset". Restart Firefox and viola, the prompt is back. You can also re-enable this through the UI, go to "Edit -> Preferences -> General -> When Firefox starts" and change "Show my windows and tabs from last time" to "Show my home page" or "Show a blank page". A bit illogical on the first sight, but it works. This was tested on Firefox 31.0.

pondělí 1. července 2013

HW mod: Increase USB power on Raspberry Pi early rev. 1 boards

The early Raspberry PI (RPI) boards had polyfuses on the USB ports. They are electronic resettable 140 mA fuses. The problem is that they do not have zero ohm resistance. This means that by increasing the power drawn from the USB port the voltage drop across the polyfuse increases. By drawing approx. 100 mA and more from the USB port the voltage drops bellow the value allowed by the USB specification and the connected USB devices may behave incorrectly. I encountered this when I was backporting the R820T tuner driver to the kernel 3.9 (needed for some RTL2832 based DVB-T dongles). Some of the DVB-T cards I had worked OK, some exhibited random failures during I2C writes to the R820T registers which resulted in occasional kernel panics.

You can workaround this by using a USB powered hub or you can fix the RPI PCB. The fix is simple - just bypass the F1 and F2 polyfuses. This fix is already implemented on the later rev. 1 and rev. 2 boards, so the later boards don't exhibit this problem. You can remove the polyfuses and short the pins, but an easier approach is to leave the polyfuses on the PCB and just short them out by wire or just by tin. You will still have the protection from the main F3 polyfuse (0.7 A). The other advantage of this mod is that it will allow you to power the RPI from the USB hubs / devices that provide power upstream.

The F1 and F2 polyfuses are green (at least on my RPI boards) and are located near the status LEDs. This modification is applicable only to the early rev. 1 boards. They probably have the HW revision code 2 or less. You can get the HW revision code by running:

cat /proc/cpuinfo

If your HW revision code is 3 or above this problem is already fixed on your board.

pátek 14. června 2013

Use Windows screensavers in Linux for screen locking

This arise from the discussion with one person who we tried to migrate to Linux. Her argument was that she would miss the Bubble screensaver :). No doubt, the new D3D Windows screensavers are cool and especially for the Bubbles screensaver there is currently no Linux counterpart. But the argument doesn't stand, here is the quick and dirty solution - the Wine:

  • Copy the screensaver, e.g. for the bubble screensaver copy the \Windows\System32\Bubbles.scr to the /opt/screensavers/ directory (or elsewhere).
  • Install the xlockmore package
  • Run the screensaver by:
    xlock -mode blank -geometry 0x0 \
    -startCmd "wine /opt/screensavers/Bubbles.scr /s"

The trick is to instruct the xlock to blank the screen area consisting of zero number of pixels, so the display is let unmodified for the screensaver. This was tested on the Fedora 18 and Xfce and worked OK. If you need to configure the screensaver, you can run it with the /c parameter. Unfortunately the Bubbles screensaver doesn't have implemented the configuration dialog and the command will fail, but there are still some hidden settings you can alter through the registry. I focused only on the technical side of the problem, not the legal one, but I think it shouldn't be problem in case there is valid Windows license for the machine (e.g. machine with dual-boot).

neděle 7. dubna 2013

Tip: using oath-toolkit for HOTP/TOTP authentication

I packaged oath-toolkit for Fedora and it is currently submitted for the merge review. The toolkit provides oathtool which can be used as a generator for HOTP/TOTP (e.g. to authenticate against LinOTP). Usage is very simple, for HOTP:
$ oathtool -c COUNTER SEED
And for TOTP:
$ oathtool --totp SEED
The package also provides library and header files and more complex applications/GUIs can be easily based on it. There is also PAM module included that allows you to use your HOTP/TOTP HW/SW token for authentication against your machines (e.g. sshd). To enable it for sshd add the following line to the top of your /etc/pam.d/sshd:
auth sufficient pam_oath.so usersfile=/etc/users.oath window=20 digits=6
This will setup the SSH for 6 digits HOTP/TOTP and will check through the 20 values (the tolerance). Then create the /etc/users.oath file and add there a list of allowed users together with their prefix passwords (PINs) and seeds, e.g.:
HOTP/T30 root pw 00
HOTP user1 - 01
In the example above, the user root is configured for 30 seconds TOTP with the prefix password (PIN) pw and seed 00, the user user1 has no prefix password and uses the seed 01. As the file contains seeds and plain text PINs, do not forget to chown it to root:root and chmod it to 600. For correct function the "UsePAM yes" and "PasswordAuthentication yes" also needs to be specified in your /etc/ssh/sshd_config. Currently it may not work correctly with the SELinux (for details see the merge review).

neděle 24. března 2013

Fix: mediawiki@openshift is not saving user preferences

I encountered this when running Mediawiki through HTTPS/TLS on Openshift. The POST queries with full URLs didn't work - it resulted in inability to save user preferences, upload files and maybe there are other weird problems. After short debugging it showed that the problem is in the HTTPS detection in Mediawiki code. The code uses _SERVER['HTTPS'] == 'on' check which according to the PHP documentation is not correct - the Amazon's load balancer sets this to '1' instead of 'on'. It seems that the latest Mediawiki 1.20.3 is also affected by this so I filled http://bugzilla.wikimedia.org/show_bug.cgi?id=46511. The patch against mediawiki-1.16 (the Openshift Mediawiki example) is attached.

pátek 15. února 2013

Tip: Learn n900 to understand Map1.eu

Recently the alpha version of Map1.eu got online. It's nice project whose aim is to provide an all-purpose map of the whole Europe suitable for outdoor activities like hiking, biking, skiing or geocaching. The project is based on OpenStreetMap data. The great thing is that it contains hiking trails for both Czech and Slovakia. But the best thing is that it can be easily integrated into n900, the procedure:
  1. Install Mappero, e.g. "apt-get install maemo-mapper"
  2. Click Mappero -> Maps -> Tiles -> New, for Name, UniqID, Cache dir fill e.g. Map1.eu, as URL use http://alpha.map1.eu/tiles/%d/%d/%d.jpg, Type: XYZ_INV, Format: JPEG, click Save.
  3. Click Mappero -> Maps -> Tiles -> Repositories -> New, fill in the following: Name: e.g. Map1.eu, Min zoom: 5, Max zoom: 17, Zoom step: 1, Tiles: Map1.eu, click Save.
  4. Restart Mappero.
  5. In Mappero -> Maps -> Map repository select the Map1.eu
And you are done. The great thing is that you can also use this map offline, just download the tiles: in Mappero -> Maps -> Manage Maps... select Area (the current view is preselected) and interested zoom levels, click OK and the map will be downloaded for offline use.

středa 26. září 2012

Datovka - Interface to Czech Databox (AKA Datové schránky)

Recently, I packaged "Datovka" for Fedora. It's GUI application for access to Czech Databox (AKA Datové schránky) - an electronic communication interface endorsed by the Czech government. There is also python-dslib library for accessing the databox programatically. It was implemented by CZ.NIC. You can also access the databox from WWW interface now as it was recently redesigned to work without Windows plugin, but this GUI application and library could bring you more comfort and automation possibility.

úterý 18. září 2012

Intel AMT quickstart guide

Introduction

Intel Active Management Technology (AMT) is very interesting technology and today it is built-in in many Intel based laptops, but many owners have no idea that their machine can do it nor how to use this technology in practice. No wonder, the Intel official documentation is not easy to read. It is full of enterprise shortcuts and buzzwords. That's why I wrote this very simple quickstart guide.

Intel AMT allows you to remotely configure, control and provision your machine. You don't need another separate management card, everything is already built-in in your machine. It is OS independent and shares your network interface transparently with OS. It processes network packets before OS. It is accessible even if the machine is off, booting or hung. There is also possibility to enable this functionality on wireless network card. There is built-in WWW server for easy human control (e.g. power on/off/reboot), but unfortunately there isn't many functions provided by WWW server. For more advanced control the WS-management needs to be used. It also supports CIM bindings. The following DMTF WS-Management specifications are generally supported:

  • DSP0226 Web Services for Management (WS Management)
  • DSP0227 WS-Management CIM Binding Specification
  • DSP0230 WS-CIM Mapping Specification

For more details see Intel documentation.

So what can you do with it in practice? You can remotely redirect the boot process to e.g. network share, mount a remote image (IDER), you can access and change BIOS settings, redirect input/output through KVM, packet filter/block/inspect/ or rate limit network traffic, access a persistent event log that is stored in protected memory and much more. But remember, it is over-engineered enterprise class technology, thus the configuration and activation of these features is not always apparent :).

Intel AMT is built into chipset. The supported features are defined by AMT version number. You can upgrade the AMT firmware but only over minor releases. It is not possible to flash the firmware with bigger major number, because it would be incompatible with your physical hardware. Handy list of AMT versions with matching chipsets is available on Wikipedia. KVM is available from AMT version 6.0 and up. For working KVM you need recent enough board and chipset that support at least Intel AMT 6.0. You also need supported CPU (with integrated video card that is utilized for this functionality).

AMT activation

At first you need to enable it in BIOS and reboot. Then in the early boot screen enter the Management Engine (ME) by pressing CTRL + P (or F12 on some machines). Login into ME, use ''admin'' for both username and password. Than change the default password. Remember this is enterprise class technology :) thus it has to be complex enough password that contains mixed case characters, digits and special characters, otherwise the password is rejected by ME (it took me a while to come with the right password for the first time :). Enable ME (it may require reboot and login with your new pasword). Then configure ME, at least set the network. You can use static configuration (with secondary IP used for the ME and different IP for the host OS) or DHCP (with one IP shared with the host OS) and it can also be set to automatically synchronize with host OS IP. Also do not forget to set the hostname - this is important, otherwise the machine will not be remotely accessible. Switch mode to SMB (Small Business) management mode. Do not use the Enterprise mode (it can be used together with Active Directory). And finally reboot.

Now you should be able to access the AMT web interface. Open your web browser and point it to http://YOURMACHINE:16992. You will probably need to do it from another machine, not the one, you are trying to control. Observe the web interface, nice heh?

More stuff

In Fedora there is nice package called ''amtterm''. It includes Perl script (''amttool'') that can query info, power up/down, configure network, redirect BIOS boot messages and also redirect the boot process. There is also command line serial terminal that is also called ''amtterm'' and graphical terminal called ''gamt''. To use the serial line remotely you need to enable the Serial Over LAN (SOL) in the ME configuration (after boot). Then the OS should see another serial port. Then you can configure your Fedora to use this serial port as boot console or you can even configure your Grub to use this serial port for remote OS selection (but the OS selection didn't work correctly for me with grub2/f17/t420s). To enable it add to /etc/default/grub the following lines (my AMT serial port was ttyS0):

GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0"

Also add 'console=tty0 console=ttyS0,115200' to your GRUB_CMDLINE_LINUX in /etc/default/grub (and you can remove the 'rhgb quiet'). Then regenerate your grub2 config:

# grub2-mkconfig -o /boot/grub2/grub.cfg
Now you can connect from remote machine by e.g.:
$ amtterm YOURMACHINE

KVM

That's all great, but the really cool stuff is KVM. It is possible to connect through VNC to your machine and control it remotely, even browse your BIOS setup :). Remember you need at least Intel AMT 6.0 and supported CPU for this to work. You can use out-of-band KVM. This is RFB packed into AMT authenticated and possibly TLS encrypted stream, thus special client is needed. There are several commercial clients, mostly for windows like RealVNC Viewer Plus that can do it out-of-the box. There is also Intel AMT SDK, that contains example Linux implementation of out-of-band KVM viewer. Unluckily it uses RealVNC binary that comes with evaluation license, but you can buy full license. So far not good for opensource/free software enthusiast.

Luckily, it is possible to redirect the KVM to classic VNC 5900 port, thus any VNC client can be used. This requires a little hackish session with wsman :), but it is needed to do only once. In Fedora there is ''wsmancli'' package that can be used for this task. At first you need to set the RFB password (this is another password that will be used only for KVM, not your AMT password). Remember this is highly over-engineered enterprise technology thus the password must have exactly 8 characters and have to be combination of mixed case characters, digits and special characters, otherwise it is rejected. Then set the password through wsman:

# wsman put \
http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData \
-h AMT_HOST -P 16992 -u admin -p AMT_PASSWORD -k RFBPassword=RFB_PASSWORD

Then enable KVM redirection to port 5900:

# wsman put \
http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData \
-h AMT_HOST -P 16992 -u admin -p AMT_PASSWORD -k Is5900PortEnabled=true

And finally enable the KVM:

# wsman invoke -a RequestStateChange \
http://schemas.dmtf.org/wbem/wscim/1/cim-schema/2/CIM_KVMRedirectionSAP \
-h AMT_HOST -P 16992 -u admin -p AMT_PASSWORD -k RequestedState=2

You can also query the current settings by:

# wsman get \
http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData \
-h AMT_HOST -P 16992 -u admin -p AMT_PASSWORD

By default there is opt-in policy enabled. This means that the remote access must be explicitly allowed by local user. Upon VNC connection the AMT generates OTP PIN, that is shown on the local screen as HW overlay. This OTP PIN is required as a second authentication for the VNC access. The local user tells this PIN to the remote user to allow him to connect. If opt-in policy is disabled no OTP PIN is required for access, but there is still shown OSD indicator on the local screen that the remote connection is in progress. Disable opt-in policy by:

# wsman put \
http://intel.com/wbem/wscim/1/ips-schema/1/IPS_KVMRedirectionSettingData \
-h AMT_HOST -P 16992 -u admin -p AMT_PASSWORD -k OptInPolicy=false

Now you can simply connect with your favorite VNC viewer.

Clean-up

To cleanup ME configuration, enter BIOS setup and disable AMT. Save and reboot. During the reboot the AMT firmware will ask you whether you really want to unconfigure it. Confirm and then the unconfiguration starts. It takes a while (again it is enterprise technology :) and when the unconfiguration finish, the machine reboots. Now the AMT is deactivated and for next activation all settings (including password) will be on their defaults.

středa 1. srpna 2012

Fedora/RHEL development on Gentoo

I was unhappy that I couldn't develop Fedora/RHEL on my loved Gentoo, thus I created portage overlay with Fedora/RHEL development tools. It is in early stage, but it should be usable. There is still more work to do, e.g. ebuilds cleanup, USE flag addition, Python test suite enablement, Python3 support addition, etc. If you are Gentoo enthusiast, feel free to try. Layman XML is also available. For more details see project wiki. Enjoy and don't forget to report bugs :)

sobota 3. prosince 2011

UHD support in Fedora's GNU Radio

The UHD is the "Universal Software Radio Peripheral" hardware driver. The goal of the UHD is to provide a host driver and API for current and future Ettus Research products. There is a nice presentation about UHD at http://gnuradio.org/redmine/attachments/download/255/04-blum-uhd_presentation_gnuradio_2011.pdf. More information can be also found at UHD homepage: http://code.ettus.com/redmine/ettus/projects/uhd/wiki. The UHD can be also used with USRP1/2 as libusrp1/2 replacement.

Currently in Fedora the UHD is supported in Rawhide (F17) and it is the only way how to control the Ettus products from Rawhide's GNU Radio 3.5. Support for F16 is also on the way. In F16 both libusrp and libuhd will be supported from GNU Radio 3.4.

pátek 2. prosince 2011

Multiple groups matching in cnucnu

Cnucnu is a tool that provides upstream release monitoring service with bugzilla
integration. It can monitor upstream projects of your interest and alert you everytime the new version is released. This tool is already deployed in Fedora project infrastructure. If you want to monitor your packages in Fedora simply follow steps on: http://fedoraproject.org/wiki/Upstream_Release_Monitoring.

Cnucnu will then check the preset URL and compare with the package versions in Fedora. If newer version is found, bug is filled. All what you need to get this work is to correctly set the URL and correct regex for your package. Currently there are templates for mostly used patterns, but if your package uses special naming you will have to create custom regex. You can develop the regex interactively by running:
cnucnu --shell
Then specify URL to check and iteratively develop the regex. The regex specify what to look for on the URL. You also need to specify how looks the version substring. In the recent version of cnucnu the first group match (part of the regex enclosed by parenthesis) was used for this. The problem arise if you specify more than one group. In such case the cnucnu hangs. This is not good, thus I reported the problem to bugzilla and created simple patch that fixes this. The patch concatenates all results from all groups together (the dot is used as separator). This also allows you to parse more complex strings than before, simple example:
package-004_001.tar.gz
regex: package-0*(\d+)_0*(\d+).tar.gz
Cnucnu without patch will hang when parsing this. Cnucnu with patch parses this as version 4.1. Hopefully the patch will be integrated soon.

čtvrtek 20. října 2011

Turn your laptop into Wi-Fi AP with hostapd

Sometimes it can be useful to turn your laptop into Wi-Fi AP and quickly share your resources (e.g. internet connection) to others. This can make you new friends especially during conferences and similar events :). Of course supported HW is needed to get this work. Current status of linux drivers can be checked on the Linux Wireless drivers status page. Look for AP mode and cfg80211 - this is the preferred combination. But several non mac80211 drivers can also be used with the hostapd. For more details visit the hostapd homepage. If your HW is supported, the easiest way is probably to use the dnsmasq and hostapd. In Fedora install them by:

# yum install dnsmasq hostapd

Simple script to set things up

You can use the following script for going on the air quickly (it is prepared for mac80211 drivers, others would require editing):

#!/bin/bash

WANIF="eth0"     # Interface connected to internet
LANIF="wlan0"    # Interface that will serve the LAN, e.g. Wi-Fi card
COUNTRYCODE="CZ" # regulationary ISO/IEC 3166-1 Alpha-2 countrycode
MODE="g"         # mode a,b,g
CHANNEL="11"     # channel to use
ESSID="MY_NET"   # SSID to use
KEY="my_pass"    # password to use
LANIP="192.168.101.1"            # IP to use on your LAN interface
DHCP_POOL_START="192.168.101.3"  # First IP to assign to clients
DHCP_POOL_END="192.168.101.254"  # Last IP to assign to clients

# Enable packet forwarding
sysctl -w net.ipv4.ip_forward=1
# Enable handling of dynamic IPs (e.g. on WANIF)
sysctl -w net.ipv4.ip_dynaddr=1
ifconfig $LANIF $LANIP

# Start hostpad
hostapd -BP /var/run/hostapd.pid <(cat <<:end
interface=$LANIF
driver=nl80211
logger_syslog=-1
logger_syslog_level=2
logger_stdout=-1
logger_stdout_level=2
debug=0
dump_file=/tmp/hostapd.dump
ctrl_interface=/var/run/hostapd
ctrl_interface_group=0
country_code=$COUNTRYCODE
CHANNEL=$CHANNEL
ssid=$ESSID
hw_MODE=$MODE
# 1 to enable only clients with MAC listed in accept_mac_file
macaddr_acl=0
#accept_mac_file=/etc/hostapd/hostapd.accept
auth_algs=1
# Workaround for WinXP (only if only broadcast keys are used)
eapol_KEY_index_workaround=0
# Beacon interval in 1.024 ms
beacon_int=100

# Wireless Multimedia Extension/Wi-Fi Multimedia needed for
# IEEE 802.11n (HT)
wmm_enabled=1
# 1 to enable 802.11n
ieee80211n=0

# WEP/WPA/WPA2 bitmask, 0 for open/WEP, 1 for WPA, 2 for WPA2
wpa=2

# WPA2 settings
wpa_passphrase=$KEY
wpa_KEY_mgmt=WPA-PSK
rsn_pairwise=CCMP

# WEP settings
# WEP key length should be 5 (40 bit), 13 (64 bit) or
# 16 (128 bit) chars
#wep_KEY0="$KEY"
#wep_default_KEY=0
:end
)

dnsmasq -i $LANIF --dhcp-range=$DHCP_POOL_START,$DHCP_POOL_END

# FWD: Allow all connections OUT and only existing and related IN
iptables -I FORWARD -i $WANIF -o $LANIF -m state \
  --state ESTABLISHED,RELATED -j ACCEPT
iptables -I FORWARD -i $LANIF -o $WANIF -j ACCEPT

# Enabling SNAT (MASQUERADE) functionality on $WANIF
iptables -t nat -I POSTROUTING -o $WANIF -j MASQUERADE

For permanent setup it is better to transfer your hostapd settings into /etc/hostapd/hostapd.conf and your dnsmasq settings into /etc/dnsmasq.conf. Then you will be able to start and manage the services through sysvinit / systemd or whatever your system uses. Finally, for permantent setup you will also need to add the two sysctls (in Fedora to /etc/sysctl.conf) and iptables rules (in Fedora to /etc/sysconfig/iptables).

Ralink cards

Personally I tried this on my netbook with integrated 802.11n card (rt2800pci). There is quick howto on the rt2x00 project page. But it didn't work for me - the client was unable to associate and I was getting in the log: "IEEE 802.11: did not acknowledge association response". I found the resolution of this problem on the Ez nem egy blog. The author stated there that the driver is unable to ack several frames, but the hostapd needs them to be acked. The simple hack is to patch the hostapd to blindly assume it gets acked. I used the following patch (it differs from the original one from the above link by not logging the errors):

diff -up src/ap/ieee802_11.c.orig src/ap/ieee802_11.c
--- src/ap/ieee802_11.c.orig 2010-09-07 17:43:39.000000000 +0200
+++ src/ap/ieee802_11.c 2011-10-08 21:02:17.000000000 +0200
@@ -1475,13 +1475,6 @@ static void handle_auth_cb(struct hostap
  u16 auth_alg, auth_transaction, status_code;
  struct sta_info *sta;
 
- if (!ok) {
-  hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
-          HOSTAPD_LEVEL_NOTICE,
-          "did not acknowledge authentication response");
-  return;
- }
-
  if (len < IEEE80211_HDRLEN + sizeof(mgmt->u.auth)) {
   printf("handle_auth_cb - too short payload (len=%lu)\n",
          (unsigned long) len);
@@ -1518,13 +1511,6 @@ static void handle_assoc_cb(struct hosta
  int new_assoc = 1;
  struct ieee80211_ht_capabilities ht_cap;
 
- if (!ok) {
-  hostapd_logger(hapd, mgmt->da, HOSTAPD_MODULE_IEEE80211,
-          HOSTAPD_LEVEL_DEBUG,
-          "did not acknowledge association response");
-  return;
- }
-
  if (len < IEEE80211_HDRLEN + (reassoc ? sizeof(mgmt->u.reassoc_resp) :
           sizeof(mgmt->u.assoc_resp))) {
   printf("handle_assoc_cb(reassoc=%d) - too short payload "
Then it worked like a charm.

I also tried the rt73usb based dongle. This one shouldn't work according to rt2x00 project page, because they don't know how to get the status messages (ACK/FAIL) for sent packets from the HW. I think there should be a way how to get the ACKs, because the Windows driver works OK. The simple association hack from the above is not enough here, probably more blindly acks would be needed. This is really dirty solution, so I give it up for today. I will look on this more deep later.