Python password display

2006-07-06 Thread Johhny
Hello,

I am currently writing some python code which requires the use of a
password. Currently I am using the raw_input function to take the users
input in and use it. One problem with that is the password is displayed
in clear text on the console of the server. I would like to work on a
way around that. Is there any built in method to do that or any
how-to's around the Internet / Advice that I could research?

Regards,

Johhny.

-- 
http://mail.python.org/mailman/listinfo/python-list


getting current UNIX uid

2006-07-06 Thread Johhny
Hello,

I am trying to get the user that is running the scripts uid, I have had
a look at the pwd module and it does not appear to offer that
functionality. Is there any way within python to get that information ?

Regards,

Johhny

-- 
http://mail.python.org/mailman/listinfo/python-list


regular expressions and matches

2006-03-30 Thread Johhny
Hello,

I have recently written a small function that will verify that an IP
address is valid.

==SNIP==

import re
ipAddress = raw_input('IP Address : ')

def validateIP(ipAddress):
ipRegex =
r^([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$
re_ip = re.compile(ipRegex)
match = re_ip.match(ipAddress)
if not match:
print an error has occured with ipAddress
return match
else:
return match

print(validateIP(ipAddress))

==SNIP==

I was having issues trying to get my code working so that I could pass
the IP addresses and it would return a true or false. When it matches I
get something that looks like this.

python ip_valid.py
IP Address : 192.158.1.1
_sre.SRE_Match object at 0xb7de8c80

As I am still attempting to learn python I am interested to know how I
could get the above to return a true or false if it matches or does not
match the IP address. I would also like to expand that so that if the
IP is wrong it requests the IP address again and recalls the function.
I have done the same thing in php very easily but python appears to be
getting the better of me. Any assistance and advice would be greatly
appreciated.

Regards,

Johhny

-- 
http://mail.python.org/mailman/listinfo/python-list


replacing \n characters in a hash

2006-01-26 Thread Johhny
Hello,

I am currently trying to write some scripts to get information from the
xmlrpc for redhat network. One of the issues I am having is trying to
strip off the special characters in the hash that is returned. Here is
an example of the information returned within the hash :

===SNIP===
{'errata_update_date': '2005-12-06', 'errata_topic': 'Updated
libc-client packages that fix a buffer overflow issue are
now\navailable.\n\nThis update has been rated as having moderate
security impact by the Red\nHat Security Response Team.',
'errata_type': 'Security Advisory', 'errata_notes': '',
'errata_synopsis': 'Moderate: libc-client security update',
'errata_references': '', 'errata_last_modified_date': '2006-01-25
10:37:24', 'errata_issue_date': '2005-12-06', 'errata_description':
'C-client is a common API for accessing mailboxes.\n\nA buffer overflow
flaw was discovered in the way C-client parses user\nsupplied
mailboxes. If an authenticated user requests a specially
crafted\nmailbox name, it may be possible to execute arbitrary code on
a server that\nuses C-client to access mailboxes. The Common
Vulnerabilities and Exposures\nproject has assigned the name
CVE-2005-2933 to this issue.\n\nAll users of libc-client should upgrade
to these updated packages, which\ncontain a backported patch that
resolves this issue.'}
===SNIP===


What I would like to do is remove the \n characters from
'errata_topic'. Which is this section of the hash.

Updated libc-client packages that fix a buffer overflow issue are
now\navailable.\n\nThis update has been rated as having moderate
security impact by the Red\nHat Security Response Team.

What I had attempted to do is use the replace() function but it
consistantly comes up with the following errors:

Traceback (most recent call last):
  File rhn_errata.py, line 63, in ?
errata_package = errata_package.strip('\n','')
AttributeError: 'dict' object has no attribute 'strip'

where errata_package is JUST the errata_topic hash value.

Any advice would be great on how to do that.

Regards,

Johhny

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacing \n characters in a hash

2006-01-26 Thread Johhny
Hello,

Thankyou for your response,
If I check that the errara_package value is with a print I get the
following.

===SNIP===
Updated libc-client packages that fix a buffer overflow issue are now
available.

This update has been rated as having moderate security impact by the
Red
Hat Security Response Team.
===SNIP===

Notice that it has formatted the output with the \n's.

So i dont understand why its reporting as a dictionary rather than just
the string.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacing \n characters in a hash

2006-01-26 Thread Johhny
Hello,

Here is the code (minus my details section).

server = xmlrpclib.ServerProxy(url)

session = server.auth.login(username,password)

#functions.

def getErrata():

channel_label = 'rhel-i386-as-4'

errata =
server.channel.software.list_errata(session,channel_label,start_date,end_date)

return errata



def getPackage(advisory):

Package = server.errata.get_details(session,advisory)

return Package



errata = getErrata()

for vals in errata:

  print %s\t\t%s\t\t%s\t%s\t%s %
(vals['errata_advisory'],vals['errata_issue_date'],vals['errata_update_date'],vals['errata_last_modified_date'],vals['errata_type'],)

  errata_info = getPackage(vals['errata_advisory'],)

  print errata_info['errata_topic']

  errata_package = errata_info['errata_topic']

  print getPackage(vals['errata_advisory'])

I have not got any of the section in to replace the \n's as I was
trying to work out why its not seeing what I thought was a string as a
dict.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replacing \n characters in a hash

2006-01-26 Thread Johhny
Hello,

In response to that the output is this :

type 'str' 'Updated libc-client packages that fix a buffer overflow
issue are now\navailable.\n\nThis update has been rated as having
moderate security impact by the Red\nHat Security Response Team.'

-- 
http://mail.python.org/mailman/listinfo/python-list


accessing hardware information using python

2006-01-20 Thread Johhny
Hello,

I am currently looking to write a utility in python that will monitor
the statis of a RAID card within linux. The card in Question is the LSI
SAS1064 as the tools provided by the vendor to monitor the software
does not suit our requirements.

However I am unsure how to convert dmidecode information like so :

Handle 0x0025
DMI type 10, 6 bytes.
On Board Device Information
Type: SCSI Controller
Status: Enabled
Description:  LSI serial-ATA #1


Into anything that I can use to extract information using python? Does
anyone have any ideas or any recommended reading about this matter?

Regards,

Johhny

-- 
http://mail.python.org/mailman/listinfo/python-list


reading files

2005-12-19 Thread Johhny
Hello All,

I am working my way through learning python as a language. I am having
some issues with something that looks right and does not work. I am
trying to get myself more familure with reading files. Based on the
tutorials at www.python.org This should work. but im not sure what
the issue is.

===SNIP===
import string

vsftpd=open('vsftpd.conf', 'r')
print vsftpd
vsftpd.read()
vsftpd.readlines()

vsftpd.close()
===SNIP===

When I check the permissions to ensure they are correct I get the
following.

stat vsftpd.conf
  File: `vsftpd.conf'
  Size: 4137Blocks: 16 IO Block: 131072 regular
file
Device: 802h/2050d  Inode: 51010   Links: 1
Access: (0644/-rw-r--r--)  Uid: ( 1000/  testing)   Gid: ( 1000/
testing)
Access: 2005-12-19 10:21:04.0 +
Modify: 2005-12-16 12:34:00.0 +
Change: 2005-12-16 12:34:00.0 +

When I run the script I get the following:

python reading_file.py
open file 'vsftpd.conf', mode 'r' at 0xb7d742a8

Does anyone have any advice on this issue at all. 

Regards,

Johhny.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: reading files

2005-12-19 Thread Johhny
Thanks for your assistance, Is it proper practice in python to flush
any memory when you exit? for example Ive read the file into memory,
when I close the file do I also have to flush any memory allocations ?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie to python

2005-12-16 Thread Johhny
Hello,

Here is the script then the problem.

cat testing.py

import crypt
import random, string
def getsalt(chars = string.letters + string.digits):
 return random.choice(chars) + random.choice(chars)
username = raw_input('password : ')
print crypt.crypt(username,getsalt())


python testing.py
password : testing
Traceback (most recent call last):
  File testing.py, line 1, in ?
import crypt
  File /home/testing/scripts/crypt.py, line 4, in ?
TypeError: 'module' object is not callable

-- 
http://mail.python.org/mailman/listinfo/python-list


text manipulation

2005-12-16 Thread Johhny
Hello,

I am trying to write a script in python (to replace a perl script with
limited functionality). Now I have some issues. Currently I am using
the perl to load the file then regex parse certain lines to remove
characters (uncomment lines and change variables). I would like to take
that into the python script. I have had a look at the module string
and I dont think its what Im looking for.

Here is an example of some text I would like to manipulate

#comment here
#user_defined_variable = no
#

I would like to make that

#comment here
user_defined_variable = yes
#

With perl/sed Its very easy, However Im having issues to do it in
python. Any advice would be great.

Regards,

Johhny.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie to python

2005-12-16 Thread Johhny
Thankyou, I appreciate your help. I did not realise that python would
behave that way.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: newbie to python

2005-12-15 Thread Johhny
Hello,

If I go into the python shell and type help(modules) It does show
that crypt is there. However Im unsure if that means that there is help
or its got the module installed.

From a dpkg --list python* I have

ii  python2.4-crypto
2.0+dp1-2ubuntu1 cryptographic
algorithms and protocols for Python

Which means it should work. However Im not really getting anything from
it. Which makes me wonder.

-- 
http://mail.python.org/mailman/listinfo/python-list