summaryrefslogtreecommitdiffstats
path: root/abs/core/supplemental-web/contents/list_exports.py
blob: 13ec690cce9571ff196bdbd074d23a47df7cf9a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/python2
import subprocess

def  nfs_export_list():
    nfslist = []
    exportfile = "/etc/exports"
    proc = subprocess.Popen(["showmount", "-a"] , stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    stdout,stderr = proc.communicate()
    rc = proc.returncode
    if rc == 0:
        try:
            f = open(exportfile,"r")
            for line in f.readlines():
                if line.startswith("#"):
                    continue
                item = line.split()
                if len(item) <= 1 :
                    continue
                nfslist.append(item)
        except :
            pass
    else:
        nfslist.append(["NFS server  is not running",'NFS server is not running'])
    return nfslist


def smb_share_list():
    smblist=[]

    proc = subprocess.Popen(["smbclient", "-L", "\\localhost" , "-N"], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    stdout,stderr = proc.communicate()
    outstuff = stderr.split("\n")
    for line in outstuff:
        try:
            heading1 = line.split()[0]
        except:
            continue
        #print heading1
        #print heading1.find("Domain")
        if heading1.find("Domain") > -1  :
            #smblist.append('')
            smblist.append(heading1)
            break

    outstuff = stdout.split("\n")
    for line in outstuff:
        try:
            heading1,heading2 = line.split()
        except:
            continue
        if heading1 == "Server" and heading2 == "Comment":
            break
        smblist.append(line)

    return smblist


nfslist = nfs_export_list()
smblist = smb_share_list()


print "---------NFS SHARES-----------\n"
print "</br>"
for sharename in nfslist:
    if sharename[1].find("noaccess") > -1 :
        print "%s \t no access" %sharename[0]
        print "</br>"
    else:
        print sharename[0]
        print "</br>"

print "\n---------SMB SHARES----------\n"
print "</br>"

if len(smblist)  == 0:
    print "Samba is not running or no shares listed"
    print "</br>"
else:
    for sharename in smblist:
        print "%s" %(sharename.split()[0])
        print "</br>"