Deleted Added
full compact
httpproxy.subr (252987) httpproxy.subr (253333)
1if [ ! "$_MEDIA_HTTPPROXY_SUBR" ]; then _MEDIA_HTTPPROXY_SUBR=1
2#
3# Copyright (c) 2012-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
1if [ ! "$_MEDIA_HTTPPROXY_SUBR" ]; then _MEDIA_HTTPPROXY_SUBR=1
2#
3# Copyright (c) 2012-2013 Devin Teske
4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:

--- 10 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/httpproxy.subr 252987 2013-07-07 18:51:44Z dteske $
27# $FreeBSD: head/usr.sbin/bsdconfig/share/media/httpproxy.subr 253333 2013-07-14 03:08:52Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/httpproxy.subr
34f_include $BSDCFG_SHARE/dialog.subr
35f_include $BSDCFG_SHARE/media/ftp.subr

--- 288 unchanged lines hidden (view full) ---

324
325 unset $VAR_HTTP_PROXY_PATH
326 f_media_set_http_proxy || break
327 done
328
329 return $http_found
330}
331
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." media/httpproxy.subr
34f_include $BSDCFG_SHARE/dialog.subr
35f_include $BSDCFG_SHARE/media/ftp.subr

--- 288 unchanged lines hidden (view full) ---

324
325 unset $VAR_HTTP_PROXY_PATH
326 f_media_set_http_proxy || break
327 done
328
329 return $http_found
330}
331
332# f_media_get_http_proxy $device $file [$probe_only]
332# f_media_get_http_proxy $device $file [$probe_type]
333#
334# Returns data from $file on an FTP server via HTTP proxy using nc(1). Please
335# note that $device is unused but must be present (even if null). Information
333#
334# Returns data from $file on an FTP server via HTTP proxy using nc(1). Please
335# note that $device is unused but must be present (even if null). Information
336# is instead gathered from the environment. If $probe_only is both present and
336# is instead gathered from the environment. If $probe_type is both present and
337# non-NULL, this function exits after receiving the HTTP header response from
338# the proxy server (if the HTTP response code is 200, success is returned;
337# non-NULL, this function exits after receiving the HTTP header response from
338# the proxy server (if the HTTP response code is 200, success is returned;
339# otherwise failure).
339# otherwise failure). If $probe_type is equal to $PROBE_SIZE, prints the
340# content-length in bytes from the response (or -1 if not found) to standard-
341# out.
340#
341# The variables used to configure the connection are as follows (all of which
342# are configured by f_media_set_http_proxy above):
343#
344# VAR_HTTP_PROXY_HOST
345# HTTP proxy host to connect. Can be an IPv4 address, IPv6
346# address, or DNS hostname of your choice.
347# VAR_HTTP_PROXY_PORT

--- 5 unchanged lines hidden (view full) ---

