Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #45 from herlo/master

Update setup.py and other awesome stuff
  • Loading branch information...
commit 3ab5ad57cf3750a1d7bc9a37a5d86516f8036a3a 2 parents 5acad9e + 8bfe18d
@atoponce authored
Showing with 163 additions and 44 deletions.
  1. +4 −0 .gitignore
  2. +26 −25 INSTALL.md
  3. +2 −0  MANIFEST.in
  4. +1 −0  README
  5. +21 −0 d-note.ini
  6. 0  { → dnote}/__init__.py
  7. 0  dnote/data/.empty
  8. +37 −4 { → dnote}/note.py
  9. 0  { → dnote}/static/css/main.css
  10. 0  { → dnote}/static/img/LICENSE.md
  11. 0  { → dnote}/static/img/README.md
  12. 0  { → dnote}/static/img/dnote-explanation.xml
  13. 0  { → dnote}/static/js/fingerprint-min.js
  14. 0  { → dnote}/static/js/hashcash.js
  15. 0  { → dnote}/static/js/isaac.js
  16. 0  { → dnote}/static/js/keygen.js
  17. 0  { → dnote}/static/js/main.js
  18. 0  { → dnote}/static/js/qrcode-min.js
  19. 0  { → dnote}/static/js/sha1-min.js
  20. 0  { → dnote}/templates/404.html
  21. 0  { → dnote}/templates/about.html
  22. 0  { → dnote}/templates/base.html
  23. 0  { → dnote}/templates/destroyed.html
  24. 0  { → dnote}/templates/faq.html
  25. 0  { → dnote}/templates/index.html
  26. 0  { → dnote}/templates/key.html
  27. 0  { → dnote}/templates/keyerror.html
  28. 0  { → dnote}/templates/note.html
  29. 0  { → dnote}/templates/post.html
  30. 0  { → dnote}/templates/security.html
  31. +2 −2 { → dnote}/utils.py
  32. +48 −0 scripts/generate_dnote_hashes
  33. +22 −13 setup.py
View
4 .gitignore
@@ -1,7 +1,11 @@
data/*
dconfig.py
+dist/
+*.egg-info/
+build
uwsgi.ini
*.pyc
*.swp
.*.swp
*~
+MANIFEST
View
51 INSTALL.md
@@ -10,24 +10,26 @@ install `python-flask` and `python-crypto`:
The correct `python-crypto` package should be coming from
https://www.dlitz.net/software/pycrypto/
-Now make a directory under your web root to clone the Git repository:
-
- # mkdir /var/www/
- # git clone https://github.com/atoponce/d-note.git /var/www/dnote
- # mkdir /var/www/dnote/data/
- # chown root.www-data /var/www/dnote/data
- # chmod g+w,o= /var/www/dnote/data
-
Configuration
-------------
Run the following from a terminal to setup the configuration file and data
storage directory before launching the application:
- $ python setup.py
+ $ python setup.py install
+
+After the application is installed, the dconfig.py needs to be generated.
+
+Edit the dnote.ini in this directory and update the 'config_path' value in
+the [default] section. It is recommended that this value be either either
+/etc/dnote or ~/.dnote. Once edited, copy the dnote.ini file to the directory
+you created.
+
+Once copied, run the following:
+
+ $ generate_dnote_hashes
-This will create a `dconfig.py` which should have salts with random hexadecimal
-strings as their values, and should create a `/data` directory to store the
-notes.
+This will create a `dconfig.py` in the proper directory. This file should
+have salts with random hexadecimal strings as their values.
Apache Setup
------------
@@ -46,9 +48,8 @@ Add the following contents to that file:
import sys
import logging
logging.basicConfig(stream=sys.stderr)
- sys.path.insert(0,"/var/www/dnote/")
from dnote import DNOTE as application
-
+
Now configure Apache to server the application. Create
`/etc/apache2/site-available/` with the following contents. It's important
that you serve the application over SSL. See additional Apache documentation as
@@ -89,16 +90,16 @@ Nginx Setup
Install uwsgi:
# apt-get install uwsgi uwsgi-core uwsgi-extra uwsgi-plugin-python
-
+
Create a uwsgi.ini file in the directory with the application:
# touch /var/www/dnote/uwsgi.ini
-
+
And add the following to that file (you can tweak these settings as required):
[uwsgi]
- socket = /tmp/dnote.sock
- chdir = /var/www/dnote
+ socket = 127.0.0.1:8081
+ chdir = /python/path/site-packages/dnote-1.0.1-py2.7.egg/dnote
plugin = python
module = __init__:dnote
processes = 4
@@ -107,11 +108,11 @@ And add the following to that file (you can tweak these settings as required):
uid = www-data
gid = www-data
logto = /var/log/dnote.log
-
-You can now start the dnote application by running:
+
+You can now start the dnote application by running:
# /usr/bin/uwsgi -c /var/www/dnote/uwsgi.ini
-
+
This will start uwsgi in the foreground. To start it as a
daemon:
@@ -119,7 +120,7 @@ daemon:
You may want to add this to an init or upstart script, see:
http://uwsgi-docs.readthedocs.org/en/latest/Management.html
-
+
Now lets configure nginx. A common example would be if you wanted it
to be avaliable under http://yoursite.tld/dnote. To acheive this, add
the following to your sites config (again, you can tweak thsi as needed):
@@ -130,7 +131,7 @@ the following to your sites config (again, you can tweak thsi as needed):
include uwsgi_params;
uwsgi_param SCRIPT_NAME /dnote;
uwsgi_modifier1 30;
- uwsgi_pass unix:/tmp/dnote.sock;
+ uwsgi_pass 127.0.0.1:8081;
}
And tada, restart the Nginx server and you should have a working dnote setup.
@@ -147,8 +148,8 @@ dnote.wsgi file (as in the Apache directions above) and using uwsgi-file
in the uwsgi.ini file instead of module, like this:
[uwsgi]
- socket = /tmp/dnote.sock
- chdir = /var/www/dnote
+ socket = 127.0.0.1:8081
+ chdir = /python/path/site-packages/dnote-1.0.1-py2.7.egg/dnote
plugin = python
wsgi-file = /var/www/dnote.wsgi
processes = 4
View
2  MANIFEST.in
@@ -0,0 +1,2 @@
+recursive-include dnote/templates *
+recursive-include dnote/static *
View
1  README
View
21 d-note.ini
@@ -0,0 +1,21 @@
+# d-note configuration file
+# structured in INI style
+# use %% to allow code interpolation
+# use % to use config interpolation
+
+[DEFAULT]
+app = dnote
+
+# search for config files here
+config_path = ~/.dnote
+data_dir = ~/.dnote/data
+
+# in production, use these values
+#config_path = /etc/dnote
+#data_dir = /var/lib/dnote/data
+
+[dnote]
+# intentionally left blank.
+# Used to interpolate defaults above when they don't get used in another category below
+
+
View
0  __init__.py → dnote/__init__.py
File renamed without changes
View
0  dnote/data/.empty
No changes.
View
41 note.py → dnote/note.py
@@ -1,19 +1,52 @@
"""Encrypts and decrypts notes."""
import base64
import os
+import sys
import zlib
from Crypto.Cipher import AES
from Crypto.Hash import HMAC, SHA512
from Crypto.Protocol import KDF
from Crypto.Util import Counter
+import ConfigParser
+
+# copy the config file from conf dir to either /etc/dnote or ~/.dnote,
+# then run this script.
+
+config = ConfigParser.SafeConfigParser()
+
+for path in ['/etc/dnote', '~/.dnote']:
+ expanded_path = "{0}/{1}".format(os.path.expanduser(path), 'd-note.ini')
+ if os.path.exists(expanded_path):
+ try:
+ f = open(expanded_path)
+ config.readfp(f)
+ f.close()
+ except ConfigParser.InterpolationSyntaxError as e:
+ raise EOFError("Unable to parse configuration file properly: {0}".format(e))
+
+cfgs = {}
+
+for section in config.sections():
+ if not cfgs.has_key(section):
+ cfgs[section] = {}
+
+ for k, v in config.items(section):
+ cfgs[section][k] = v
+
+dconfig_path = os.path.expanduser(cfgs['dnote']['config_path'])
+dconfig = dconfig_path + "/dconfig.py"
+
+# add dconfig.py to the sys.path
+sys.path.append(dconfig_path)
+
try:
import dconfig
except ImportError:
- print "You need to run 'python setup.py' as part of the installation."
+ print "You need to run 'generate_dnote_hashes' as part of the installation."
os.sys.exit(1)
-DATA_DIR = os.path.dirname(os.path.realpath(__file__)) + "/data"
+data_dir = os.path.expanduser(cfgs['dnote']['data_dir'])
class Note(object):
"""Note Model"""
@@ -41,9 +74,9 @@ def exists(self):
def path(self, kind=None):
"""Return the file path to the note file"""
if kind is None:
- return '%s/%s' % (DATA_DIR, self.fname)
+ return '%s/%s' % (data_dir, self.fname)
else:
- return '%s/%s.%s' % (DATA_DIR, self.fname, kind)
+ return '%s/%s.%s' % (data_dir, self.fname, kind)
def create_url(self):
"""Create a cryptographic nonce for our URL, and use PBKDF2 with our
View
0  static/css/main.css → dnote/static/css/main.css
File renamed without changes
View
0  static/img/LICENSE.md → dnote/static/img/LICENSE.md
File renamed without changes
View
0  static/img/README.md → dnote/static/img/README.md
File renamed without changes
View
0  static/img/dnote-explanation.xml → dnote/static/img/dnote-explanation.xml
File renamed without changes
View
0  static/js/fingerprint-min.js → dnote/static/js/fingerprint-min.js
File renamed without changes
View
0  static/js/hashcash.js → dnote/static/js/hashcash.js
File renamed without changes
View
0  static/js/isaac.js → dnote/static/js/isaac.js
File renamed without changes
View
0  static/js/keygen.js → dnote/static/js/keygen.js
File renamed without changes
View
0  static/js/main.js → dnote/static/js/main.js
File renamed without changes
View
0  static/js/qrcode-min.js → dnote/static/js/qrcode-min.js
File renamed without changes
View
0  static/js/sha1-min.js → dnote/static/js/sha1-min.js
File renamed without changes
View
0  templates/404.html → dnote/templates/404.html
File renamed without changes
View
0  templates/about.html → dnote/templates/about.html
File renamed without changes
View
0  templates/base.html → dnote/templates/base.html
File renamed without changes
View
0  templates/destroyed.html → dnote/templates/destroyed.html
File renamed without changes
View
0  templates/faq.html → dnote/templates/faq.html
File renamed without changes
View
0  templates/index.html → dnote/templates/index.html
File renamed without changes
View
0  templates/key.html → dnote/templates/key.html
File renamed without changes
View
0  templates/keyerror.html → dnote/templates/keyerror.html
File renamed without changes
View
0  templates/note.html → dnote/templates/note.html
File renamed without changes
View
0  templates/post.html → dnote/templates/post.html
File renamed without changes
View
0  templates/security.html → dnote/templates/security.html
File renamed without changes
View
4 utils.py → dnote/utils.py
@@ -1,7 +1,7 @@
"""Utility functions for d-note."""
import random
from Crypto.Hash import SHA
-from note import DATA_DIR
+from note import data_dir
def duress_text():
"""Return 5 random sentences of the Zen of Python."""
@@ -27,7 +27,7 @@ def verify_hashcash(token):
token -- a proposed Hashcash token to validate."""
digest = SHA.new(token)
- with open('%s/hashcash.db' % DATA_DIR, 'a+') as database:
+ with open('%s/hashcash.db' % data_dir, 'a+') as database:
if digest.hexdigest()[:4] == '0000' and token not in database.read():
database.write(token+'\n')
return True
View
48 scripts/generate_dnote_hashes
@@ -0,0 +1,48 @@
+#!/usr/bin/env python
+
+import os
+import ConfigParser
+
+# copy the config file from conf dir to either /etc/dnote or ~/.dnote,
+# then run this script.
+
+config = ConfigParser.SafeConfigParser()
+
+for path in ['/etc/dnote', '~/.dnote']:
+ expanded_path = "{0}/{1}".format(os.path.expanduser(path), 'd-note.ini')
+ if os.path.exists(expanded_path):
+ try:
+ f = open(expanded_path)
+ config.readfp(f)
+ f.close()
+ except ConfigParser.InterpolationSyntaxError as e:
+ raise EOFError("Unable to parse configuration file properly: {0}".format(e))
+
+cfgs = {}
+
+for section in config.sections():
+ if not cfgs.has_key(section):
+ cfgs[section] = {}
+
+ for k, v in config.items(section):
+ cfgs[section][k] = v
+
+# make data_dir
+data_dir = os.path.expanduser(cfgs['dnote']['data_dir'])
+
+if not os.path.isdir(data_dir):
+ os.makedirs(data_dir, 0755)
+
+dconfig_path = os.path.expanduser(cfgs['dnote']['config_path'])
+dconfig = dconfig_path + "/dconfig.py"
+
+if not os.path.isdir(dconfig_path):
+ os.makedirs(dconfig_path, 0755)
+
+if not os.path.exists(dconfig):
+ with open(dconfig, 'w') as f:
+ f.write('aes_salt = "%s"\n' % os.urandom(16).encode('hex'))
+ f.write('mac_salt = "%s"\n' % os.urandom(16).encode('hex'))
+ f.write('nonce_salt = "%s"\n' % os.urandom(16).encode('hex'))
+ f.write('duress_salt = "%s"\n' % os.urandom(16).encode('hex'))
+ os.chmod(dconfig, 0440)
View
35 setup.py
@@ -1,17 +1,26 @@
-#!/usr/bin/python
+#!/usr/bin/env python
-import os
+from setuptools import setup, find_packages
-DCONFIG = os.path.dirname(os.path.realpath(__file__)) + "/dconfig.py"
-DATA_DIR = os.path.dirname(os.path.realpath(__file__)) + "/data"
+import os
+import glob
-if not os.path.exists(DCONFIG):
- with open(DCONFIG, 'w') as f:
- f.write('aes_salt = "%s"\n' % os.urandom(16).encode('hex'))
- f.write('mac_salt = "%s"\n' % os.urandom(16).encode('hex'))
- f.write('nonce_salt = "%s"\n' % os.urandom(16).encode('hex'))
- f.write('duress_salt = "%s"\n' % os.urandom(16).encode('hex'))
- os.chmod(DCONFIG, 0440)
+def read(fname):
+ return open(os.path.join(os.path.dirname(__file__), fname)).read()
-if not os.path.exists(DATA_DIR):
- os.makedirs(DATA_DIR)
+setup(
+ name='dnote',
+ version='1.0.1',
+ description='d-note is a self-destructing notes web application',
+ packages=find_packages(),
+ install_requires=['Flask'],
+ zip_safe=False,
+ include_package_data=True,
+ license='GPLv3',
+ author_email='aaron.toponce@gmail.com',
+ author='Aaron Toponce',
+ maintainer='Clint Savage',
+ url='http://github.com/atoponce/d-note',
+ long_description=read('README'),
+ scripts=['scripts/generate_dnote_hashes'],
+)
Please sign in to comment.
Something went wrong with that request. Please try again.