Advertisement
uriel1998

GUI for using Python's HTTP server (using Zenity)

Apr 20th, 2012
455
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.39 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #
  4. # Requires Zenity to handle GUI output.  Creates a GUI walkthrough to use the built-in
  5. # HTTP server in Python for simple sharing on a LAN.  SECURE YOUR NETWORKS.
  6. # Run this script a second time to kill the server via killall.
  7. # Take out the gksudo portion if you need to
  8.  
  9. running=$(ps aux | grep -c "python -m SimpleHTTPServer")
  10. # my copy of grep always returns itself, hence it must be greater than 1.  Adjust as needed.
  11. if [ "$running" -gt "1" ];then
  12.     #this is inelegant as all hell, but I can't think of another way if it's running in the bg that can be handled from a GUI interface.
  13.     gksudo killall python -m SimpleHTTPServer
  14.     notify-send --icon=notification-network-wireless-disconnected "Stopped simple sharing."
  15. else
  16.     ans=`$(zenity --question --text "This will start a local webserver; to kill it, run this script again.  Please choose your directory to share in the next step.  Do you wish to continue?"); echo $?`
  17.     if [ "$ans" -lt "1" ]; then
  18.         rawfile=$(zenity --file-selection "--directory" --separator="*" --multiple)
  19.         localip=$(ifconfig | grep -e addr: | grep -e Bcast | awk '{print $2}'| awk -F ":" '{print $2}')
  20.         cd $rawfile
  21.         zenity --info --text "This script will start a webserver at $localip on port 8000 showing directory $rawfile."
  22.         notify-send --icon=notification-network-wireless-full "Serving $rawfile on port 8000"
  23.         python -m SimpleHTTPServer &
  24.     fi
  25. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement