#!/usr/bin/python # -*- coding: UTF-8 -*- # +-----------------------------------------------------------------------------+ # | GPL | # +-----------------------------------------------------------------------------+ # | Copyright (c) Brian Lewis Cairns | # | | # | This program is free software; you can redistribute it and/or | # | modify it under the terms of the GNU General Public License | # | as published by the Free Software Foundation; either version 2 | # | of the License, or (at your option) any later version. | # | | # | This program is distributed in the hope that it will be useful, | # | but WITHOUT ANY WARRANTY; without even the implied warranty of | # | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # | GNU General Public License for more details. | # | | # | You should have received a copy of the GNU General Public License | # | along with this program; if not, write to the Free Software | # | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | # +-----------------------------------------------------------------------------+ import binascii import commands import os import sys import time import sys # The "worker" part of the code. This code is called as a separate process by # the main code when changes need to be made, as those changes can only be made # by root. Essentially, SimplePPPApplet uses sudo to execute itself (specifically this # code) in a separate instance of the Python interpreter running as root. while True: connectdata = [] stdin = sys.stdin.readline() if stdin <> "": stdin = stdin[:-1] try: connectdata = binascii.a2b_hex(stdin).replace("\\","\\\\").replace('"','\\"').replace("$","\$").replace("`","\`").split("\n") except TypeError: print "This script (simpleppp-settings-client) is used by simplepppapplett to manage a ppp connection. It is not intended for direct use." sys.exit() else: if connectdata[0] == "ifup": r = commands.getoutput('ifup "' + connectdata[1] + '"') # The pppd process can die, leaving the interface configured, # but the connection down; if this happens, just bring the # interface down before attempting to bring it up. if r.find("already configured") > -1: commands.getoutput('ifdown "' + connectdata[1] + '"') commands.getoutput('ifup "' + connectdata[1] + '"') if connectdata[0] == "ifdown": commands.getoutput('ifdown "' + connectdata[1] + '"') if connectdata[0] == "kill": commands.getoutput("killall gtkwifi-settings-client") time.sleep(0.5) sys.exit() stdin = "" time.sleep(0.5)