2018-01-02 08:43:29 +00:00
|
|
|
'''
|
|
|
|
Onionr - P2P Microblogging Platform & Social network
|
|
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
'''
|
2018-01-07 08:55:44 +00:00
|
|
|
import sqlite3, os, time, math, gnupg, base64, tarfile, getpass, simplecrypt
|
|
|
|
from Crypto.Cipher import AES
|
|
|
|
from Crypto import Random
|
|
|
|
|
|
|
|
|
2018-01-02 08:43:29 +00:00
|
|
|
class Core:
|
|
|
|
def __init__(self):
|
|
|
|
self.queueDB = 'data/queue.db'
|
2018-01-04 07:12:46 +00:00
|
|
|
#self.daemonQueue() # Call to create the DB if it doesn't exist
|
2018-01-02 08:43:29 +00:00
|
|
|
return
|
|
|
|
|
2018-01-05 09:16:21 +00:00
|
|
|
def generateMainPGP(self):
|
|
|
|
# Generate main pgp key
|
|
|
|
gpg = gnupg.GPG(gnupghome='data/pgp/')
|
2018-01-06 08:51:26 +00:00
|
|
|
input_data = gpg.gen_key_input(key_type="RSA", key_length=2048, name_real='anon', name_comment='Onionr key', name_email='anon@onionr')
|
|
|
|
key = gpg.gen_key(input_data)
|
|
|
|
return
|
|
|
|
|
|
|
|
def dataDirEncrypt(self):
|
2018-01-07 08:55:44 +00:00
|
|
|
simplecrypt.encrypt()
|
2018-01-05 09:16:21 +00:00
|
|
|
return
|
|
|
|
|
2018-01-02 08:43:29 +00:00
|
|
|
def daemonQueue(self):
|
2018-01-04 07:12:46 +00:00
|
|
|
# This function intended to be used by the client
|
2018-01-02 08:43:29 +00:00
|
|
|
# Queue to exchange data between "client" and server.
|
|
|
|
retData = False
|
|
|
|
if not os.path.exists(self.queueDB):
|
2018-01-04 07:12:46 +00:00
|
|
|
conn = sqlite3.connect(self.queueDB)
|
|
|
|
c = conn.cursor()
|
2018-01-02 08:43:29 +00:00
|
|
|
# Create table
|
|
|
|
c.execute('''CREATE TABLE commands
|
|
|
|
(id integer primary key autoincrement, command text, data text, date text)''')
|
|
|
|
conn.commit()
|
|
|
|
else:
|
2018-01-04 07:12:46 +00:00
|
|
|
conn = sqlite3.connect(self.queueDB)
|
|
|
|
c = conn.cursor()
|
|
|
|
for row in c.execute('SELECT command, data, date, min(ID) FROM commands group by id'):
|
|
|
|
retData = row
|
|
|
|
break
|
|
|
|
if retData != False:
|
|
|
|
c.execute('delete from commands where id = ?', (retData[3],))
|
|
|
|
conn.commit()
|
2018-01-02 08:43:29 +00:00
|
|
|
conn.close()
|
|
|
|
|
|
|
|
return retData
|
|
|
|
|
|
|
|
def daemonQueueAdd(self, command, data=''):
|
2018-01-04 07:12:46 +00:00
|
|
|
# Intended to be used by the web server
|
2018-01-02 08:43:29 +00:00
|
|
|
date = math.floor(time.time())
|
|
|
|
conn = sqlite3.connect(self.queueDB)
|
|
|
|
c = conn.cursor()
|
|
|
|
t = (command, data, date)
|
|
|
|
c.execute('INSERT into commands (command, data, date) values (?, ?, ?)', t)
|
|
|
|
conn.commit()
|
|
|
|
conn.close()
|
|
|
|
return
|