summaryrefslogtreecommitdiffstats
path: root/linhes/linhes-web/website/contents/list_exports.py
blob: 79c2c38476d91fda4921d3520e70965b309dd97a (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
83
84
85
#!/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 "</br>"
print "<h2>__________ NFS Shares __________</h2>"
print "</br>"
print '<ul id="navlist">'
for sharename in nfslist:
    if sharename[1].find("noaccess") > -1 :
        print "<h3>%s \t no access</h3>" %sharename[0]
    else:
        print "<li>%s</li>" %sharename[0]

print '</ul>'

print "</br>"
print "<h2>__________ SMB Shares __________</h2>"
print "</br>"
print '<ul id="navlist">'
if len(smblist)  == 0:
    print "<h3>Samba is not running or no shares are listed</h3>"
    print "</br>"
else:
    for sharename in smblist:
        print "<li>%s</li>" %(sharename.split()[0])

print '</ul>'