353# See variable.subr for additional information.
354#
355# Example usage:
356# f_media_set_http_proxy
357# f_media_get_http_proxy media $file
358#
359f_media_get_http_proxy()
360{
342#
343# The variables used to configure the connection are as follows (all of which
344# are configured by f_media_set_http_proxy above):
345#
346# VAR_HTTP_PROXY_HOST
347# HTTP proxy host to connect. Can be an IPv4 address, IPv6
348# address, or DNS hostname of your choice.
349# VAR_HTTP_PROXY_PORT

--- 5 unchanged lines hidden (view full) ---

355# See variable.subr for additional information.
356#
357# Example usage:
358# f_media_set_http_proxy
359# f_media_get_http_proxy media $file
360#
361f_media_get_http_proxy()
362{
361 local dev="$1" file="$2" probe_only="$3" hosts=
363 local dev="$1" file="$2" probe_type="$3" hosts=
362
364
363 f_dprintf "f_media_get_http_proxy: dev=[%s] file=[%s] probe_only=%s" \
364 "$dev" "$file" "$probe_only"
365 f_dprintf "f_media_get_http_proxy: dev=[%s] file=[%s] probe_type=%s" \
366 "$dev" "$file" "$probe_type"
365
366 local proxy_host proxy_port
367 f_getvar $VAR_HTTP_PROXY_HOST proxy_host
368 f_getvar $VAR_HTTP_PROXY_PORT proxy_port
369
370 if ! {
371 f_validate_ipaddr "$proxy_host" ||
372 f_validate_ipaddr6 "$proxy_host" ||

--- 30 unchanged lines hidden (view full) ---

403 f_dprintf "sending http request for: %s" "$url"
404 printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$proxy_port" |
405 (
406 #
407 # scan the headers of the response
408 # this is extremely quick'n dirty
409 #
410
367
368 local proxy_host proxy_port
369 f_getvar $VAR_HTTP_PROXY_HOST proxy_host
370 f_getvar $VAR_HTTP_PROXY_PORT proxy_port
371
372 if ! {
373 f_validate_ipaddr "$proxy_host" ||
374 f_validate_ipaddr6 "$proxy_host" ||

--- 30 unchanged lines hidden (view full) ---

405 f_dprintf "sending http request for: %s" "$url"
406 printf "GET %s HTTP/1.0\r\n\r\n" "$url" | nc -n "$host" "$proxy_port" |
407 (
408 #
409 # scan the headers of the response
410 # this is extremely quick'n dirty
411 #
412
411 rv=0
413 rv=0 length=-1
412 while read LINE; do
413 case "$LINE" in
414 HTTP*)
415 f_dprintf "received response: %s" "$LINE"
416 set -- $LINE; rv=$2
417 f_isinteger "$rv" || rv=0
418 ;;
414 while read LINE; do
415 case "$LINE" in
416 HTTP*)
417 f_dprintf "received response: %s" "$LINE"
418 set -- $LINE; rv=$2
419 f_isinteger "$rv" || rv=0
420 ;;
421 "Content-Length: "*)
422 length="${LINE%
423}"
424 length="${length#Content-Length: }"
425 f_dprintf "received content-length: %s" \
426 "$length"
427 ;;
419 *)
420 [ "${LINE%
421}" ] || break # End of headers
422 esac
423 done
424
425 [ $rv -ge 500 ] && exit 5
426 [ $rv -eq 404 ] && exit 44
427 [ $rv -ge 400 ] && exit 4
428 [ $rv -ge 300 ] && exit 3
429 [ $rv -eq 200 ] || exit $FAILURE
430
428 *)
429 [ "${LINE%
430}" ] || break # End of headers
431 esac
432 done
433
434 [ $rv -ge 500 ] && exit 5
435 [ $rv -eq 404 ] && exit 44
436 [ $rv -ge 400 ] && exit 4
437 [ $rv -ge 300 ] && exit 3
438 [ $rv -eq 200 ] || exit $FAILURE
439
431 if [ ! "$probe_only" ]; then
440 if [ ! "$probe_type" ]; then
432 cat # output the rest ``as-is''
441 cat # output the rest ``as-is''
442 elif [ "$probe_type" = "$PROBE_SIZE" ]; then
443 f_isinteger "$length" || length=-1
444 echo "$length"
433 fi
434 exit 200
435 )
436 local retval=$?
437 [ $retval -eq 200 ] && return $SUCCESS
445 fi
446 exit 200
447 )
448 local retval=$?
449 [ $retval -eq 200 ] && return $SUCCESS
438 [ "$probe_only" ] && return $FAILURE
450 [ "$probe_type" ] && return $FAILURE
439
440 case "$retval" in
441 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
442 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
443 4) f_show_msg "$msg_client_error" ;;
444 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
445 esac
446 return $FAILURE
447}
448
449############################################################ MAIN
450
451f_dprintf "%s: Successfully loaded." media/httpproxy.subr
452
453fi # ! $_MEDIA_HTTPPROXY_SUBR
451
452 case "$retval" in
453 5) f_show_msg "$msg_server_error_when_requesting_url" "$url" ;;
454 44) f_show_msg "$msg_url_was_not_found" "$url" ;;
455 4) f_show_msg "$msg_client_error" ;;
456 *) f_show_msg "$msg_error_when_requesting_url" "$url" ;;
457 esac
458 return $FAILURE
459}
460
461############################################################ MAIN
462
463f_dprintf "%s: Successfully loaded." media/httpproxy.subr
464
465fi # ! $_MEDIA_HTTPPROXY_SUBR