Tuesday, August 5, 2014

Very light http server: lighttpd

The first thing that I wanted to do after setting up an Access Point on my laptop's wifi (See the previous post) is to setup an http server which is extremely light. My intention was to display some text, maybe some nice picture or a file-list of a directory. So, here is the solution, with a punny name:

pacman -S lighttpd

The config file is located at:  
Check if config file's syntax is correct:  
lighttpd -t -f /etc/lighttpd/lighttpd.conf
Default location of index.html file, according to the default config:

To create the index.html file:
echo 'TestMe!' >> /srv/http/index.html
chmod 755 /srv/http/index.html

Starting and reloading:
systemctl start lighttpd
systemctl reload lighttpd

Enabling over boot:
systemctl enable lighttpd

For PHP, SSL etc, check out the documentation home page.

Creating an access point in your system

If you wish to share your LAN bandwidth through wifi or just share some file though your wifi in an ad-hoc manner (a reference to wInDoWs users), or I don't know, just to check things out, you might want to look at this project by OBLiQUE that makes it very simple: https://bbs.archlinux.org/viewtopic.php?id=162895

Download the create_ap directory from git or otherwise.
No NAT or bridge needed. The script has options to set them or not. There are important dependencies. Check README or the create_ap file to find out.


systemctl disable netctl-auto@wlp6s0.service
# So that is does not conflict with "netctl-auto" managed wlan card wlp6s0

systemctl stop netctl-auto@wlp6s0.service

# So, disabling it stops it from happening over roboots
# Stopping it actually stops the service

ifconfig wlp6s0 up
# To bring the interface up (important)

Then traverse the directory and see help to set up aps.
For example, the share your LAN's (eth0) internet through wifi (wlp6s0) access point called "koboglo" with passphrase "lenovo1234", use:
./create_ap wlp6s0 eth0 koboglo lenovo1234 

I need to use --no-virt option to make it work depending on my wlan card. i.e.

./create_ap --no-virt wlp6s0 eth0 myaccesspt thebigpasswd

All about wifi

Most of the information presented here are taken from and are no richer than: https://wiki.archlinux.org/index.php/Wireless_network_configuration
But then again, it is a well known fact that setting up/reconfiguring the wifi on your laptop may be one of the most challenging tasks you had to go through at some point or the other in your life. At least I had to. For the first time when you get it working, you ask yourself, "How exactly did it work?" But it's the same as asking "How do magnets work?" and the answer always is "Magic".

So, when you are in the illusion that you have isolated the minimum number of steps to get it working again, you do not bother making them generic or don't care whether they work on other computers or wlan cards. You just stop asking questions, write the steps down and upload it to a place like a blog or something similarly eternal, hoping that you won't have to go through the same nightmare all over again. Until you buy a new laptop.

Anyways, the moral here is: life is too short to rediscover the steps to get your wifi working again.

Vague Theory:

Notation: We are using Arch Linux. The wlan card is: wlp6s0, the profile you want to connect to is: profile.

The program "netctl-auto" automates the connecting process.
"wifi-menu" creates the profile and keeps it in /etc/netctl.
"netctl-auto start/enable profile" attaches the profile to netctl and finally, 
"netctl-auto start/enable netctl-auto@wlp6s0.service" forces wlp6s0 to connect to the internet using the profile. 

This eases up several jobs: 

Setting up wifi for the first time:  
wifi-menu to create a profile,  
dhcpcd wlp6s0 to get ip through dhcp,  
systemctl enable dhcpcd.service to make it work over reboots.  

systemctl start netctl-auto@wlp6s0 to let netctl-auto handle the automatic connection,

systemctl enable netctl-auto@wlp6s0 to make it work over reboots. netctl-auto enable profile to make the profile work over reboots. 

Deleting a profile, while it is already enabled: 

The first step is to tell netctl-auto to stop using the profile. 

netctl-auto disable profile  
should do that. But unfortunately, it still uses the profile somehow. You can verify it by issuing "systemctl restart netctl-auto@wlp6s0" and see that it is again connecting to the same profile. The solution is to delete the profile. 

rm /etc/netctl/profile  
netctl-auto disable profile
systemctl restart netctl-auto@wlp6s0 
and "ifconfig" to verify that the wlp6s0 is free. 

Note that: there is no such method to stop the profile using a single netctl-auto command. (Or, is there?)

Setting up a new profile:

To set up the profile, issue  

If you get error (maybe through journalctl -xn) that "the interface is already up", it means that the profile still exists somehow. Follow the previous steps of "Deleting a profile while it is already enabled". 

After wifi-menu finishes creating the profile, if "systemctl enable/start netctl-auto@wlp6s0" is already issued, you should be able to connect. Otherwise, issue
systemctl start netctl-auto@wlp6s0 
systemctl enable netctl-auto@wlp6s0 

Optionally, use 
netctl-auto enable profile
to make it an automatic profile. 

Switching to a new profile: 

Use wifi-menu to create a new profile and use  
netctl-auto switch-to new_profile.