source: TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browse/insecure.py @ 1171

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI07-MOLES/trunk/StubB/XSLT/browse/portal/cgi/browse/insecure.py@1171
Revision 1171, 2.2 KB checked in by lawrence, 13 years ago (diff)

More browse/discovery rendering modifications, utilising
Kev's new DIF returning routine ...

Line 
1#
2#This module provides python wrappers to Kevin's java code
3# I'm aiming to avoid having any java dependencies in the main browseCGI code
4# as I figure these command line activities at some point ought to be removed.
5# They certainly should be regarded as potentially insecure, especially the
6# exist call ...
7# BNL, April 2006
8#
9
10import os
11import os.path
12import tempfile
13import commands
14
15def osCommand(cmd):
16        stdin,stdout,stderr=os.popen3(cmd)
17        error=stderr.readlines()
18        if error !=[]:
19                return 1,error
20        else:
21                s=''
22                for i in stdout.readlines():s+=i
23                return 0,s
24
25def insecureGetDoc(uri,db='glue.badc.rl.ac.uk',format='NDG-B0',
26        jar='./returnstubb.jar',javaBin='java'):
27        ''' Use Kevin's code to get the document from exist '''
28        #we assume the URI is of the form repository/localid
29        #we don't use os.path.split, because this is os indpendent.
30        edb='xmldb:exist://%s:8080/exist/xmlrpc'%db
31        #following a hack for testing:
32        if uri=='methyl.example.xml':
33            try:
34                f=file('../exampleB/methyl.example.xml')
35            except:
36                f=file('/var/www/html/exampleB/methyl.example.xml')
37            return f.read()
38        try:
39                repPath,localID=uri.split('/')
40        except:
41                return None
42        #we can hash all this up properly later ...
43        #this file should exist (for the moment) in the cgi directory ...
44        #I know that's not very tidy, but it doesn't matter for the moment ...
45        f=file('passwords.txt','r')
46        pw={}
47        for host in f.readlines():
48            h=host.strip().split(' ')
49            pw[h[0]]=h[1],h[2]
50        #try:
51        cmd='%s -jar %s repositoryID %s localID %s repository %s user %s userpw %s format %s'%(
52               javaBin,jar,repPath,localID, edb, pw[db][0], pw[db][1], format)
53        status,result=commands.getstatusoutput(cmd)
54        #except:
55        #    return None
56        if status: 
57                return None
58        else:
59                return result
60       
61if __name__=="__main__":
62        javaBin='java'
63        jarLoc='../../returnstubb.jar'
64        id='badc.nerc.ac.uk/dataent1'
65        db='glue.badc.rl.ac.uk'
66        d= insecureGetDoc(id,db=db,jar=jarLoc,javaBin=javaBin,format='DIF')
67        print d
68        #print d
69        #dd=doXSLT(d,jar='../xalan-j_2_7_0/xalan.jar')
70        #print dd
Note: See TracBrowser for help on using the repository browser.