File: zarapy.py

package info (click to toggle)
kopanocore 8.7.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 15,400 kB
  • sloc: cpp: 175,422; python: 24,623; perl: 7,319; php: 6,056; sh: 2,172; makefile: 1,294; xml: 45; ansic: 1
file content (102 lines) | stat: -rwxr-xr-x 4,782 bytes parent folder | download
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/python3
# SPDX-License-Identifier: AGPL-3.0-only

# simple html-based viewer (users, folders, items)

import cherrypy
import kopano

cherrypy.server.socket_host = '127.0.0.1'

class ZaraPy(object):
    @cherrypy.expose
    def index(self):
        html ='<html>'

        for company in kopano.Server().companies():
            html = html + '<table>'
            html = html + "<tr><th>company.name</th><th>user.name </th><th> user.store.guid</th><th>user.server.name</th><tr>\n"
            for user in kopano.Server().company(company.name).users():
                html = html + "<tr><td>" + company.name + "</td><td><a href=/viewuser/"+ company.name + "/" + user.name + ">" + user.name + "</a><td><a href=/listfolders/"+ company.name + "/" + user.name + ">Folders</a></td></td><td>" + user.store.guid + "</td><td>" + user.server.name + "</td><tr>\n"
            html = html + '</table>\n'

            html =  html + '</html>\n'

        return html

    @cherrypy.expose
    def viewuser(self, company=None,user=None):
        user = dict(user=user)
        company = dict(company=company)

        html = '<html><h1>Company: %s <br>User: %s</h1>' % (company['company'],user['user'])
        html = html + "<table><tr><th>prop.idname</th><th>prop.proptype</th><th>prop.value</th><tr>\n"

        for props in kopano.Server().company(company['company']).user(user['user']).props():
            if props.typename == 'PT_BINARY':
                html = html + "<tr><td>" + str(props.idname) + "</td><td>" +  "</td><td>" + str(props.value.encode('hex').upper()) + "</td><tr>\n"
            else:
                html = html + "<tr><td>" + str(props.idname) + "</td><td>" + "</td><td>" + str(props.value) + "</td><tr>\n"
    
        html = html + '</table></html>\n'
        return html


    @cherrypy.expose
    def listfolders(self, company=None,user=None,folder=None):
        user = dict(user=user)
        company = dict(company=company)
        foldername= dict(folder=folder)
        html = '<html><h1>Company: %s <br>User: %s</h1>' % (company['company'],user['user'])
        if foldername['folder']:
            html = html + "<table><tr><th>item.subject</th><th>item.entryid</th><tr>\n"
            for folder in kopano.Server().company(company['company']).user(user['user']).store.folders():
                if folder.entryid == foldername['folder']:
                    for item in folder.items():
                        html = html + "<tr><td><a href=/listitem/%s/%s/%s/%s>%s</a></td><td>%s</td><tr>\n" %( company['company'],user['user'],folder.entryid,item.entryid.encode('hex'),item.subject.encode("utf-8"),item.entryid.encode('hex'))
        else:
            html = html + "<table><tr><th>item.subject</th><th>item.entryid</th><tr>\n"
            for folder in kopano.Server().company(company['company']).user(user['user']).store.folders():
                html = html + "<tr><td><a href=/listfolders/%s/%s/%s>%s</a></td><td>%s</td><tr>\n" %( company['company'],user['user'],folder.entryid,folder.name,folder.entryid)
        
        html = html + '</table></html>\n'

        return html

    @cherrypy.expose
    def listitem(self, company=None,user=None,folder=None,item=None):
        user = dict(user=user)
        company = dict(company=company)
        itemname= dict(item=item)
        foldername= dict(folder=folder)
        html=''
        print(itemname['item'] + "\n")
        html = '<html><h1>Company: %s <br>User: %s</h1>' % (company['company'],user['user'])
        #html = html + "<table><tr><th>prop.name</th><th>prop.value</th><tr>\n"
        if itemname['item']:
            #html = html + "<table><tr><th>item.subject</th><th>item.entryid</th><tr>\n"
            for folder in kopano.Server().company(company['company']).user(user['user']).store.folders():
                if folder.entryid == foldername['folder']:
                    for item in folder.items():
                        print("curr %s" , item.entryid.encode('hex'))
                        print("look %s", itemname['item'])
                        if item.entryid.encode('hex')==itemname['item']:
                            print("match")
                            for prop in item.props():
                                if (prop.idname == 'PR_HTML') or (prop.idname=='PR_BODY'):
                                    try:
                                        html = html + "<table><tr><td>%s</td><td>%s</td><tr>\n" % ( prop.name , str(prop.value))
                                    except:
                                        pass
        
        html = html + '</table></html>\n'

        return html

if __name__ == '__main__':
    conf = {
        '/': {
            'tools.sessions.on': True
        }
    }
    cherrypy.quickstart(ZaraPy())