[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Una de hostapd en debian 7...



On Thu, 30 Mar 2017 14:11:47 -0400, JAP <javier.debian.bb.ar@gmail.com> wrote:

El 29/03/17 a las 15:43, luisededios escribió:
La mía se reduce a un portal cautivo ZeroShell, el cual podía
engañarse mediante un script en python, el cual se iniciaba desde
/etc/rc.local.

Me interesa ese tema, recuerdas cómo lo hacías desde rc.local, alguna
línea?  :)

Bien.
Lo hice de dos maneras distintas.
Una, añadiendo el script de identificación en mi escritorio KDE, en "Arranque y apagado", "Autoarranque".
De esa manera, se iniciaba sólo si yo iniciaba la sesión en KDE.
La contra, es que cualquier problemita del escritorio, me quedaba sin red.
Por ello, pasá a adicionar la siguiente línea en /etc/rc.local

/usr/bin/python /opt/ZeroShell/zeroshell-autologin.py

Esto lo saqué de https://code.google.com/archive/p/zeroshell-autologin/


El script en cuestión, con alguna ínfima modificación mía, es el que sigue:

=============================================================
#!/usr/bin/python

# ZeroShell autologin

# load python library

from urllib import urlencode
from urllib2 import urlopen
from HTMLParser import HTMLParser
from time import sleep

# login conf

USERNAME = 'MiUsuario'
PASSWORD = 'MiClaveMuyDificil'
REALM = 'ElDominio' =========> El dominio de tu ISP
SERVER = '192.168.1.1' ======> El servidor ZeroShell

# default params

PROTOCOL = 'http'
PORT = '12080'
SCRIPT = 'zscp'
ZSCPRedirect = '_:::_'

URL = PROTOCOL + '://' + SERVER + ':' + PORT + '/cgi-bin/' + SCRIPT
RENEW_INTERVAL = 40

# class to parse Captive Portal HTML

class ZSParser(HTMLParser):
	def __init__(self):
		HTMLParser.__init__(self)
		self.params = {}
params = { 'U' : USERNAME , 'P' : PASSWORD , 'Realm' : REALM , 'Section' : 'CPAuth' , 'Action' : 'Authenticate' , 'ZSCPRedirect' : '_:::_' }
		http_req = urlopen(URL, urlencode(params))
		html_content = http_req.read()
		self.feed(html_content)
	
	def get_authkey(self):
return self.params['Authenticator'] # after parse HTML return the authenticator string

	def handle_starttag(self, tag, attrs):
if tag == 'input' and attrs[0][1] == 'hidden': # parse only de html input and hidden tags
			self.params[attrs[1][1]] = attrs[2][1]

parser = ZSParser() # instantiate the class
authkey = parser.get_authkey() # get authenticator string

# http_request 1 - Section = CPGW

params = { 'U' : USERNAME , 'P' : PASSWORD , 'Realm' : REALM , 'Authenticator' : authkey, 'Section' : 'CPGW' , 'Action' : 'Connect' , 'ZSCPRedirect' : '_:::_' }
urlopen(URL, urlencode(params))

# http_request 2 - Section = ClientCTRL

params = { 'U' : USERNAME , 'P' : PASSWORD , 'Realm' : REALM , 'Authenticator' : authkey, 'Section' : 'ClientCTRL' , 'Action' : 'Connect' , 'ZSCPRedirect' : '_:::_' }
urlopen(URL, urlencode(params))


while True:
	sleep(RENEW_INTERVAL) # wait a time in seconds to renew the connection
params = { 'Authenticator' : authkey, 'Section' : 'CPGW' , 'Action' : 'Renew' , 'ZSCPRedirect' : '_:::_' }
	urlopen(URL, urlencode(params))

=============================================================


Problemas conocidos:

A veces, ante un "lag" del sistema, el equipo se desconectaba de la red por haber vencido la sesión. Eso, si usas un navegador común, es cuestión de reiniciarlo, pero acá me quedaba el script corriendo.
Por lo que, como root, debía matar a python y reiniciar el script.
El BOFH que me tocó, le puso un temporizador al portal, de manera que si se me caía la conexión, debía esperar 10 minutos para reintentar conectarlo.

# killall -s 9 python

# /etc/rc.local
ó
# /usr/bin/python /opt/ZeroShell/zeroshell-autologin.py &

JAP

Interesante la aplicación pero yo pensaba que los datos usuario y contraseña podían pasarse en /etc/network/interfaces :)

--
Saludos,
Luis


Reply to: