Compare commits

...

24 Commits

Author SHA1 Message Date
ManUtopiK 44a7feddd1 oups. 2022-12-07 19:19:50 +01:00
ManUtopiK b7d55cfb89 fix 'NoneType' and 'str' when DUNITER env not found 2022-12-07 19:12:37 +01:00
ManUtopiK b8c84c8126 Prevent apt install on other distro on setup 2022-12-07 19:11:37 +01:00
poka f99b6558a2 fix fucking down CS POD in .env.template 2022-11-23 01:41:04 +01:00
poka a882593ead update .env.template 2022-10-23 04:27:00 +02:00
poka 8690615335 fix GVA comment transaction sentence 2022-10-23 04:21:30 +02:00
poka 60bae39fba fix everything in universe and more 2022-10-23 04:05:48 +02:00
poka 0d7db5ba17 remove tata mother fucker 2022-10-23 03:44:37 +02:00
poka 8daee665e4 fix bad nonce on some message 2022-10-23 03:42:18 +02:00
poka 5a7b0c6901 fix null message content 2022-10-23 03:31:27 +02:00
poka ec7fcdfb45 Replace NODE and POD envvar with DUNITER and ESNODE, like g1stats 2022-03-29 00:27:00 +02:00
poka 9117def4b9 Change cesium pods and duniter node ofr good one; Fix MY_PATH for symlink; Add jaklis to env in setup.sh 2021-12-08 11:12:51 +01:00
poka efed7354df listWallets: Show balance in G1, not cents 2021-10-18 01:31:28 +02:00
poka db39e5c77d Mise à jour de 'README.md' 2021-10-09 12:51:26 +02:00
poka b291ddaef5 test git 2021-10-07 10:42:01 +02:00
poka 9270fb7ba2 Add username for non mbr 2021-08-28 06:56:29 +02:00
poka 53cbdfe982 Add username in mbr brut list 2021-08-28 03:11:11 +02:00
poka e8aa6723ee Improve listWallets options and algo 2021-08-28 02:47:20 +02:00
poka 314dc74404 fix cursor 2021-08-27 23:08:38 +02:00
poka 7bfa733fc5 fix typo 2021-08-27 23:02:08 +02:00
poka 43e5836eef fix listWallets with no dunikey 2021-08-27 22:59:16 +02:00
poka 116b362ea9 Add listWallet command 2021-08-27 05:02:16 +02:00
poka a6f26331d7 Merge pull request 'default offer category = CD/DVD' (#17) from qo-op/jaklis:master into master
Reviewed-on: axiom-team/jaklis#17
2021-07-02 01:14:20 +02:00
qo-op 30e206d61d default offer category = CD/DVD 2021-07-02 00:08:35 +02:00
10 changed files with 310 additions and 31 deletions

View File

@ -2,9 +2,13 @@
DUNIKEY=
# Noeud Duniter
NODE=https://g1.librelois.fr/gva
DUNITER="https://g1.librelois.fr"
#DUNITER="http://g1.duniter.org"
# Adresse du pod Cesium ou Gchange à utiliser
POD=https://g1.data.le-sou.org
#POD=https://g1.data.duniter.fr
#POD=https://data.gchange.fr
ESNODE="https://g1.data.e-is.pro"
#ESNODE="https://g1.data.presles.fr"
#ESNODE="https://g1.data.adn.life"
#ESNODE=https://g1.data.le-sou.org
#ESNODE=https://g1.data.duniter.fr
#ESNODE=https://data.gchange.fr

1
.gitignore vendored
View File

@ -3,3 +3,4 @@ __pycache__
*.dunikey
not4U
.vscode/settings.json

View File

@ -6,9 +6,9 @@ from shutil import copyfile
from dotenv import load_dotenv
from duniterpy.key import SigningKey
__version__ = "0.0.4"
__version__ = "0.0.5"
MY_PATH = os.path.realpath(os.path.dirname(sys.argv[0])) + '/'
MY_PATH = os.path.realpath(sys.argv[0]).replace('jaklis.py','')
# Get variables environment
if not os.path.isfile(MY_PATH + '.env'):
@ -17,13 +17,16 @@ dotenv_path = join(dirname(__file__),MY_PATH + '.env')
load_dotenv(dotenv_path)
# Set global values (default parameters) , regarding variables environments
node = os.getenv('NODE')
if not node:
node="https://g1.librelois.fr/gva"
duniter = os.getenv('DUNITER')
pod = os.getenv('POD')
if not duniter:
node = "https://g1.librelois.fr/gva"
else:
node = os.getenv('DUNITER') + '/gva'
pod = os.getenv('ESNODE')
if not pod:
pod="https://g1.data.le-sou.org"
pod="https://g1.data.e-is.pro"
destPubkey = False
@ -38,6 +41,7 @@ read_cmd = subparsers.add_parser('read', help="Lecture des messages")
send_cmd = subparsers.add_parser('send', help="Envoi d'un message")
delete_cmd = subparsers.add_parser('delete', help="Supression d'un message")
getProfile_cmd = subparsers.add_parser('get', help="Voir un profile Cesium+")
getPage_cmd = subparsers.add_parser('page', help="Voir une page Cesium+")
setProfile_cmd = subparsers.add_parser('set', help="Configurer son profile Cesium+")
eraseProfile_cmd = subparsers.add_parser('erase', help="Effacer son profile Cesium+")
stars_cmd = subparsers.add_parser('stars', help="Voir les étoiles d'un profile / Noter un profile (option -s NOTE)")
@ -51,6 +55,7 @@ balance_cmd = subparsers.add_parser('balance', help="Voir le solde d'un compte
id_cmd = subparsers.add_parser('id', help="Voir l'identité d'une clé publique/username")
id_balance_cmd = subparsers.add_parser('idBalance', help="Voir l'identité d'une clé publique/username et son solde")
currentUd = subparsers.add_parser('currentUd', help="Affiche la montant actuel du dividende Universel")
listWallets = subparsers.add_parser('listWallets', help="Liste de toutes les portefeuilles G1")
# Messages management
read_cmd.add_argument('-n', '--number',type=int, default=3, help="Affiche les NUMBER derniers messages")
@ -78,6 +83,9 @@ setProfile_cmd.add_argument('-A', '--avatar', help="Chemin vers mon avatar en PN
getProfile_cmd.add_argument('-p', '--profile', help="Nom du profile")
getProfile_cmd.add_argument('-a', '--avatar', action='store_true', help="Récupérer également l'avatar au format raw base64")
getPage_cmd.add_argument('-p', '--page', help="Nom de la page")
getPage_cmd.add_argument('-a', '--avatar', action='store_true', help="Récupérer également l'avatar au format raw base64")
# Likes management
stars_cmd.add_argument('-p', '--profile', help="Profile cible")
stars_cmd.add_argument('-n', '--number', type=int, help="Nombre d'étoile")
@ -97,7 +105,7 @@ deleteoffer_cmd.add_argument('-i', '--id', help="Annonce cible à supprimer")
# GVA usage
pay_cmd.add_argument('-p', '--pubkey', help="Destinataire du paiement")
pay_cmd.add_argument('-a', '--amount', type=float, help="Montant de la transaction")
pay_cmd.add_argument('-c', '--comment', default="", help="Commentaire de la transaction")
pay_cmd.add_argument('-c', '--comment', default="", help="Commentaire de la transaction", nargs='*')
pay_cmd.add_argument('-m', '--mempool', action='store_true', help="Utilise les sources en Mempool")
pay_cmd.add_argument('-v', '--verbose', action='store_true', help="Affiche le résultat JSON de la transaction")
@ -112,7 +120,12 @@ id_cmd.add_argument('-p', '--pubkey', help="Clé publique du compte visé")
id_cmd.add_argument('-u', '--username', help="Username du compte visé")
id_balance_cmd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
currentUd.add_argument('-p', '--pubkey', help="Pubkey du compte visé")
listWallets.add_argument('-b', '--balance', action='store_true', help="Affiche les soldes")
listWallets.add_argument('--mbr', action='store_true', help="Affiche la liste de pubkey membres brut")
listWallets.add_argument('--non_mbr', action='store_true', help="Affiche la liste de pubkey des identités non membres brut")
listWallets.add_argument('--larf', action='store_true', help="Affiche la liste des pubkey non membres brut")
listWallets.add_argument('--brut', action='store_true', help="Affiche la liste de toutes les pubkey brut")
listWallets.add_argument('-p', '--pubkey', help="useless but needed")
args = parser.parse_args()
cmd = args.cmd
@ -133,7 +146,8 @@ def createTmpDunikey():
nonce = ''.join(nonce)
keyPath = "/tmp/secret.dunikey-" + nonce
key = SigningKey.from_credentials(getpass.getpass("Identifiant: "), getpass.getpass("Mot de passe: "), None)
# key = SigningKey.from_credentials(getpass.getpass("Identifiant: "), getpass.getpass("Mot de passe: "), None)
key = SigningKey.from_credentials("sgse547yhd54xv6541srdh", "sfdgwdrhpkxdawsbszqpof1sdg65xc", None)
key.save_pubsec_file(keyPath)
return keyPath
@ -148,7 +162,8 @@ try:
except:
profile = False
if cmd in ('history','balance','get','id','idBalance') and (pubkey or profile):
# print(pubkey, profile)
if cmd in ('history','balance','get','page','id','idBalance','listWallets') and (pubkey or profile):
noNeedDunikey = True
keyPath = False
try:
@ -176,7 +191,7 @@ else:
# Construct CesiumPlus object
if cmd in ("read","send","delete","set","get","erase","stars","unstars","getoffer","setoffer","deleteoffer"):
if cmd in ("read","send","delete","set","get","page","erase","stars","unstars","getoffer","setoffer","deleteoffer"):
from lib.cesium import CesiumPlus
if args.node:
@ -213,6 +228,8 @@ if cmd in ("read","send","delete","set","get","erase","stars","unstars","getoffe
cesium.set(args.name, args.description, args.ville, args.adresse, args.position, args.site, args.avatar)
elif cmd == "get":
cesium.get(args.profile, args.avatar)
elif cmd == "page":
cesium.getPage(args.page, args.avatar)
elif cmd == "erase":
cesium.erase()
@ -234,7 +251,7 @@ if cmd in ("read","send","delete","set","get","erase","stars","unstars","getoffe
cesium.deleteOffer(args.id)
# Construct GVA object
elif cmd in ("pay","history","balance","id","idBalance","currentUd"):
elif cmd in ("pay","history","balance","id","idBalance","currentUd","listWallets"):
from lib.gva import GvaApi
if args.node:
@ -257,6 +274,8 @@ elif cmd in ("pay","history","balance","id","idBalance","currentUd"):
gva.idBalance(args.pubkey)
elif cmd == "currentUd":
gva.currentUd()
elif cmd == "listWallets":
gva.listWallets(args.brut, args.mbr, args.non_mbr, args.larf)
if keyPath:

View File

@ -1,5 +1,6 @@
import re, string, random, base64
from lib.cesiumCommon import CesiumCommon, PUBKEY_REGEX
from lib.getPages import Pages
from lib.messaging import ReadFromCesium, SendToCesium, DeleteFromCesium
from lib.profiles import Profiles
from lib.stars import ReadLikes, SendLikes, UnLikes
@ -62,6 +63,21 @@ class CesiumPlus(CesiumCommon):
result = getProfile.parseJSON(resultJSON)
print(result)
def getPage(self, page=None, avatar=None):
getPage = Pages(self.dunikey, self.pod, self.noNeedDunikey)
if not page:
page = self.pubkey
if not re.match(PUBKEY_REGEX, page) or len(page) > 45:
scope = 'title'
else:
scope = '_id'
document = getPage.configDocGet(page, scope, avatar)
resultJSON = getPage.sendDocument(document, 'get')
result = getPage.parseJSON(resultJSON)
print(result)
def erase(self):
eraseProfile = Profiles(self.dunikey, self.pod)

125
lib/getPages.py Normal file
View File

@ -0,0 +1,125 @@
import sys, re, json, requests, base64
from time import time
from lib.cesiumCommon import CesiumCommon, PUBKEY_REGEX
class Pages(CesiumCommon):
# Configure JSON document SET to send
def configDocSet(self, name, description, city, address, pos, socials, avatar):
timeSent = int(time())
data = {}
if name: data['title'] = name
if description: data['description'] = description
if address: data['address'] = address
if city: data['city'] = city
if pos:
geoPoint = {}
geoPoint['lat'] = pos[0]
geoPoint['lon'] = pos[1]
data['geoPoint'] = geoPoint
if socials:
data['socials'] = []
data['socials'].append({})
data['socials'][0]['type'] = "web"
data['socials'][0]['url'] = socials
if avatar:
avatar = open(avatar, 'rb').read()
avatar = base64.b64encode(avatar).decode()
data['avatar'] = {}
data['avatar']['_content'] = avatar
data['avatar']['_content_type'] = "image/png"
data['time'] = timeSent
data['issuer'] = self.pubkey
data['version'] = 2
data['tags'] = []
document = json.dumps(data)
return self.signDoc(document)
# Configure JSON document GET to send
def configDocGet(self, profile, scope='title', getAvatar=None):
if getAvatar:
avatar = "avatar"
else:
avatar = "avatar._content_type"
data = {
"query": {
"bool": {
"should":[
{
"match":{
scope:{
"query": profile,"boost":2
}
}
},{
"prefix": {scope: profile}
}
]
}
},"highlight": {
"fields": {
"title":{},
"tags":{}
}
},"from":0,
"size":100,
"_source":["title", avatar,"description","city","address","socials.url","creationTime","membersCount","type","geoPoint"],
"indices_boost":{"user":100,"page":1,"group":0.01
}
}
document = json.dumps(data)
return document
# Configure JSON document SET to send
def configDocErase(self):
timeSent = int(time())
data = {}
data['time'] = timeSent
data['id'] = self.pubkey
data['issuer'] = self.pubkey
data['version'] = 2
data['index'] = "user"
data['type'] = "profile"
document = json.dumps(data)
return self.signDoc(document)
def sendDocument(self, document, type):
headers = {
'Content-type': 'application/json',
}
# Send JSON document and get JSON result
if type == 'set':
reqQuery = '{0}/user/profile?pubkey={1}/_update?pubkey={1}'.format(self.pod, self.pubkey)
elif type == 'get':
reqQuery = '{0}/user,page,group/profile,record/_search'.format(self.pod)
elif type == 'erase':
reqQuery = '{0}/history/delete'.format(self.pod)
result = requests.post(reqQuery, headers=headers, data=document)
if result.status_code == 200:
# print(result.text)
return result.text
else:
sys.stderr.write("Echec de l'envoi du document...\n" + result.text + '\n')
def parseJSON(self, doc):
doc = json.loads(doc)['hits']['hits']
if doc:
pubkey = { "pubkey": doc[0]['_id'] }
rest = doc[0]['_source']
final = {**pubkey, **rest}
return json.dumps(final, indent=2)
else:
return 'Profile vide'

View File

@ -1,4 +1,5 @@
from lib.currentUd import currentUd
from lib.gvaWallets import ListWallets
import sys, re
from lib.natools import get_privkey
from lib.gvaPay import Transaction, PUBKEY_REGEX
@ -38,6 +39,7 @@ class GvaApi():
#################### Payments ####################
def pay(self, amount, comment, mempool, verbose):
comment = " ".join(comment)
gva = Transaction(self.dunikey, self.node, self.destPubkey, amount, comment, mempool, verbose)
gva.genDoc()
gva.checkTXDoc()
@ -73,4 +75,10 @@ class GvaApi():
def currentUd(self):
gva = currentUd(self.node)
result = gva.sendDoc()
print(result)
def listWallets(self, brut, brutMbr, brutNonMbr, brutLarf):
gva = ListWallets(self.node, brut, brutMbr, brutNonMbr, brutLarf)
result = gva.sendDoc()
print(result)

77
lib/gvaWallets.py Normal file
View File

@ -0,0 +1,77 @@
#!/usr/bin/env python3
import sys, re, os.path, json, ast
from termcolor import colored
from lib.natools import fmt, sign, get_privkey
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
PUBKEY_REGEX = "(?![OIl])[1-9A-Za-z]{42,45}"
class ListWallets:
def __init__(self, node, brut, mbr, nonMbr, larf):
self.mbr = mbr
self.larf = larf
self.nonMbr = nonMbr
self.brut = brut
# Define Duniter GVA node
transport = AIOHTTPTransport(url=node)
self.client = Client(transport=transport, fetch_schema_from_transport=True)
def sendDoc(self):
# Build wallets generation document
queryBuild = gql(
"""
{
wallets(pagination: { cursor: null, ord: ASC, pageSize: 0 }) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
script
balance {
amount
base
}
idty {
isMember
username
}
}
}
}
}
""")
# Send wallets document
try:
queryResult = self.client.execute(queryBuild)
except Exception as e:
sys.stderr.write("Echec de récupération de la liste:\n" + str(e) + "\n")
sys.exit(1)
jsonBrut = queryResult['wallets']['edges']
walletList = []
for i, trans in enumerate(jsonBrut):
dataWork = trans['node']
if (self.mbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == False)): continue
if (self.nonMbr and (dataWork['idty'] == None or dataWork['idty']['isMember'] == True)): continue
if (self.larf and (dataWork['idty'] != None)): continue
walletList.append({'pubkey': dataWork['script'],'balance': dataWork['balance']['amount']/100,'id': dataWork['idty']})
if (self.brut):
names = []
for dataWork in walletList:
if (self.mbr or self.nonMbr):
names.append(dataWork['pubkey'] + ' ' + dataWork['id']['username'])
else:
names.append(dataWork['pubkey'])
return "\n".join(names)
else:
return json.dumps(walletList, indent=2)

View File

@ -46,6 +46,7 @@ class ReadFromCesium(CesiumCommon):
# Parse JSON result and display messages
def readMessages(self, msgJSON, nbrMsg, outbox):
def decrypt(msg):
if msg is None: return ''
msg64 = base64.b64decode(msg)
return box_decrypt(msg64, get_privkey(self.dunikey, "pubsec"), self.issuer, nonce).decode()
@ -67,7 +68,10 @@ class ReadFromCesium(CesiumCommon):
msgSrc = hits["_source"]
self.issuer = msgSrc["issuer"]
nonce = msgSrc["nonce"]
nonce = base58.b58decode(nonce)
try:
nonce = base58.b58decode(nonce)
except:
nonce = base58.b58decode('5aZdSqKGHBqm2uMPwN6XnfiiJKRieb1Hh')
self.dateS = msgSrc["time"]
date = datetime.fromtimestamp(self.dateS).strftime(", le %d/%m/%Y à %H:%M ")
if outbox:
@ -94,6 +98,7 @@ class ReadFromCesium(CesiumCommon):
# Parse JSON result and display messages
def jsonMessages(self, msgJSON, nbrMsg, outbox):
def decrypt(msg):
if msg is None: return ''
msg64 = base64.b64decode(msg)
return box_decrypt(msg64, get_privkey(self.dunikey, "pubsec"), self.issuer, nonce).decode()
@ -113,7 +118,10 @@ class ReadFromCesium(CesiumCommon):
msgSrc = hits["_source"]
self.issuer = msgSrc["issuer"]
nonce = msgSrc["nonce"]
nonce = base58.b58decode(nonce)
try:
nonce = base58.b58decode(nonce)
except:
nonce = base58.b58decode('5aZdSqKGHBqm2uMPwN6XnfiiJKRieb1Hh')
self.date = msgSrc["time"]
if outbox:
@ -123,11 +131,18 @@ class ReadFromCesium(CesiumCommon):
try:
self.title = decrypt(msgSrc["title"])
except Exception as e:
self.title = "jaklis can't read that mother fucker"
# sys.stderr.write(colored(str('Error decrypt message title: ' + str(e)), 'red') + '\n')
# pp_json(hits)
try:
self.content = decrypt(msgSrc["content"])
except Exception as e:
sys.stderr.write(colored(str(e), 'red') + '\n')
pp_json(hits)
continue
self.content = "jaklis can't read that mother fucker"
# sys.stderr.write(colored(str('Error decrypt message content: ' + str(e)), 'red') + '\n')
# pp_json(hits)
data.append(i)
data[i] = {}
@ -136,6 +151,7 @@ class ReadFromCesium(CesiumCommon):
data[i]['pubkey'] = pubkey
data[i]['title'] = self.title
data[i]['content'] = self.content
# print('toto')
data = json.dumps(data, indent=2)
return data

View File

@ -26,7 +26,7 @@ class Offers(CesiumCommon):
data['thumbnail']['_content_type'] = "image/png"
# if category: data['category'] = category
# else:
data['category'] = {"parent":"cat90","localizedNames":{"en":"Fruits & Vegetables","es-ES":"Frutas y Vegetales","fr-FR":"Fruits & Légumes"},"name":"Fruits & Légumes","id":"cat92"}
data['category'] = {"parent":"cat24","localizedNames":{"en":"DVD / Films","es-ES":"DVDs / Cine","fr-FR":"DVD / Films"},"name":"DVD / Films","id":"cat25"}
if price: data['price'] = float(price) * 100
data['type'] = 'offer'
data['time'] = timeSent

View File

@ -1,12 +1,25 @@
#!/bin/bash
for i in gcc python3-pip python3-setuptools libpq-dev python3-dev python3-wheel; do
if [ $(dpkg-query -W -f='${Status}' $i 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
[[ ! $j ]] && sudo apt update
sudo apt install -y $i
j=1
fi
done
hasError=0
pip3 install -r requirements.txt
if [ -f "/etc/arch-release" ]; then
echo '! jaklis needs gcc python3-pip python3-setuptools libpq-dev python3-dev python3-wheel'
elif [ -f "/etc/lsb-release" ]; then # ubuntu
for i in gcc python3-pip python3-setuptools libpq-dev python3-dev python3-wheel; do
if [ $(dpkg-query -W -f='${Status}' $i 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
[[ ! $j ]] && sudo apt update
sudo apt install -y $i
j=1
fi
done
fi
pip3 install -r requirements.txt || hasError=1
chmod u+x jaklis.py
ln -sf $(realpath jaklis.py) /usr/local/bin/jaklis || hasError=1
if [[ hasError -eq 0 ]]; then
echo "Setup done. You can use 'jaklis' command, try it."
else
echo "An error has occurred"
fi