summaryrefslogtreecommitdiff
path: root/src/webhttrack
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2014-10-15 19:17:29 +0000
committerXavier Roche <xroche@users.noreply.github.com>2014-10-15 19:17:29 +0000
commit9b5c6cf86ed8dbf749bc2e401d4f87d340b6413d (patch)
tree38e035f0b797edeb5bdbc708681eacedeef53887 /src/webhttrack
parentcce112d40a6e36b2c437418e84c57490818603cb (diff)
Fixed webhttrack incompatibility with Chrome
* closes:#53 Also fixed HTML-escaping issues inside webhttrack Rationale: The webhttrack script made the wrong assumption that once the "browse" command returned, it meant the user killed the navigation window, and it had to kill the server itself. However, modern browsers tend to "attach" to an existing session (creating a new tab, for example, within an existing window), causing the browsing command to return immediately, thus causing the server to be killed immediately by the webhttrack script. I have rewritten the logic behind, and now the server is able to kill himself if the parent script dies, AND if the browsing client did not make any activity for two minutes. The "activity" can be any browser/refreshed page, or the internal "ping" iframe (which pings the server every 30 seconds). With this model, we *should* be compatible with old browsers, and modern ones.
Diffstat (limited to 'src/webhttrack')
-rwxr-xr-xsrc/webhttrack79
1 files changed, 7 insertions, 72 deletions
diff --git a/src/webhttrack b/src/webhttrack
index e41991a..879a5d8 100755
--- a/src/webhttrack
+++ b/src/webhttrack
@@ -29,81 +29,15 @@ echo "$0($$): $@" >&2
return 0
}
-function mozillabrowser {
-# returns 0, if the browser is mozilla type
-echo "$1" | grep -q "iceape"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "mozilla"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "netscape"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "firebird"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "firefox"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "iceweasel"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "abrowser"
-[ $? -eq 0 ] && return 0
-echo "$1" | grep -q "icecat"
-[ $? -eq 0 ] && return 0
-return 1;
-}
-function mozillaloaded {
-user_name=`logname 2>/dev/null`
-if ! test -n "${user_name}"; then
-user_name=`id -un`
-fi
-if test -n "${user_name}"; then
-ps -e -U "$user_name" | grep -E "(iceape|mozilla|netscape|firebird|firefox)" | grep -qv "grep -E"
-else
-false
-fi
-}
-
function launch_browser {
log "launching $1"
-start_t=`date +%s`
browser=$1
url=$2
-moz=
-if mozillaloaded; then
-moz=1
-fi
-# launch any browser
-# if it is a mozilla like browser, check if the browser is running and use
-# -remote if needed. Change the URL into openURL($url) too.
-# (thanks to Torsten Werner for the patch)
-# see http://www.mozilla.org/unix/remote.html
-# 04/2006: openurl() fix from Samuel Suther
-if mozillabrowser ${browser}; then
- if ! ${browser} -remote "openurl(${url})"; then
- log "spawning browser.."
- ${browser} "${url}"
- fi
-else
- log "spawning regular browser.."
- ${browser} "${url}"
-fi
-# this is a real pain in the neck: browser can hiddenly use the -remote feature of
+log "spawning browser.."
+${browser} "${url}"
+# note: browser can hiddenly use the -remote feature of
# mozilla and therefore return immediately
-# this loop is the only reliable solution AFAIK
-end_t=`date +%s`
-if test -n "$start_t" -a -n "$end_t"; then
- int_t=$[$end_t-$start_t]
-else
- int_t=0
-fi
-if test -n "${int_t}" -a "${int_t}" -lt 60; then
- if test -n "$moz"; then
- log "waiting for browser to terminate.."
- while mozillaloaded; do
- sleep 3
- done
- log "browser seems to have been closed.."
- fi
-fi
-log "browser exited"
+log "browser (or helper) exited"
}
# First ensure that we can launch the server
@@ -164,7 +98,7 @@ fi
# Create a temporary filename
TMPSRVFILE="$(mktemp ${TMPDIR:-/tmp}/.webhttrack.XXXXXXXX)" || ! log "cound not create the temporary file ${TMPSRVFILE}" || exit 1
# Launch htsserver binary and setup the server
-(${BINPATH}/htsserver "${DISTPATH}/" path "${HOME}/websites" lang "${LANGN}" $@; echo SRVURL=error) > ${TMPSRVFILE}&
+(${BINPATH}/htsserver "${DISTPATH}/" --ppid "$$" path "${HOME}/websites" lang "${LANGN}" $@; echo SRVURL=error) > ${TMPSRVFILE}&
# Find the generated SRVURL
SRVURL=
MAXCOUNT=60
@@ -180,7 +114,8 @@ done
# Cleanup function
function cleanup {
test -n "$1" && log "nasty signal caught, cleaning up.."
-test -f ${TMPSRVFILE} && SRVPID=`grep -E PID= ${TMPSRVFILE} | cut -f2- -d=`
+# Do not kill if browser exited (chrome bug issue) ; server will die itself
+test -n "$1" && test -f ${TMPSRVFILE} && SRVPID=`grep -E PID= ${TMPSRVFILE} | cut -f2- -d=`
test -n "${SRVPID}" && kill -9 ${SRVPID}
test -f ${TMPSRVFILE} && rm ${TMPSRVFILE}
test -n "$1" && log "..done"