2003-07-04 14:24:44 +00:00
|
|
|
# -*- coding: iso-8859-1 -*-
|
2001-03-15 01:19:35 +00:00
|
|
|
"""Handle telnet: links"""
|
2003-01-11 12:38:18 +00:00
|
|
|
# Copyright (C) 2000-2003 Bastian Kleineidam
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# 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.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# 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.
|
2001-03-15 01:19:35 +00:00
|
|
|
#
|
2001-05-23 21:20:44 +00:00
|
|
|
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2000-11-11 00:38:04 +00:00
|
|
|
|
2003-01-05 23:20:59 +00:00
|
|
|
import telnetlib, urlparse
|
2003-08-18 22:14:47 +00:00
|
|
|
from linkcheck import LinkCheckerError, i18n
|
2003-01-08 08:47:49 +00:00
|
|
|
from debug import *
|
2003-08-18 22:14:47 +00:00
|
|
|
from urllib import splituser, splitport, splitpasswd
|
2000-02-26 10:24:46 +00:00
|
|
|
from HostCheckingUrlData import HostCheckingUrlData
|
2002-12-31 00:31:22 +00:00
|
|
|
from UrlData import is_valid_port
|
2000-02-26 10:24:46 +00:00
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
class TelnetUrlData (HostCheckingUrlData):
|
2000-02-26 10:24:46 +00:00
|
|
|
"Url link with telnet scheme"
|
2000-04-24 22:07:48 +00:00
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
def buildUrl (self):
|
2003-08-11 13:19:39 +00:00
|
|
|
super(TelnetUrlData, self).buildUrl()
|
2002-12-31 00:31:22 +00:00
|
|
|
parts = urlparse.urlsplit(self.url)
|
|
|
|
|
userinfo, self.host = splituser(parts[1])
|
|
|
|
|
self.host, self.port = splitport(self.host)
|
|
|
|
|
if self.port is not None:
|
|
|
|
|
if not is_valid_port(self.port):
|
2003-01-22 19:50:13 +00:00
|
|
|
raise LinkCheckerError(i18n._("URL has invalid port number %s")\
|
2002-12-31 00:31:22 +00:00
|
|
|
% self.port)
|
|
|
|
|
self.port = int(self.port)
|
|
|
|
|
else:
|
2002-01-28 21:24:59 +00:00
|
|
|
self.port = 23
|
2002-12-31 00:31:22 +00:00
|
|
|
if userinfo:
|
|
|
|
|
self.user, self.password = splitpasswd(userinfo)
|
|
|
|
|
else:
|
|
|
|
|
self.user, self.password = self.getUserPassword()
|
|
|
|
|
|
2000-02-26 10:24:46 +00:00
|
|
|
|
2002-05-04 13:27:02 +00:00
|
|
|
def checkConnection (self):
|
2003-08-11 13:19:39 +00:00
|
|
|
super(TelnetUrlData, self).checkConnection()
|
2000-02-26 10:24:46 +00:00
|
|
|
self.urlConnection = telnetlib.Telnet()
|
2003-01-09 01:53:05 +00:00
|
|
|
self.urlConnection.set_debuglevel(get_debuglevel())
|
2002-01-28 21:24:59 +00:00
|
|
|
self.urlConnection.open(self.host, self.port)
|
|
|
|
|
if self.user:
|
|
|
|
|
self.urlConnection.read_until("login: ", 10)
|
|
|
|
|
self.urlConnection.write(self.user+"\n")
|
|
|
|
|
if self.password:
|
|
|
|
|
self.urlConnection.read_until("Password: ", 10)
|
|
|
|
|
self.urlConnection.write(self.password+"\n")
|
2002-12-31 00:31:22 +00:00
|
|
|
# XXX how to tell if we are logged in??
|
2002-01-28 21:24:59 +00:00
|
|
|
self.urlConnection.write("exit\n")
|
2003-07-04 14:24:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def hasContent (self):
|
2003-08-11 12:29:11 +00:00
|
|
|
return False
|
2003-07-04 14:24:44 +00:00
|
|
|
|