The files in this article are now bundled in a package available on Cydia called Lighttpd. You can also add lighttpd from the Wizardry and Steamworks Cydia repository and transfer it to your device using ssh
to install it locally using the debian package manager dpkg
.
The following shows how to create an on-off switch using PreferenceLoader for lighttpd.
/Library/PreferenceLoader/Preferences/net.lightysettings.plist <string>PSSwitchCell</string> <string>lightyEnabled</string> <string>net.lighttpd</string> +------>>------+ <key>key</key> | +<string>lightyEnabled</string> +----->>------+ v | +------+----------|---+ | | | _+_ | | | | Enable [_|_] | | +------+ | write | | Ext | | | +------+ | | | | | | | | | | +------+--------------+ | +--------------------------+ | read /private/var/mobile/Library/Preferences/net.lighttpd.plist +----->>-----------* | | | run | launchd v monitor +-------------->>-----+ /etc/scripts/lighttpd_manager.sh | + | / \ | / \ /Library/LaunchDaemons/net.lighttpd.plist / \ lighttpd lighttpd on off
PreferenceLoader stores all Settings plists in:
/Library/PreferenceLoader/Preferences
Every item on the Settings pane filed under Extensions
on a jailbroken device can reference a settings plist in /Library/PreferenceLoader/Preferences
:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>title</key> <string>Lighttpd Settings</string> <key>entry</key> <dict> <key>cell</key> <string>PSLinkCell</string> <key>label</key> <string>Lighttpd Settings</string> <key>icon</key> <string>LighttpdSettings.png</string> </dict> <key>items</key> <array> <dict> <key>cell</key> <string>PSSwitchCell</string> <key>default</key> <true/> <key>defaults</key> <string>net.lighttpd</string> <key>key</key> <string>lightyEnabled</string> <key>label</key> <string>Enable</string> </dict> <dict> <key>cell</key> <string>PSGroupCell</string> <key>footerText</key> <string>Lighttpd Switch (c) 2012 Wizardry and Steamworks.</string> </dict> </array> </dict> </plist>
The settings plist is located in:
/private/var/mobile/Library/Preferences
Whenever the example button above is flicked to on or off, we can see the setting in /private/var/mobile/Library/Preferences/net.lighttpd
using plutil
:
{ lightyEnabled = 1; }
Two icons are used:
LighttpdSettings@2x.png
of size 55x58
.LighttpdSettings.png
of size 28x29
.
and must be uploaded in the same folder as LighttpdSettings.plist
under /Library/PreferenceLoader/Preferences
.
Then, using a launchd plist placed in /Library/LaunchDaemons/
we can execute a shell script whenever that setting changes:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>Label</key> <string>net.lighttpd</string> <key>LowPriorityIO</key> <true/> <key>ProgramArguments</key> <array> <string>/etc/scripts/lighttpd_launcher.sh</string> </array> <key>RunAtLoad</key> <true/> <key>WatchPaths</key> <array> <string>/private/var/mobile/Library/Preferences/net.lighttpd.plist</string> </array> </dict> </plist>
The underlying trick are the launchd directives:
<key>WatchPaths</key> <array> <string>/private/var/mobile/Library/Preferences/net.lighttpd.plist</string> </array>
which make launchd monitor the /private/var/mobile/Library/Preferences/net.lighttpd.plist
file for changes.
Then we add the lighttpd_manager.sh
bash script in /etc/scripts/
containing:
#!/bin/bash # Copyright (C) Wizardry and Steamworks. # # Licensed to Wizardry and Steamworks under # the GPLv3 GNU License which can be found at: # http://www.gnu.org/licenses/gpl.html # STATUS=`ps -ax | grep '[l]ighttpd' | awk '{ print $1 }'` SETTING=`plutil -key lightyEnabled /private/var/mobile/Library/Preferences/net.lighttpd.plist` if [ $SETTING -eq 0 ]; then kill -s TERM $STATUS else lighttpd-angel -f /etc/lighttpd.conf fi
which will make sure that the daemon is launched and killed once the button is flicked on the Settings pane.