h2020-westlife-eu / virtualfolder

Virtual Folder
http://internal-wiki.west-life.eu/w/index.php?title=D6.1
MIT License
1 stars 0 forks source link

Update webdav proxy config generation #24

Closed Benzene closed 7 years ago

Benzene commented 7 years ago

To make things work on my side, I had to configure apache so that a config block for a mounted webdav folder looks like:

<Location /webdav/mriviere@kth.se/b2drop/ >
  RequestHeader set Authorization "Basic XXXXXXXXXXXXXXXXXX"
  RequestHeader set Host "b2drop.eudat.eu"
  ProxyPreserveHost On
  ProxyPass "https://b2drop.eudat.eu/remote.php/webdav/"
  ProxyPassReverse "https://b2drop.eudat.eu/remote.php/webdav/"
</Location>

I'm not sure why it didn't work directly with the config you had. But anyway, the things I had to add (compared to the current version of mountb2drop.sh) were:

My updated mountb2drop.sh looks like the following. It's wrong to hardcode b2drop.eudat.eu in there, but I'm not sure how else to do it. Maybe there is a way to extract it from [url], but I'm not very good at bash.

function addapacheproxy {
  removeapacheproxy $2
  SFILE2=/tmp/secrets2
  echo -n $3:$4 > $SFILE2
  if [ -e $SFILE2 ]; then
    AUTH="$(base64 -w 0 $SFILE2)"
    #echo $AUTH
    echo "<Location $2 >" | sudo tee -a ${HTTPD_CONF}
    echo "  RequestHeader set Authorization \"Basic $AUTH\"" | sudo tee -a ${HTTPD_CONF} > /dev/null
    echo "  RequestHeader set Host b2drop.eudat.eu" | sudo tee -a ${HTTPD_CONF}
    echo "  ProxyPreserveHost On" | sudo tee -a ${HTTPD_CONF}
    echo "  ProxyPass \"$1\"" | sudo tee -a ${HTTPD_CONF}
    echo "  ProxyPassReverse \"$1\"" | sudo tee -a ${HTTPD_CONF}
    echo "</Location>" | sudo tee -a ${HTTPD_CONF}
    sudo service ${HTTPD_SERVICE} reload
  fi  
  rm $SFILE2
}

function removeapacheproxy {
 echo removing apache proxy
 L1=`grep -n -m 1 "\<Location $1" ${HTTPD_CONF} | cut -f1 -d:`
 echo from row $L1
 if [ $L1 > 0 ]; then #???
   let L2=$L1+6
   echo to row $L2
   sudo sed -i "$L1,$L2 d" ${HTTPD_CONF}
 fi
}