#!/usr/bin/env python #============================================================================ # This file is part of Pwman3. # # Pwman3 is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 2 # as published by the Free Software Foundation; # # Pwman3 is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Pwman3; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #============================================================================ # Copyright (C) 2012-2014 Oz Nahum #============================================================================ from __future__ import print_function from bottle import route, run, debug, template, request, get, redirect import os import sys import re import shutil from pwman import default_config, which from pwman import parser_options from pwman.ui import get_ui_platform from pwman.ui.tools import CLICallback from pwman.util.crypto import CryptoEngine import pwman.util.config as config import pwman.data.factory from pwman.data.tags import TagNew from pwman import parser_options, get_conf_options AUTHENTICATED = False TAGS = None DB = None tmplt = """ %#template to generate a HTML table from a list of tuples (or list of lists, or tuple of tuples or ...)

Click on username to view the details:

%for node in nodes: %#for item in node: %# %end %end
<{{item}} {{node.username}}@{{node.url}} {{ ', '.join([t.strip() for t in filter(None, node.tags)]) }} edit
""" edit_node_tmplt = """
Username:
Password:
Repeat Password:
Notes:
Tags:
""" login = """

Please enter your database password:

Password: """ @route('/node/:no') def view_node(no): global DB node = DB.getnodes([no]) tmplt = """
Username: {{ node.username }}
Password: {{ node.password }}
Url: {{node.url}}
Notes: {{node.notes}}
Tags: {{node.tags}}
""" output = template(tmplt, node=node[0]) return output @route('/new', method=['GET', 'POST']) def new(): pass @route('/edit/:no', method=['GET', 'POST']) def edit_node(no): global DB node = DB.getnodes([no])[0] output = template(edit_node_tmplt, node=node) return output @route('/auth', method=['GET', 'POST']) def is_authenticated(): global AUTHENTICATED crypto = CryptoEngine.get() if request.method == 'POST': key = request.POST.get('pwd', '') crypto.auth(key) AUTHENTICATED = True redirect('/') else: return login @route('/', method=['GET', 'POST']) def listnodes(): global AUTHENTICATED, TAGS, DB _filter = None OSX = False args = parser_options().parse_args() xselpath, dbtype = get_conf_options(args, OSX) dbver = 0.4 DB = pwman.data.factory.create(dbtype, dbver) DB.open() crypto = CryptoEngine.get() if not AUTHENTICATED: redirect('/auth') if 'POST' in request.method: _filter = request.POST.get('tag') if _filter: DB._filtertags = [TagNew(_filter.strip())] if _filter == 'None': DB._filtertags = [] nodeids = DB.listnodes() nodes = DB.getnodes(nodeids) nodesd = [''] * len(nodes) for idx, node in enumerate(nodes): ntags = [t.strip() for t in filter(None, node.tags)] nodesd[idx] = ('@'.join((node.username, node.url)), ', '.join(ntags)) if not TAGS: TAGS = list(set([''.join(node.tags).strip() for node in nodes])) TAGS.sort() TAGS.insert(0, 'None') print(len(TAGS)) output = template(tmplt, nodes=nodes, tags=TAGS) return output debug(True) run(reloader=True)