Some black magic: bash, cgi and file uploads

Before you declare me an insane old man, I have to say, that I needed it for an embedded board with only 64MiBs of RAM. And (mostly due to the specifics of the tasks), I ended up using bash hooked to lighttpd via cgi. Bringing on heavy artillery (php or python), really complicated the task, since I mostly needed the outputs of different shell utils.
Anyway, I quickly got to the part where I needed to handle POST requests to upload binary files. First, I googled for a solution, and one of them eventually did what I needed. But alas, it had a drawback.
(more…)

android and dnsmasq: making a better dnsmasq wrapper

A few posts ago, I wrote about making android’s dnsmasq more usable by turning on local hostname resolution. Since I use my android phone as a pocket server, dnsmasq plays a vital role here.
However, one thing was bad – whenever I used usb tether connection to my PC, the whole dns thingie did not work. Why?

So, a little theory. When I enable the wifi ap mode, an interface called ap0 is brought up with a static ip 192.168.43.1.
Whenever I turn on usb tethering, usb0 pops into the existence with ip 192.168.42.129.
(On other mobile phones these settings can differ)
Fine, so when we resolve our pocket server from within the usb0 network, we want to get 192.168.42.129, and when via a wireless network – 192.168.43.1
I started by adding two distinct entries in /etc/hosts

192.168.43.1 anomalia anomalia.portable git.anomalia p.anomalia
192.168.42.129 anomalia anomalia.portable git.anomalia p.anomalia

Did it work? No! Why?
(more…)

Getting newer 2g/3g/4g dongles to work in debian.

Okay, this is just a small tip. All newer dongles, instead of having you to undergo some nasty sex with pppd over serial to make them work, have an ethernet interface, like cdc-ncm, sierra_net and etc. So, once you plug those, you usually see an extra interface when doing ifconfig -a.
So, how should we bring up the interface?
It is done via sending

AT^NDISDUP=1,1,"apn"

command via the serial interface (it shouldn’t be locked via any pin number whatsoever, if it is – we need to issue AT+CPIN before that).
Newer network-manager takes care of them, but on a headless box or some singleboard embedded device this is a no-go. In my case I use debian on my embedded box, so I threw up this very snipplet to /etc/network/interfaces:

iface wwan0 inet dhcp
        pre-up echo -ne '\r\nAT^NDISDUP=1,1,"internet"\r\n' > /dev/ttyUSB0 && sleep 15
        dns-nameservers 127.0.0.1 8.8.8.8

It gives a 15 second delay, so that the modem can bring up the interface, and adds 127.0.0.1 as a nameserver, since I’m using dnsmasq for local dns stuff. Replace /dev/ttyUSB0 with whatever port you need. Once done – use

ifup wwan0

or

ifdown wwan0

To get this interface up and down.
It’s also a good idea to ping google or something once every 5 to 10 seconds, because after a few hours of inactivity the modem drops the connection, and while now there is no mechanism in cdc_ncm except for a note in dmesg that the connection has been dropped.

There’s a server in my pocket!

I’m not a psychopath, I’m just very creative.
(c) Harry Potter and the Methods of Rationality

Taking part in competitions like “eurobot”, where you have to do some coding in extreme conditions, on/under a table, on the floor, etc. and a few other trips like that convinced me that I should definitely make something more of my cell phone. Something, that will help me out in this case.

So, we have:

  • A dumb brick called ‘HD7 Pro’ from china, with android 2.3.5. One and a half years old.
  • /dev/brains
  • A few hours of free time

What we want to get:

  • A portable server with lighttpd, ssh, git, etc
  • WiFi AP with local dns, internet tethering (if we’re not roaming!)

2013-03-18-00-19-06

(more…)

Работаем с мегафоном через PhantomJS (часть 1)

Итак, валяется у меня на даче на чердаке модем, который подцеплен к серверу, и через который ко мне идут интернеты. И через интернеты я иногда заглядываю как там и что без меня происходит. И все бы хорошо, но иногда хочется узнать, сколько осталось там траффика.
Вариантов тут было несколько.

  • USSD запрос до провайдера.
    Чревато занятиями любовью с /dev/ttyUSB* для отправки USSD и парсингом ответа с последующим вырезанием рекламы. Но так как один такой порт у меня оккупировал gammu-smsd, а на другом висит самописная приблуда для мониторинга качества соединения и переключения на 2g, в случае если вышка 3g “упадет”… (почему не доверяю переключаться самостоятельно модему – это отдельная история). В обещем, вкрячивать в эту штуку что-то еще мне ой как не хочется.
    Да и, как выяснилось, во время отправки USSD иногда мой хуавей рвет соединение. Отпадает.
  • Отправлять SMS и парсить ответ.
    C gammu-smsd это можно было бы сделать досточно быстро, да вот в силу неизбежной необходимости работать со страницей мегафона, этот вариант отпал.
  • Доступ для автоматизированных систем (который проскакивал в некоторых софтинах, типа BalanceRobot под андройд). Да вот только после 10 минут гуглежа документации по нему так и не нашлось.
  • Забирать http://user.moscow.megafon.ru и парсить содержимое.

(more…)

openwrt-sunxi: progress report

I finally managed to find a few spare minutes and make some serious progress on this port.

So, what’s new:

  • Rebased against the current openwrt trunk
  • Initial router name/model  stuff support via uboot env.
  • Now with stable 3.4 kernel from sunxi-3.4 branch. OpenWRT compiles kernel and working module packages
  • sun4i-specific modules like ahci, ir, i2c, etc. are now compiled and loaded by OpenWRT.
  • Instructions for building can be found at the github repo

wrt

 

Simple things that look complex: ping from android

Coding for a mobile platform has always been a frustrating experience ever since J2ME. Right now I really hope, that Jolla Mobile will succeed and roll their thingie to the market, since both iOS and android are smoking crap. But for now – I choose droid as a lesser evil.
So, a few days ago I needed to ping the internets from my app, to check if the connection is live. It’s been less than a week since a friend told me of all the ‘fun’ he had with SCNetworkCheckReachabilityByName on iOS for that purpose.

(more…)

Windows XP: transferring an installation from one partition to another (worst case)

Okay, a lot of people hate windows these days, few can say why.
A have quite a few reasons to do so. Especially, since quite a few retarted developers write software that I _have_ to use, to get some the work done, I eventually have to boot it, and, even, work in it. Luckily, thanks to the fact emacs feels nicely even there, that’s not big deal … But the tale is about how I wasted a whole evening trying to move a windows installations from one hdd to another. If in case of *NIX that takes a few minutes and a few config files to edit, here… Well, it’s a different reality.
So, my setup:
Old hdd, now in a usb-hdd enclosure:
/dev/sdс1 – / of the installed linux (Agilia)
/dev/sdc2 – swap
/dev/sdc3 – A temporary field for experiments with moblin/android x86/etc
/dev/sdc4 – WinXP

On the new drive, now fitted into my asus n10j the table was as follows:
/dev/sda1 – A spare place for Windoze
/dev/sda2 – / of Arch Linux
/dev/sda3 – swap

(more…)