#!/bin/bash

#
# Detect proxy URL via WPAD
#
# Author: Mike Gabriel
# License: GNU General Public License v2 or later

# This new and very short wpad-extract script is a replacement
# for the old (before squeeze) libjavascript-perl based wpad-extract
# script. This version uses libproxy-tools to retrieve the
# proxy URL and thus is much shorter then its predecessor.

# Trick the KDE4 config backend to use the settings there to load the
# WPAD setting.  See also bug #644373.

# Look up one of the www.debian.org IP addresses to avoid hanging on
# DNS if the skolelinux machines are not connected to the Internet.
proxy_url=$(KDE_FULL_SESSION=foo \
   KDEDIRS=/usr/share/debian-edu/networked-kde3 \
   proxy http://130.89.148.14 2>/dev/null | cut -d" " -f1)

# make sure direct:// urls do not make it through to the system config
case "$proxy_url" in
    http:*|https:*)
	echo http_proxy=$proxy_url
	;;
esac
