Advertisement
Guest User

bitboard_Installer_Bitmessage

a guest
Jun 29th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 14.55 KB | None | 0 0
  1. #!/bin/bash
  2. ########################################################################################
  3.  
  4.  
  5.  
  6. #     usage example:       menu     pwd whoami ls ps
  7.  
  8. #     giving you a menu with 4 options to execute in bash shell / Konsole
  9.  
  10.  
  11.  
  12. # call in bash as:    . menu1    # if  menu1  is the file name with this script in it
  13. # usage e.g.:
  14. # menu ls  "ls -l"  "echo  list dir ; clear ; ls -la "   clear
  15. # q, Q or 0 or empty_string i.e. ENTER-key alone     always exits the menu
  16.  
  17.  
  18. # click-launch from Dolphin file-manager in KDE: associate shell script  open-action command:  konsole -e %f
  19. # under right-cick,  FILE TYPE OPTIONS,  ...  advanced option, do not tag "run in Terminal"
  20. # so you get a  "open action"  rather than an "execute action" , but it does what you expect.
  21.  
  22.  
  23. # to set as a bash lib func  : copy the text  between the upper and lower ###### lines into your ~/.bashrc file
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31. ibitboard()
  32. {
  33. clear
  34. echo "install of bitboard web thingy"
  35. pushd .
  36.  
  37. # unalias cp
  38. # cp
  39.  
  40. mkdir    bb
  41. cd     ./bb
  42.  
  43.  
  44. (
  45. cat <<'EOFherefile'
  46. import base64
  47. import json
  48. import logging as log
  49. import time
  50. import traceback
  51. import xmlrpclib
  52. from threading import Thread
  53.  
  54. import config
  55. from chan_objects import ChanBoard
  56. from chan_objects import ChanPost
  57.  
  58.  
  59. def getBitmessageEndpoint():
  60.     username = "aa"        #config.getBMConfig("apiusername")
  61.     password = "aa"        #config.getBMConfig("apipassword")
  62.     host =     "127.0.1"   #config.getBMConfig("apiinterface")
  63.     port =     "8442"      #config.getBMConfig("apiport")
  64. #   return "http://"+username+":"+password+"@"+host+":"+port+"/"
  65.     return "http://aa:aa@127.0.0.1:8442/"
  66.  
  67. '''
  68.  
  69. this is file  /bitboard-master/bitmessage_gateway.py
  70.  
  71. lauch as daemon and curses, then the missing Qt4 stuff does not matter.
  72.  
  73. python2 bitmessagemain.py --curses
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.                                                    http://localhost:8080
  81.                                  
  82.                                   kioclient5 exec 'http://localhost:8080'
  83.                                  
  84.                                  
  85. daemon = true
  86. dontconnect = false
  87.  
  88.  
  89. maxdownloadrate = 33
  90. maxoutboundconnections = 2
  91. maxuploadrate = 33
  92.  
  93.  
  94.  
  95. apienabled = true
  96. apiusername = aa
  97. apipassword = aa
  98. apiinterface = 127.0.0.1
  99. apiport = 8442
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. '''
  107.  
  108.  
  109. class BitMessageGateway(Thread):
  110.     def __init__(self):
  111.         super(BitMessageGateway, self).__init__()
  112.         self._postsById = {}
  113.         self._boardByChan = {}
  114.         self._chanDict = {}
  115.         self._refresh = True
  116.         self._api = xmlrpclib.ServerProxy(getBitmessageEndpoint())
  117.  
  118.     def run(self):
  119.         while True:
  120.             try:
  121.                 print "Updating bitmessage info."
  122.                 self.updateChans()
  123.                 self.updateChanThreads()
  124.  
  125.                 print `len(self._postsById)` + " total messages " + `len(self._chanDict)` + " total chans."
  126.  
  127.                 for i in range(0, config.bm_refresh_interval):
  128.                     time.sleep(i)
  129.                     if self._refresh:
  130.                         self._refresh = False
  131.                         break
  132.             except Exception as e:
  133.                 log.error("Exception in gateway thread: " + `e`)
  134.                 time.sleep(config.bm_refresh_interval)
  135.                
  136.     def getChans(self):
  137.         return self._chanDict
  138.  
  139.     def deleteMessage(self, chan, messageid):
  140.         try:
  141.             board = self._boardByChan[chan]
  142.             post = self._postsById[messageid]
  143.             board.deletePost(post)
  144.             del self._postsById[messageid]
  145.         except Exception as e:
  146.             print "Exception deleting post: " + `e`
  147.             traceback.print_exc()
  148.         return self._api.trashMessage(messageid)
  149.  
  150.     def deleteThread(self, chan, threadid):
  151.         try:
  152.             board = self._boardByChan[chan]
  153.             thread = board.getThread(threadid)
  154.             if thread:
  155.                 threadposts = thread.getPosts()
  156.                 for post in threadposts:
  157.                     self.deleteMessage(chan, post.msgid)
  158.             board.deleteThread(threadid)
  159.         except Exception as e:
  160.             print "Exception deleting thread: " + repr(e)
  161.             traceback.print_exc()
  162.         return "Thread [" + repr(threadid) + "] deleted."
  163.  
  164.     def updateChans(self):
  165.         chans = {}
  166.         try:
  167.             straddr = self._api.listAddresses()
  168.             addresses = json.loads(straddr)['addresses']
  169.             for jaddr in addresses:
  170.                 if jaddr['chan'] and jaddr['enabled']:
  171.                     chan_name = jaddr['label']
  172.                     chans[chan_name] = jaddr['address']
  173.         except Exception as e:
  174.             log.error("Exception getting channels: " + `e`)
  175.             traceback.print_exc()
  176.  
  177.         self._chanDict = dict(self._chanDict.items() + chans.items())
  178.  
  179.     def getChanName(self, chan):
  180.         for label, addr in self._chanDict.iteritems():
  181.             if addr == chan:
  182.                 return label
  183.  
  184.     def getImage(self, imageid):
  185.         return self._postsById[imageid].image
  186.  
  187.     def updateChanThreads(self):
  188.         strmessages = self._api.getAllInboxMessageIDs()
  189.         messages = json.loads(strmessages)['inboxMessageIds']
  190.         for message in messages:
  191.             messageid = message["msgid"]
  192.  
  193.             if messageid in self._postsById:
  194.                 continue
  195.  
  196.             strmessage = self._api.getInboxMessageByID(messageid)
  197.             jsonmessages = json.loads(strmessage)['inboxMessage']
  198.  
  199.             if len(jsonmessages) <= 0:
  200.                 continue
  201.  
  202.             chan = jsonmessages[0]['toAddress']
  203.             post = ChanPost(chan, jsonmessages[0])
  204.  
  205.             if chan not in self._boardByChan:
  206.                 self._boardByChan[chan] = ChanBoard(chan)
  207.  
  208.             self._postsById[messageid] = post
  209.             chanboard = self._boardByChan[chan]
  210.             chanboard.addPost(post)
  211.  
  212.     def getThreadCount(self, chan):
  213.         if chan not in self._boardByChan:
  214.             return 0
  215.         return self._boardByChan[chan].getThreadCount()
  216.  
  217.     def getChanThreads(self, chan, page=1):
  218.         if chan not in self._boardByChan:
  219.             return []
  220.         board = self._boardByChan[chan]
  221.  
  222.         thread_start = int((int(page) - 1) * config.threads_per_page)
  223.         thread_end = int(int(page) * config.threads_per_page)
  224.  
  225.         return board.getThreads(thread_start, thread_end)
  226.  
  227.     def getChanThread(self, chan, thread_id):
  228.         if chan not in self._boardByChan:
  229.             return None
  230.  
  231.         board = self._boardByChan[chan]
  232.  
  233.         return board.getThread(thread_id)
  234.  
  235.     def submitPost(self, chan, subject, body, image):
  236.         subject = subject.encode('utf-8').strip()
  237.         subjectdata = base64.b64encode(subject)
  238.  
  239.         msgdata = body.encode('utf-8').strip()
  240.  
  241.         if image:
  242.             imagedata = base64.b64encode(image)
  243.             msgdata += "\n\n<img src=\"data:image/jpg;base64," + imagedata + "\">"
  244.  
  245.         msg = base64.b64encode(msgdata)
  246.  
  247.         self._refresh = True
  248.         return self._api.sendMessage(chan, chan, subjectdata, msg)
  249.  
  250.     def joinChan(self, passphrase):
  251.         self._refresh = True
  252.  
  253.         try:
  254.             result = self._api.createChan(base64.b64encode(passphrase))
  255.         except Exception as e:
  256.             result = repr(e)
  257.  
  258.         return result
  259.  
  260.     def getAPIStatus(self):
  261.         try:
  262.             result = self._api.add(2, 2)
  263.         except Exception as e:
  264.             return repr(e)
  265.         if result == 4:
  266.             return True
  267.         return result
  268.  
  269. gateway_instance = BitMessageGateway()
  270. gateway_instance.start()
  271. EOFherefile
  272. ) > bitmessage_gateway.py
  273.  
  274. git clone https://github.com/michrob/bitboard  #  modded 8442
  275. cd bitboard/
  276.  
  277.  
  278. mv    bitmessage_gateway.py  bitmessage_gateway___ORIG.py
  279. mv ../bitmessage_gateway.py  .
  280. #                                  github version breaks too much
  281.  
  282.  
  283. echo '#!/usr/bin/env python2 '  >  bb.py
  284. chmod +x                           bb.py
  285. cat ./bitboard.py               >> bb.py
  286.  
  287.  
  288.  
  289. python2 -m pip install --user  -r requirements.txt
  290. # mod gateway aa:aa
  291.  
  292. # python2 ./bitmessagemain.py --curses
  293. # python2   bitboard.py                   &
  294. #         ./bb.py                         &  
  295. #                                                  env might be elsewhere
  296.   python2 ./bb.py                         &  
  297. sleep 1.1 # wait until web server is ready
  298. kioclient5 exec 'http://localhost:8080'   &
  299. popd
  300. }
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309. menu()
  310. {
  311. local IFS=$' \t\n'
  312. local num n=1 opt item cmd
  313.  
  314. clear
  315.  
  316. ## Use default setting of IFS,  Loop though the command-line arguments
  317. echo
  318. for item
  319. do
  320.   printf " %3d. %s\n" "$n" "${item%%:*}"
  321.   n=$(( $n + 1 ))
  322. done
  323.  
  324. ## If there are fewer than 10 items, set option to accept key without ENTER
  325. echo    
  326. if [ $# -lt 10 ]
  327. then
  328.   opt=-sn1
  329. else
  330.   opt=
  331. fi
  332.  
  333. read -p "ENTER quits menu - please choose  1 to $# ==> " $opt num   ## Get response from user
  334.  
  335. ## Check that user entry is valid
  336. case $num in
  337.    [qQ0]   | "" ) clear ; return ;;   ## q, Q or 0 or "" exits
  338.   *[!0-9]* | 0* )                     ## invalid entry
  339.  
  340.   printf "\aInvalid menu choice : %s\n" "$num" >&2
  341.   return 1
  342.   ;;
  343. esac
  344.  
  345. echo
  346. if     [ "$num" -le "$#" ]  ## Check that number is <= to the number of menu items
  347. then
  348.   eval  ${!num}             ## eval  "${!num#*:}"  # Execute it using indirect expansion,  breaking stuff  :-(
  349. else
  350.   printf "\aInvalid menu choice: %s\n" "$num" >&2
  351.   return 1
  352. fi
  353. }
  354. ##############################################################################################
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363. #-----------------------------------------------------------
  364. # "Here-document" containing nice standard keys.dat with 3 chans and 1 nuked ID / pml , dropped into thwe cwd, i.e.  .
  365.  
  366. # note that a nuked address is kind of useless , since its key was published. It still is kinda broadcast fun though.
  367. # You have no privacy using a nuked key -
  368. # much like you don't have privacy while using a key which someone has stolen from you.
  369.  
  370. (
  371. cat <<'EOFherefile'
  372.  
  373. [bitmessagesettings]
  374. apienabled = true
  375. apiport = 8442
  376. apiinterface = 127.0.0.1
  377. apipassword = aa
  378. apiusername = aa
  379. blackwhitelist = black
  380. daemon = true
  381. defaultnoncetrialsperbyte = 1000
  382. defaultpayloadlengthextrabytes = 1000
  383. dontconnect = false
  384. dontsendack = False
  385. hidetrayconnectionnotifications = True
  386. identiconsuffix = AAAAAAAAAAAA
  387. keysencrypted = false
  388. maxacceptablenoncetrialsperbyte = 20000000000
  389. maxacceptablepayloadlengthextrabytes = 20000000000
  390. maxdownloadrate = 55
  391. maxoutboundconnections = 1
  392. maxuploadrate = 55
  393. messagesencrypted = false
  394. minimizeonclose = false
  395. minimizetotray = False
  396. namecoinrpchost = localhost
  397. namecoinrpcpassword =
  398. namecoinrpcport = 8336
  399. namecoinrpctype = namecoind
  400. namecoinrpcuser =
  401. onionbindip = 127.0.0.1
  402. onionhostname = AAAAAAAAAAAAAAAA.onion
  403. onionport = 8448
  404. opencl = None
  405. port = 8444
  406. replybelow = False
  407. sendoutgoingconnections = True
  408. settingsversion = 10
  409. showtraynotifications = False
  410. smtpdeliver =
  411. socksauthentication = False
  412. sockshostname = 127.0.0.1
  413. sockslisten = False
  414. sockspassword =
  415. socksport = 9150
  416. socksproxytype = none
  417. socksusername =
  418. startintray = False
  419. startonlogon = False
  420. stopresendingafterxdays = 5.0
  421. stopresendingafterxmonths = 5.0
  422. timeformat = %%a, %%d %%b %%Y  %%H:%%M
  423. trayonclose = False
  424. ttl = 1381224
  425. upnp = False
  426. useidenticons = False
  427. userlocale = en
  428. willinglysendtomobile = False
  429.  
  430. [BM-2cWy7cvHoq3f1rYMerRJp8PT653jjSuEdY]
  431. label = [chan] bitmessage
  432. enabled = true
  433. decoy = false
  434. chan = true
  435. noncetrialsperbyte = 1000
  436. payloadlengthextrabytes = 1000
  437. privsigningkey = 5K42shDERM5g7Kbi3JT5vsAWpXMqRhWZpX835M2pdSoqQQpJMYm
  438. privencryptionkey = 5HwugVWm31gnxtoYcvcK7oywH2ezYTh6Y4tzRxsndAeMi6NHqpA
  439.  
  440. [BM-2cUzsvYoNbKNNuDnJtdPVS2pbSHzNJyqdD]
  441. label = [chan] find-new-chan
  442. enabled = true
  443. decoy = false
  444. chan = true
  445. noncetrialsperbyte = 1000
  446. payloadlengthextrabytes = 1000
  447. privsigningkey = 5JrsTVeBZYUxYeK5WQgiESBxpfMvqMp2bdvu7FyY356rMqzTdiB
  448. privencryptionkey = 5KXBMwknxy585jkR3TVZuYgBjAawtGfWUp98cmaWvFjAZwC2yaN
  449.  
  450. [BM-2cW67GEKkHGonXKZLCzouLLxnLym3azS8r]
  451. label = [chan]   general
  452. enabled = true
  453. decoy = false
  454. chan = true
  455. noncetrialsperbyte = 1000
  456. payloadlengthextrabytes = 1000
  457. privsigningkey = 5Jnbdwc4u4DG9ipJxYLznXSvemkRFueQJNHujAQamtDDoX3N1eQ
  458. privencryptionkey = 5JrDcFtQDv5ydcHRW6dfGUEvThoxCCLNEUaxQfy8LXXgTJzVAcq
  459.  
  460. [BM-2cTaRF4nbj4ByCTH13SUMouK8nHXBLaLmS]
  461. label = NUKED ADDRESS LmS
  462. enabled = true
  463. decoy = false
  464. chan = false
  465. noncetrialsperbyte = 1000
  466. payloadlengthextrabytes = 1000
  467. privsigningkey = 5J9gVWmW9XCjJo1CdymosipSuWRLp2ovaUkJ2JGFc9T1A9SHJvB
  468. privencryptionkey = 5HrrrckD7RPYhiBeRPAqmUUv73ajYnHKgsC2Q2f3AqK9hptr7aN
  469. mailinglist = false
  470. mailinglistname = nuked_PML
  471. lastpubkeysendtime = 1469973237
  472.  
  473. EOFherefile
  474. ) > keys.dat
  475. #-----------------------------------------------------------
  476.  
  477.  
  478.  
  479.  
  480.  
  481.  
  482.  
  483. #'echo " delete unimportant files                  " ;  rm ./PyBitmessage/* ; cd PyBitmessage ; rm -rf man dev build packages desktop ; cd .. ' \
  484.  
  485.  
  486. #   useful in click-launch to add    ; read WAITNOW        #  which will wait for keypress before closing Konsole
  487.  
  488.  
  489. # now actually using the menu:
  490.  
  491. # modify it to your liking        note you are then on  MASTER  branch , not on the newer  ver. 0.6.3   branch
  492.  
  493. #  run through the options  1 2 3 4   in this order:   1 2 3 4
  494.  
  495. menu                                                                                                                              \
  496. 'echo " clone BitMessage repo below current dir   " ;  git clone -b 'v0.6'  "https://github.com/Bitmessage/PyBitmessage.git"    ' \
  497. 'echo " check dependencies i.e. py modules etc.   " ;  cd ./PyBitmessage/ ; python2 checkdeps.py ; cd ..                        ' \
  498. 'echo " inject standard KEYS.DAT file             " ;  cp  ./keys.dat                   PyBitmessage/src                        ' \
  499. 'echo " run new BM from py source                 " ;  pushd . ; cd  PyBitmessage/src ; ./bitmessagemain.py --curses &     popd ' \
  500. 'echo " pull    BM update from github             " ;  pushd . ; cd  PyBitmessage/ ; git pull ;                            popd ' \
  501. 'echo " fetch all                                 " ;  pushd . ; cd  PyBitmessage/ ; git fetch --all;                      popd ' \
  502. 'echo " git hard reset                            " ;  pushd . ; cd  PyBitmessage/ ; git reset --hard origin/master ;      popd ' \
  503. 'echo " kill bitboard, pyBM daemon, plus any py2  " ;  killall python2                                                          ' \
  504. 'echo " inst bitboard                             " ;  ibitboard                                                                '
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement