From 74db4d2d9ddf815427c5177d85cf90b443e76d72 Mon Sep 17 00:00:00 2001 From: Kevin Froman Date: Mon, 18 Jan 2021 04:35:28 +0000 Subject: [PATCH] added username plugin and api endpoint to get all contacts as opposed to just friends --- src/httpapi/friendsapi/__init__.py | 9 ++++ src/onionrusers/onionrusers.py | 4 +- static-data/default-plugins/pms/info.json | 2 +- static-data/default-plugins/pms/main.py | 2 +- .../default-plugins/pms/web/index.html | 2 +- static-data/default-plugins/pms/web/mail.js | 2 +- .../default-plugins/usernames/info.json | 5 +++ static-data/default-plugins/usernames/main.py | 42 +++++++++++++++++++ .../default-plugins/usernames/usernames.dat | 1 + 9 files changed, 63 insertions(+), 6 deletions(-) create mode 100755 static-data/default-plugins/usernames/info.json create mode 100755 static-data/default-plugins/usernames/main.py create mode 100644 static-data/default-plugins/usernames/usernames.dat diff --git a/src/httpapi/friendsapi/__init__.py b/src/httpapi/friendsapi/__init__.py index 329ea7f4..03a20153 100755 --- a/src/httpapi/friendsapi/__init__.py +++ b/src/httpapi/friendsapi/__init__.py @@ -24,6 +24,15 @@ from coredb import keydb friends = Blueprint('friends', __name__) +@friends.route('/friends/listall') +def list_all(): + pubkey_list = {} + friend_list = contactmanager.ContactManager.list_friends(0) + for friend in friend_list: + pubkey_list[friend.publicKey] = {'name': friend.get_info('name')} + return json.dumps(pubkey_list) + + @friends.route('/friends/list') def list_friends(): pubkey_list = {} diff --git a/src/onionrusers/onionrusers.py b/src/onionrusers/onionrusers.py index 21263772..70cd8299 100755 --- a/src/onionrusers/onionrusers.py +++ b/src/onionrusers/onionrusers.py @@ -252,8 +252,8 @@ class OnionrUser: return True @classmethod - def list_friends(cls): + def list_friends(cls, trust_level=1): friendList = [] - for x in keydb.listkeys.list_peers(trust=1): + for x in keydb.listkeys.list_peers(trust=trust_level): friendList.append(cls(x)) return list(friendList) diff --git a/static-data/default-plugins/pms/info.json b/static-data/default-plugins/pms/info.json index 72ce2b39..83f1c5fb 100755 --- a/static-data/default-plugins/pms/info.json +++ b/static-data/default-plugins/pms/info.json @@ -1,5 +1,5 @@ { "name" : "pms", - "version" : "0.1.2", + "version" : "0.1.3", "author" : "onionr" } diff --git a/static-data/default-plugins/pms/main.py b/static-data/default-plugins/pms/main.py index 4d2219f2..6fb08a8c 100755 --- a/static-data/default-plugins/pms/main.py +++ b/static-data/default-plugins/pms/main.py @@ -31,7 +31,7 @@ import notifier locale.setlocale(locale.LC_ALL, '') plugin_name = 'pms' -PLUGIN_VERSION = '0.1.2' +PLUGIN_VERSION = '0.1.3' sys.path.insert(0, os.path.dirname(os.path.realpath(__file__))) import sentboxdb, mailapi, loadinbox # import after path insert diff --git a/static-data/default-plugins/pms/web/index.html b/static-data/default-plugins/pms/web/index.html index c838d30b..f4603633 100755 --- a/static-data/default-plugins/pms/web/index.html +++ b/static-data/default-plugins/pms/web/index.html @@ -240,7 +240,7 @@
- +
diff --git a/static-data/default-plugins/pms/web/mail.js b/static-data/default-plugins/pms/web/mail.js index 8153c817..d781ba49 100755 --- a/static-data/default-plugins/pms/web/mail.js +++ b/static-data/default-plugins/pms/web/mail.js @@ -415,7 +415,7 @@ for (var i = 0; i < document.getElementsByClassName('refresh').length; i++){ document.getElementsByClassName('refresh')[i].style.float = 'right' } -fetch('/friends/list', { +fetch('/friends/listall', { headers: { "token": webpass }}) diff --git a/static-data/default-plugins/usernames/info.json b/static-data/default-plugins/usernames/info.json new file mode 100755 index 00000000..981f422c --- /dev/null +++ b/static-data/default-plugins/usernames/info.json @@ -0,0 +1,5 @@ +{ + "name" : "usernames", + "version" : "0.0.0", + "author" : "onionr" +} diff --git a/static-data/default-plugins/usernames/main.py b/static-data/default-plugins/usernames/main.py new file mode 100755 index 00000000..9c88f6ef --- /dev/null +++ b/static-data/default-plugins/usernames/main.py @@ -0,0 +1,42 @@ +""" +Onionr - Private P2P Communication. + +Preset Onionr usernames +""" +import locale +locale.setlocale(locale.LC_ALL, '') + +from utils import identifyhome +from onionrusers import contactmanager +""" +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program 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 this program. If not, see . +""" + +plugin_name = 'usernames' + + +def on_onboard(api, data=None): + username_file = identifyhome.identify_home() + f'plugins/{plugin_name}/usernames.dat' + with open(username_file, 'r') as usernames: + username_and_keys = usernames.readlines() + + for entry in username_and_keys: + username, key = entry.split(',') + username = username.strip() + key = key.strip() + user = contactmanager.ContactManager(key, saveUser=True) + user.set_info('name', username) + + + diff --git a/static-data/default-plugins/usernames/usernames.dat b/static-data/default-plugins/usernames/usernames.dat new file mode 100644 index 00000000..e591de2b --- /dev/null +++ b/static-data/default-plugins/usernames/usernames.dat @@ -0,0 +1 @@ +Kevin Froman,GM3E4VCUNLF5F7Y64STD2HEURG45U3NYPLBZBT3Z6YWOALJHZPPQ