コード例 #1
0
ファイル: main.py プロジェクト: M0Dark/ZeroNet
def siteCreate():
	logging.info("Generating new privatekey...")
	from Crypt import CryptBitcoin
	privatekey = CryptBitcoin.newPrivatekey()
	logging.info("----------------------------------------------------------------------")
	logging.info("Site private key: %s" % privatekey)
	logging.info("                  !!! ^ Save it now, required to modify the site ^ !!!")
	address = CryptBitcoin.privatekeyToAddress(privatekey)
	logging.info("Site address:     %s" % address)
	logging.info("----------------------------------------------------------------------")

	while True:
		if raw_input("? Have you secured your private key? (yes, no) > ").lower() == "yes": break
		else: logging.info("Please, secure it now, you going to need it to modify your site!")

	logging.info("Creating directory structure...")
	from Site import Site
	os.mkdir("data/%s" % address)
	open("data/%s/index.html" % address, "w").write("Hello %s!" % address)

	logging.info("Creating content.json...")
	site = Site(address)
	site.content_manager.sign(privatekey=privatekey)
	site.settings["own"] = True
	site.saveSettings()

	logging.info("Site created!")
コード例 #2
0
ファイル: main.py プロジェクト: TheBojda/ZeroNet
    def siteDownload(self, address):
        from Site import Site
        from Site import SiteManager
        SiteManager.site_manager.load()

        logging.info("Opening a simple connection server")
        global file_server
        from Connection import ConnectionServer
        file_server = ConnectionServer("127.0.0.1", 1234)

        site = Site(address)

        on_completed = gevent.event.AsyncResult()

        def onComplete(evt):
            evt.set(True)

        site.onComplete.once(lambda: onComplete(on_completed))
        print "Announcing..."
        site.announce()

        s = time.time()
        print "Downloading..."
        site.downloadContent("content.json", check_modifications=True)

        print on_completed.get()
        print "Downloaded in %.3fs" % (time.time()-s)
コード例 #3
0
    def testFindOptional(self, file_server, site, site_temp):
        file_server.ip_incoming = {}  # Reset flood protection

        # Init source server
        site.connection_server = file_server
        file_server.sites[site.address] = site

        # Init full source server (has optional files)
        site_full = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
        file_server_full = FileServer("127.0.0.1", 1546)
        site_full.connection_server = file_server_full
        gevent.spawn(lambda: ConnectionServer.start(file_server_full))
        time.sleep(0)  # Port opening
        file_server_full.sites[site_full.address] = site_full  # Add site
        site_full.storage.verifyFiles(quick_check=True)  # Check optional files
        site_full_peer = site.addPeer("127.0.0.1", 1546)  # Add it to source server
        assert site_full_peer.updateHashfield()  # Update hashfield

        # Init client server
        site_temp.connection_server = ConnectionServer("127.0.0.1", 1545)
        site_temp.announce = mock.MagicMock(return_value=True)  # Don't try to find peers from the net
        site_temp.addPeer("127.0.0.1", 1544)  # Add source server

        # Download normal files
        site_temp.download(blind_includes=True).join(timeout=5)

        # Download optional data/optional.txt
        optional_file_info = site_temp.content_manager.getFileInfo("data/optional.txt")
        assert not site_temp.storage.isFile("data/optional.txt")
        assert not site.content_manager.hashfield.hasHash(
            optional_file_info["sha512"]
        )  # Source server don't know he has the file
        assert site_full_peer.hashfield.hasHash(
            optional_file_info["sha512"]
        )  # Source full peer on source server has the file
        assert site_full.content_manager.hashfield.hasHash(
            optional_file_info["sha512"]
        )  # Source full server he has the file

        with Spy.Spy(FileRequest, "route") as requests:
            # Request 2 file same time
            threads = []
            threads.append(site_temp.needFile("data/optional.txt", blocking=False))
            threads.append(
                site_temp.needFile(
                    "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif", blocking=False
                )
            )
            gevent.joinall(threads)

            assert (
                len([request for request in requests if request[0] == "findHashIds"]) == 1
            )  # findHashids should call only once

        assert site_temp.storage.isFile("data/optional.txt")
        assert site_temp.storage.isFile("data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif")

        assert site_temp.storage.deleteFiles()
        file_server_full.stop()
        [connection.close() for connection in file_server.connections]
コード例 #4
0
ファイル: main.py プロジェクト: TheBojda/ZeroNet
    def siteCreate(self):
        logging.info("Generating new privatekey...")
        from Crypt import CryptBitcoin
        privatekey = CryptBitcoin.newPrivatekey()
        logging.info("----------------------------------------------------------------------")
        logging.info("Site private key: %s" % privatekey)
        logging.info("                  !!! ^ Save it now, required to modify the site ^ !!!")
        address = CryptBitcoin.privatekeyToAddress(privatekey)
        logging.info("Site address:     %s" % address)
        logging.info("----------------------------------------------------------------------")

        while True and not config.batch:
            if raw_input("? Have you secured your private key? (yes, no) > ").lower() == "yes":
                break
            else:
                logging.info("Please, secure it now, you going to need it to modify your site!")

        logging.info("Creating directory structure...")
        from Site import Site
        from Site import SiteManager
        SiteManager.site_manager.load()

        os.mkdir("%s/%s" % (config.data_dir, address))
        open("%s/%s/index.html" % (config.data_dir, address), "w").write("Hello %s!" % address)

        logging.info("Creating content.json...")
        site = Site(address)
        site.content_manager.sign(privatekey=privatekey, extend={"postmessage_nonce_security": True})
        site.settings["own"] = True
        site.saveSettings()

        logging.info("Site created!")
コード例 #5
0
ファイル: conftest.py プロジェクト: binerf/zeronet_tor
def site(request):
    threads_before = [obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet)]
    # Reset ratelimit
    RateLimit.queue_db = {}
    RateLimit.called_db = {}

    site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")

    # Always use original data
    assert "1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT" in site.storage.getPath("")  # Make sure we dont delete everything
    shutil.rmtree(site.storage.getPath(""), True)
    shutil.copytree(site.storage.getPath("") + "-original", site.storage.getPath(""))

    # Add to site manager
    SiteManager.site_manager.get("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
    site.announce = mock.MagicMock(return_value=True)  # Don't try to find peers from the net

    def cleanup():
        site.storage.deleteFiles()
        site.content_manager.contents.db.deleteSite(site)
        del SiteManager.site_manager.sites["1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"]
        site.content_manager.contents.db.close()
        SiteManager.site_manager.sites.clear()
        db_path = "%s/content.db" % config.data_dir
        os.unlink(db_path)
        del ContentDb.content_dbs[db_path]
        gevent.killall([obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet) and obj not in threads_before])
    request.addfinalizer(cleanup)

    site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")  # Create new Site object to load content.json files
    if not SiteManager.site_manager.sites:
        SiteManager.site_manager.sites = {}
    SiteManager.site_manager.sites["1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT"] = site
    return site
コード例 #6
0
ファイル: main.py プロジェクト: lrmodesgh/ZeroNet
    def siteAnnounce(self, address):
        from Site.Site import Site
        logging.info("Announcing site %s to tracker..." % address)
        site = Site(address)

        s = time.time()
        site.announce()
        print "Response time: %.3fs" % (time.time() - s)
        print site.peers
コード例 #7
0
ファイル: conftest.py プロジェクト: cryptowest/ZeroNet
def site_temp(request):
    with mock.patch("Config.config.data_dir", config.data_dir + "-temp"):
        site_temp = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
        site_temp.announce = mock.MagicMock(return_value=True)  # Don't try to find peers from the net

    def cleanup():
        site_temp.storage.deleteFiles()
        site_temp.content_manager.contents.db.deleteSite("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
        site_temp.content_manager.contents.db.close()
        db_path = "%s-temp/content.db" % config.data_dir
        os.unlink(db_path)
        del ContentDb.content_dbs[db_path]
    request.addfinalizer(cleanup)
    return site_temp
コード例 #8
0
ファイル: test.py プロジェクト: TamtamHero/ZeroNet
    def testClone(self):
        from Site import Site
        import shutil

        site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")  # Privatekey: 5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv
        self.assertEqual(site.storage.directory, "src/Test/testdata/1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")

        # Remove old files
        if os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
            shutil.rmtree("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
        self.assertFalse(os.path.isfile("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL/content.json"))

        # Clone 1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT to 15E5rhcAUD69WbiYsYARh4YHJ4sLm2JEyc
        new_site = site.clone("159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL", "5JU2p5h3R7B1WrbaEdEDNZR7YHqRLGcjNcqwqVQzX2H4SuNe2ee", address_index=1)

        # Check if clone was successful
        self.assertEqual(new_site.address, "159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
        self.assertTrue(new_site.storage.isFile("content.json"))
        self.assertTrue(new_site.storage.isFile("index.html"))
        self.assertTrue(new_site.storage.isFile("data/users/content.json"))
        self.assertTrue(new_site.storage.isFile("data/zeroblog.db"))

        # Test re-cloning (updating)

        # Changes in non-data files should be overwritten
        new_site.storage.write("index.html", "this will be overwritten")
        self.assertEqual(new_site.storage.read("index.html"), "this will be overwritten")

        # Changes in data file should be kept after re-cloning
        changed_contentjson = new_site.storage.loadJson("content.json")
        changed_contentjson["description"] = "Update Description Test"
        new_site.storage.writeJson("content.json", changed_contentjson)

        changed_data = new_site.storage.loadJson("data/data.json")
        changed_data["title"] = "UpdateTest"
        new_site.storage.writeJson("data/data.json", changed_data)

        # Re-clone the site
        site.clone("159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")

        self.assertEqual(new_site.storage.loadJson("data/data.json")["title"], "UpdateTest")
        self.assertEqual(new_site.storage.loadJson("content.json")["description"], "Update Description Test")
        self.assertNotEqual(new_site.storage.read("index.html"), "this will be overwritten")

        # Delete created files
        if os.path.isdir("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL"):
            new_site.storage.closeDb()
            shutil.rmtree("src/Test/testdata/159EGD5srUsMP97UpcLy8AtKQbQLK2AbbL")
コード例 #9
0
ファイル: conftest.py プロジェクト: binerf/zeronet_tor
def site_temp(request):
    threads_before = [obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet)]
    with mock.patch("Config.config.data_dir", config.data_dir + "-temp"):
        site_temp = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
        site_temp.announce = mock.MagicMock(return_value=True)  # Don't try to find peers from the net

    def cleanup():
        site_temp.storage.deleteFiles()
        site_temp.content_manager.contents.db.deleteSite(site_temp)
        site_temp.content_manager.contents.db.close()
        db_path = "%s-temp/content.db" % config.data_dir
        os.unlink(db_path)
        del ContentDb.content_dbs[db_path]
        gevent.killall([obj for obj in gc.get_objects() if isinstance(obj, gevent.Greenlet) and obj not in threads_before])
    request.addfinalizer(cleanup)
    return site_temp
コード例 #10
0
ファイル: Phantom_Ui.py プロジェクト: shiftcurrency/phantom
    def create_phantom_site(self):

        from Config import config
        from Crypt import CryptBitcoin
        from Site import Site
        import os

        config.parse(silent=True)
        if not config.arguments:
            config.parse()

        self.private_key = CryptBitcoin.newPrivatekey()
        self.address = CryptBitcoin.privatekeyToAddress(self.private_key)

        try:
            os.mkdir("%s/%s" % (config.data_dir, self.address))
            open("%s/%s/index.html" % (config.data_dir, self.address), "w").write("Hello %s!" % self.address)
        except Exception as e:
            return self.error_msg.error_response("err_create_sitedir")
    
        try:
            self.site = Site(self.address)
            self.site.content_manager.sign(privatekey=self.private_key, extend={"postmessage_nonce_security": True})
            self.site.settings["own"] = True
            self.site.saveSettings()
        except Exception as e:
            print e
            return self.error_msg.error_response("err_create_site")
        return {"jsonrpc": "2.0", "id": "1", "result": ["true", str(self.address), str(self.private_key)]}
コード例 #11
0
ファイル: main.py プロジェクト: lrmodesgh/ZeroNet
    def siteNeedFile(self, address, inner_path):
        from Site import Site
        def checker():
            while 1:
                s = time.time()
                time.sleep(1)
                print time.time()-s
        gevent.spawn(checker)

        logging.info("Opening a simple connection server")
        global file_server
        from Connection import ConnectionServer
        file_server = ConnectionServer("127.0.0.1", 1234)

        site = Site(address)
        site.announce()
        print site.needFile(inner_path, update=True)
コード例 #12
0
def getSitesAndFeeds():
    doc = xml.dom.minidom.parse(_pwd + '/sites.xml')
    
    # Iterate through the list of sites in the XML feed.
    for node_site in doc.getElementsByTagName('site'):
        # Instantiate a Site object and assign its name.
        site = Site()
        site.name = node_site.getAttribute('name')
        site.image = node_site.getAttribute('image')
    
        # Retrieve the name of each feed to build the top-level menu.
        for node_feed in node_site.getElementsByTagName('feed'):
            feed = Feed()
            feed.name = node_feed.getAttribute('name')
            feed.type = node_feed.getAttribute('type')
            for node_url in node_feed.getElementsByTagName('url'):
                url_quality = node_url.getAttribute('quality')
                feed.urls[url_quality] = SimplerXML.getText(node_url, 'url')
            site.feeds.append(feed)
    
        array_sites.append(site)
コード例 #13
0
ファイル: TestSiteDownload.py プロジェクト: jobsfan/ZeroNet
    def testFindOptional(self, file_server, site, site_temp):
        file_server.ip_incoming = {}  # Reset flood protection

        # Init source server
        site.connection_server = file_server
        file_server.sites[site.address] = site

        # Init full source server (has optional files)
        site_full = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
        file_server_full = FileServer("127.0.0.1", 1546)
        site_full.connection_server = file_server_full
        gevent.spawn(lambda: ConnectionServer.start(file_server_full))
        time.sleep(0)  # Port opening
        file_server_full.sites[site_full.address] = site_full  # Add site
        site_full.storage.verifyFiles(quick_check=True)  # Check optional files
        site_full_peer = site.addPeer("127.0.0.1", 1546)  # Add it to source server
        assert site_full_peer.updateHashfield()  # Update hashfield

        # Init client server
        site_temp.connection_server = ConnectionServer("127.0.0.1", 1545)
        site_temp.announce = mock.MagicMock(return_value=True)  # Don't try to find peers from the net
        site_temp.addPeer("127.0.0.1", 1544)  # Add source server

        # Download normal files
        site_temp.download(blind_includes=True).join(timeout=5)

        # Download optional data/optional.txt
        optional_file_info = site_temp.content_manager.getFileInfo("data/optional.txt")
        assert not site_temp.storage.isFile("data/optional.txt")
        assert not site.content_manager.hashfield.hasHash(optional_file_info["sha512"])  # Source server don't know he has the file
        assert site_full_peer.hashfield.hasHash(optional_file_info["sha512"])  # Source full peer on source server has the file
        assert site_full.content_manager.hashfield.hasHash(optional_file_info["sha512"])  # Source full server he has the file

        with Spy.Spy(FileRequest, "route") as requests:
            site_temp.needFile("data/optional.txt")
            print requests

        assert site_temp.storage.deleteFiles()
        file_server_full.stop()
        [connection.close() for connection in file_server.connections]
コード例 #14
0
ファイル: main.py プロジェクト: TheBojda/ZeroNet
    def sitePublish(self, address, peer_ip=None, peer_port=15441, inner_path="content.json", diffs={}):
        global file_server
        from Site import Site
        from Site import SiteManager
        from File import FileServer  # We need fileserver to handle incoming file requests
        from Peer import Peer
        SiteManager.site_manager.load()

        logging.info("Loading site...")
        site = Site(address, allow_create=False)
        site.settings["serving"] = True  # Serving the site even if its disabled

        logging.info("Creating FileServer....")
        file_server = FileServer()
        site.connection_server = file_server
        file_server_thread = gevent.spawn(file_server.start, check_sites=False)  # Dont check every site integrity
        time.sleep(0.001)

        if not file_server_thread.ready():
            # Started fileserver
            file_server.openport()
            if peer_ip:  # Announce ip specificed
                site.addPeer(peer_ip, peer_port)
            else:  # Just ask the tracker
                logging.info("Gathering peers from tracker")
                site.announce()  # Gather peers
            published = site.publish(5, inner_path, diffs=diffs)  # Push to peers
            if published > 0:
                time.sleep(3)
                logging.info("Serving files (max 60s)...")
                gevent.joinall([file_server_thread], timeout=60)
                logging.info("Done.")
            else:
                logging.info("No peers found, sitePublish command only works if you already have visitors serving your site")
        else:
            # Already running, notify local client on new content
            logging.info("Sending siteReload")
            if config.fileserver_ip == "*":
                my_peer = Peer("127.0.0.1", config.fileserver_port)
            else:
                my_peer = Peer(config.fileserver_ip, config.fileserver_port)

            logging.info(my_peer.request("siteReload", {"site": site.address, "inner_path": inner_path}))
            logging.info("Sending sitePublish")
            logging.info(my_peer.request("sitePublish", {"site": site.address, "inner_path": inner_path, "diffs": diffs}))
            logging.info("Done.")
コード例 #15
0
ファイル: SiteManager.py プロジェクト: noflag/ZeroNet
    def need(self, address, all_file=True):
        from Site import Site
        site = self.get(address)
        if not site:  # Site not exist yet
            if not self.isAddress(address):
                return False  # Not address: %s % address
            logging.debug("Added new site: %s" % address)
            site = Site(address)
            self.sites[address] = site
            if not site.settings["serving"]:  # Maybe it was deleted before
                site.settings["serving"] = True
                site.saveSettings()
            if all_file:  # Also download user files on first sync
                site.download(blind_includes=True)
        else:
            if all_file:
                site.download()

        return site
コード例 #16
0
ファイル: SiteManager.py プロジェクト: shea256/ZeroNet
	def need(self, address, all_file=True):
		from Site import Site
		new = False
		site = self.get(address)
		if not site: # Site not exits yet
			if not self.isAddress(address): return False # Not address: %s % address
			logging.debug("Added new site: %s" % address)
			site = Site(address)
			self.sites[address] = site
			if not site.settings["serving"]: # Maybe it was deleted before
				site.settings["serving"] = True
				site.saveSettings()
			new = True

		if all_file: site.download()
		return site
コード例 #17
0
    def open(self, row: int, col: int):
        site = Site(row, col)
        site1DCoordinates = self.grid.convertToSite1DCoordinates(site)

        if self.sitesOpened[site1DCoordinates]:
            return

        self.sitesOpened[site1DCoordinates] = True

        for neighbor in self.grid.retrieveSiteNeighbors(site):
            neighbor1DCoords = self.grid.convertToSite1DCoordinates(neighbor)
            if not self.sitesOpened[neighbor1DCoords]:
                continue
            self.quickFindAlgorithm.union(site1DCoordinates, neighbor1DCoords)

        if row == 1:
            self.quickFindAlgorithm.union(site1DCoordinates, 0)

        if row == self.grid.getN():
            self.quickFindAlgorithm.union(
                site1DCoordinates,
                int(math.pow(self.grid.getN(), 2)) + 1)
コード例 #18
0
def parseMusavatAz(query):
    query = querize(query)
    
    request = Request('https://musavat.com/search?text=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('div', class_= 'row block-news')

    source_tags = parent.find_all('a', class_= 'block', href=True)
    headline_tags = parent.find_all('strong')
    date_tags = parent.find_all('span', class_= 'pull-left')

    site = Site('Musavat.az')

    for i in range(len(source_tags)):
        source = source_tags[i]
        headline = headline_tags[i]
        date = date_tags[i]
        site.results.append(News('https://www.musavat.com' + source['href'], headline.get_text(), date.get_text(), '00:00'))

    return site
コード例 #19
0
def parseApaAz(query):
    query = querize(query)

    request = Request('https://apa.az/az/search?q=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('div', class_='row block category')

    source_tags = parent.find_all('a', href=True)
    headline_tags = parent.find_all('p')
    date_tags = parent.find_all('span', class_='date')

    site = Site("Apa.az")

    for i in range(len(source_tags)): 
        source = source_tags[i]
        headline = headline_tags[i]
        date = date_tags[i]
        site.results.append(News('https://www.apa.az' + source['href'], headline.get_text(), date.get_text(), '00:00'))

    return site
コード例 #20
0
def parseLentAz(query):
    query = querize(query)

    request = Request('https://www.lent.az/axtaris-neticesi?search=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    print(file)
    
    news_tags = file.find_all('a', class_='link-ln-news')
    date_tags = file.find_all('div', class_='pull-right')

    site = Site('Lent.az')

    print(date_tags[0].get_text())

    for i in range(len(news_tags)): 
        tag = news_tags[i]
        date = date_tags[i]
        site.results.append(News('https://www.lent.az' + tag['href'], tag.get_text().strip(), date.get_text().strip(), '00:00'))

    return site
コード例 #21
0
    def load(self, cleanup=True):
        self.log.debug("Loading sites...")
        self.loaded = False
        from Site import Site
        if self.sites is None:
            self.sites = {}
        address_found = []
        added = 0
        # Load new adresses
        for address, settings in json.load(open("%s/sites.json" % config.data_dir)).iteritems():
            if address not in self.sites and os.path.isfile("%s/%s/content.json" % (config.data_dir, address)):
                s = time.time()
                self.sites[address] = Site(address, settings=settings)
                self.log.debug("Loaded site %s in %.3fs" % (address, time.time() - s))
                added += 1
            address_found.append(address)

        # Remove deleted adresses
        if cleanup:
            for address in self.sites.keys():
                if address not in address_found:
                    del(self.sites[address])
                    self.log.debug("Removed site: %s" % address)

            # Remove orpan sites from contentdb
            content_db = ContentDb.getContentDb()
            for row in content_db.execute("SELECT * FROM site"):
                address = row["address"]
                if address not in self.sites:
                    self.log.info("Deleting orphan site from content.db: %s" % address)
                    content_db.execute("DELETE FROM site WHERE ?", {"address": address})
                    if address in content_db.site_ids:
                        del content_db.site_ids[address]
                    if address in content_db.sites:
                        del content_db.sites[address]

        if added:
            self.log.debug("SiteManager added %s sites" % added)
        self.loaded = True
コード例 #22
0
    def testVerify():
        from Site import Site
        site = Site("12Hw8rTgzrNo4DSh2AkqwPRqDyTticwJyH")

        content_manager = ContentManager(site)
        print "Loaded contents:", content_manager.contents.keys()

        file = open(
            site.storage.getPath(
                "data/users/1KRxE1s3oDyNDawuYWpzbLUwNm8oDbeEp6/content.json"))
        print "content.json valid:", content_manager.verifyFile(
            "data/users/1KRxE1s3oDyNDawuYWpzbLUwNm8oDbeEp6/content.json",
            file,
            ignore_same=False)

        file = open(
            site.storage.getPath(
                "data/users/1KRxE1s3oDyNDawuYWpzbLUwNm8oDbeEp6/messages.json"))
        print "messages.json valid:", content_manager.verifyFile(
            "data/users/1KRxE1s3oDyNDawuYWpzbLUwNm8oDbeEp6/messages.json",
            file,
            ignore_same=False)
コード例 #23
0
def parseMetbuatAz(query):
    query = querize(query)

    request = Request('https://metbuat.az/news/search?q=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('div', class_='col-sm-8 col-md-9 col-lg-9')

    source_tags = parent.find_all('a', class_ = 'news_box')
    headline_tags = parent.find_all('h4', class_ = 'news_box_ttl')
    date_tags = parent.find_all('span', class_ = 'news_box_date')

    site = Site('Musavat.az')

    for i in range(len(source_tags)):
        source = source_tags[i]
        headline = headline_tags[i]
        date = date_tags[i]
        site.results.append(News('https://metbuat.az' + source['href'], headline.get_text(), date.get_text(), '00:00'))

    return site
コード例 #24
0
    def siteNeedFile(self, address, inner_path):
        from Site import Site
        def checker():
            while 1:
                s = time.time()
                time.sleep(1)
                print "Switch time:", time.time()-s
        gevent.spawn(checker)

        logging.info("Opening a simple connection server")
        global file_server
        from Connection import ConnectionServer
        file_server = ConnectionServer("127.0.0.1", 1234)

        site = Site(address)
        site.announce()
        print site.needFile(inner_path, update=True)
コード例 #25
0
ファイル: SiteManager.py プロジェクト: 52M/ZeroNet
    def need(self, address, all_file=True):
        from Site import Site
        site = self.get(address)
        if not site:  # Site not exist yet
            # Try to find site with differect case
            for recover_address, recover_site in self.sites.items():
                if recover_address.lower() == address.lower():
                    return recover_site

            if not self.isAddress(address):
                return False  # Not address: %s % address
            self.log.debug("Added new site: %s" % address)
            site = Site(address)
            self.sites[address] = site
            if not site.settings["serving"]:  # Maybe it was deleted before
                site.settings["serving"] = True
            site.saveSettings()
            if all_file:  # Also download user files on first sync
                site.download(check_size=True, blind_includes=True)
        else:
            if all_file:
                site.download(check_size=True, blind_includes=True)

        return site
コード例 #26
0
    def need(self, address, all_file=True):
        from Site import Site
        site = self.get(address)
        if not site:  # Site not exist yet
            # Try to find site with differect case
            for recover_address, recover_site in self.sites.items():
                if recover_address.lower() == address.lower():
                    return recover_site

            if not self.isAddress(address):
                return False  # Not address: %s % address
            self.log.debug("Added new site: %s" % address)
            site = Site(address)
            self.sites[address] = site
            if not site.settings["serving"]:  # Maybe it was deleted before
                site.settings["serving"] = True
            site.saveSettings()
            if all_file:  # Also download user files on first sync
                site.download(check_size=True, blind_includes=True)

        return site
コード例 #27
0
ファイル: main.py プロジェクト: CAOLINAN/zeronet_analysis
    def setPrice(self, address, path, price, privatekey=None):
        logging.info("set data price...")
        try:
            price = float(price)
        except:
            logging.error("Error pricing {}: price {} isn't a num.".format(
                path, price))
        from Site import Site
        from Site import SiteManager
        SiteManager.site_manager.load()
        site = Site(address, allow_create=False)

        if not privatekey:  # If no privatekey defined
            from User import UserManager
            user = UserManager.user_manager.get()
            if user:
                site_data = user.getSiteData(address)
                privatekey = site_data.get("privatekey")
            else:
                privatekey = None
            if not privatekey:
                # Not found in users.json, ask from console
                import getpass
                privatekey = getpass.getpass("Private key (input hidden):")
            from Crypt import CryptBitcoin
            privatekey_address = CryptBitcoin.privatekeyToAddress(privatekey)
            if privatekey_address == address:
                if site.price_manger.setPrice(path, price):
                    return True
                else:
                    logging.error(
                        "Error set {}'s price: set failed! Please try again.".
                        format(path))
                    return False
            else:
                logging.error(
                    "Error set {}'s price: error password.".format(path))
                return False
コード例 #28
0
ファイル: main.py プロジェクト: goddess5321/Fuzium
    def siteSign(self, address, privatekey=None, inner_path="content.json", publish=False, remove_missing_optional=False):
        from Site import Site
        from Site import SiteManager
        SiteManager.site_manager.load()
        logging.info("Signing site: %s..." % address)
        site = Site(address, allow_create=False)

        if not privatekey:  # If no privatekey defined
            from User import UserManager
            user = UserManager.user_manager.get()
            if user:
                site_data = user.getSiteData(address)
                privatekey = site_data.get("privatekey")
            else:
                privatekey = None
            if not privatekey:
                # Not found in users.json, ask from console
                import getpass
                privatekey = getpass.getpass("Private key (input hidden):")
        diffs = site.content_manager.getDiffs(inner_path)
        succ = site.content_manager.sign(inner_path=inner_path, privatekey=privatekey, update_changed_files=True, remove_missing_optional=remove_missing_optional)
        if succ and publish:
            self.sitePublish(address, inner_path=inner_path, diffs=diffs)
コード例 #29
0
ファイル: main.py プロジェクト: CAOLINAN/zeronet_analysis
 def deletePrice(self, address, path, privatekey=None):
     logging.info("delete data price...")
     from Site import Site
     from Site import SiteManager
     if not os.path.isdir(os.path.join(config.data_dir, address)):
         logging.error(
             "Error address:{} isn't an address! Please try again!".format(
                 address))
         return False
     # maybe the creater move the file
     # if not os.path.isfile(path):
     #     logging.error("Error path:{} isn't a file! Please try again!".format(path))
     #     return False
     SiteManager.site_manager.load()
     site = Site(address, allow_create=False)
     if site.price_manger.deletePrice(path):
         logging.info("Success delte {}'s price".format(path))
         return True
     else:
         logging.error(
             "Error delete {}'s price: delete failed! Please try again.".
             format(path))
         return False
コード例 #30
0
def parseRealTV(query):
    query = querize(query)
    
    request = Request('https://www.realtv.az/search/?text=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')
    
    parent_tags = file.find_all('h4', class_='card-title gel-pica-bold')
    news_tags = list()

    site = Site("Real TV")
    
    for tag in parent_tags:
        news_tags.append(tag.find('a', href=True))
    
    for i in range(len(news_tags)): 
        tag = news_tags[i]
        site.results.append(News('https://www.lent.az' + tag['href'], tag.get_text().strip(), ' ', '00:00'))

    for r in site.results:
       print(r.source + '|' + r.headline + '|' + r.date)

    return site
コード例 #31
0
ファイル: main.py プロジェクト: davinirjr/ZeroNet
def siteVerify(address):
    from Site import Site
    logging.info("Verifing site: %s..." % address)
    site = Site(address)

    for content_inner_path in site.content_manager.contents:
        logging.info("Verifing %s signature..." % content_inner_path)
        if site.content_manager.verifyFile(content_inner_path,
                                           site.storage.open(
                                               content_inner_path, "rb"),
                                           ignore_same=False) == True:
            logging.info("[OK] %s signed by address %s!" %
                         (content_inner_path, address))
        else:
            logging.error("[ERROR] %s not signed by address %s!" %
                          (content_inner_path, address))

    logging.info("Verifying site files...")
    bad_files = site.storage.verifyFiles()
    if not bad_files:
        logging.info("[OK] All file sha512sum matches!")
    else:
        logging.error("[ERROR] Error during verifying site files!")
コード例 #32
0
def parseAzToday(query):
    query = querize(query)

    request = Request('https://www.aztoday.az/?s=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('ul', class_='penci-wrapper-data penci-grid')
    
    news_tags = parent.find_all('a', class_='penci-image-holder penci-lazy', href=True)
    date_tags = parent.find_all('time', class_='entry-date published')

    site = Site('Aztoday.az')

    for i in range(len(news_tags)): 
        tag = news_tags[i]
        date = date_tags[i]
        site.results.append(News(tag['href'], tag['title'], date.get_text().strip(), '00:00'))

    for r in site.results:
        print(r.source + '|' + r.headline + '|' + r.date)

    return site
コード例 #33
0
def parseAzadliq(query):
    query = querize(query)

    request = Request('https://www.azadliq.org/s?k=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    source_tags = file.find_all('a', class_='img-wrap img-wrap--t-spac img-wrap--size-3 img-wrap--float img-wrap--xs', href=True)
    headline_tags = file.find_all('h4', class_='media-block__title media-block__title--size-3')
    date_tags = file.find_all('span', class_='date date--mb date--size-3')

    site = Site('Azadliq Radiosu')
    
    for i in range(len(source_tags)): 
        source = source_tags[i]
        headline = source['title']
        date = date_tags[i]
        site.results.append(News('https://www.azadliq.org' + source['href'], headline, date.string, '00:00'))

    for r in site.results:
        print(r.source + '|' + r.headline + '|' + r.date)

    return site
コード例 #34
0
def parsePublikaAz(query):
    query = querize(query)

    request = Request('https://publika.az/search.php?query=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('div', class_='page_layout clearfix')

    news_tags = parent.find_all('a', href=True)
    date_tags = parent.find_all('li', class_='date')

    print(len(news_tags))
    print(len(date_tags))

    length = len(news_tags)

    del news_tags[length - 1]
    del news_tags[length - 2]

    i = 0
    
    while (i < len(news_tags)):
        news_tags[i] = date_tags[0]
        i = i + 2

    while date_tags[0] in news_tags:
        news_tags.remove(date_tags[0])

    site = Site('Publika.az')

    for i in range(len(news_tags)): 
        tag = news_tags[i]
        date = date_tags[i]
        site.results.append(News(tag['href'], tag.get_text().strip(), date.get_text().strip(), '00:00'))

    return site
コード例 #35
0
def parseTeleqraf(query):
    query = querize(query)

    request = Request('https://teleqraf.com/search.php?query=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('div', 'col-md-11 col-sm-11')

    source_tags = parent.find_all('a', href=True)
    headline_tags = parent.find_all('h3')
    date_tags = parent.find_all('div', class_='time')

    print(len(source_tags))
    print(len(headline_tags))
    print(len(date_tags))

    print(source_tags)

    length = len(source_tags)

    del source_tags[length - 1]
    del source_tags[length - 2]
    
    site = Site('Teleqraf.com')

    for i in range(len(source_tags)):
        source = source_tags[i]
        headline = headline_tags[i]
        date = date_tags[i]
        site.results.append(News(source['href'], headline.get_text(), date.get_text(), '00:00'))

    for r in site.results:
       print(r.source + '|' + r.headline + '|' + r.date)

    return site
コード例 #36
0
def parseOrduAz(query):
    query = querize(query)

    request = Request('https://ordu.az/index.php?search=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    super_parent = file.find('div', class_='col-md-9 col-sm-12')
    parent = super_parent.find('div', class_='row')

    source_tags = parent.find_all('a', href=True)
    headline_tags = parent.find_all('div', class_='news-title')
    
    site = Site('Ordu.az')

    for i in range(len(source_tags)): 
        source = source_tags[i]
        headline = headline_tags[i]
        site.results.append(News(source['href'], headline.get_text().strip(), '00.00.0000', '00:00'))

    for r in site.results:
        print(r.source + '|' + r.headline + '|' + r.date)

    return site
コード例 #37
0
def parseAxarAz(query):
    query = querize(query)

    request = Request('https://axar.az/search.php?query=' + query, None, HEADERS)
    source = urlopen(request)
    file = bs.BeautifulSoup(source, 'lxml')

    parent = file.find('div', class_='newsPlace')

    news_tags = parent.find_all('a', href=True)
    date_tags = file.find_all('div', {'id' : 'cat_news_info'})
   
    length = len(news_tags)
    del news_tags[length - 1]
    del news_tags[length - 2]

    i = 1

    while (i < len(date_tags)):
        date_tags[i] = 'x'
        i = i + 2

    while 'x' in date_tags:
        date_tags.remove('x')
    
    site = Site('Axar.az')
    
    for i in range(len(news_tags)): 
        tag = news_tags[i]
        date = date_tags[i]
        site.results.append(News(tag['href'], tag.get_text(), date.get_text(), '00:00'))

    for r in site.results:
        print(r.source + '|' + r.headline + '|' + r.date)

    return site
コード例 #38
0
ファイル: main.py プロジェクト: volker48/ZeroNet
def siteCreate():
    logging.info("Generating new privatekey...")
    from src.Crypt import CryptBitcoin
    privatekey = CryptBitcoin.newPrivatekey()
    logging.info(
        "----------------------------------------------------------------------"
    )
    logging.info("Site private key: %s" % privatekey)
    logging.info(
        "                  !!! ^ Save it now, required to modify the site ^ !!!"
    )
    address = CryptBitcoin.privatekeyToAddress(privatekey)
    logging.info("Site address:     %s" % address)
    logging.info(
        "----------------------------------------------------------------------"
    )

    while True:
        if raw_input("? Have you secured your private key? (yes, no) > "
                     ).lower() == "yes":
            break
        else:
            logging.info(
                "Please, secure it now, you going to need it to modify your site!"
            )

    logging.info("Creating directory structure...")
    from Site import Site
    os.mkdir("data/%s" % address)
    open("data/%s/index.html" % address, "w").write("Hello %s!" % address)

    logging.info("Creating content.json...")
    site = Site(address)
    site.signContent(privatekey)
    site.settings["own"] = True
    site.saveSettings()

    logging.info("Site created!")
コード例 #39
0
def site(request):
    con = pymysql.connect(host='localhost',
                          user='******',
                          password='',
                          db='dan_py',
                          charset='utf8mb4',
                          autocommit=True,
                          cursorclass=pymysql.cursors.DictCursor)
    SITE = Site()
    SITE.db = con.cursor()
    path = request.match_info.get('url', '')
    SITE.path = path
    SITE.p = path.split('/')
    i = len(SITE.p)
    while i < 7:
        SITE.p.append('')
        i += 1
    SITE.request = request

    return SITE
コード例 #40
0
    def siteNeedFile(self, address, inner_path):
        from Site import Site
        from Site import SiteManager
        SiteManager.site_manager.load()

        def checker():
            while 1:
                s = time.time()
                time.sleep(1)
                print "Switch time:", time.time() - s
        gevent.spawn(checker)

        logging.info("Opening a simple connection server")
        global file_server
        from File import FileServer
        file_server = FileServer("127.0.0.1", 1234)
        file_server_thread = gevent.spawn(file_server.start, check_sites=False)

        site = Site(address)
        site.announce()
        print site.needFile(inner_path, update=True)
コード例 #41
0
ファイル: LifeVC.py プロジェクト: chenzhenguo/daka
	def __init__(self):
		Site.__init__(self,sitename="LifeVC")
		self.LOGIN_URL = "https://account.lifevc.com/account/login"
コード例 #42
0
ファイル: Phantom_Ui.py プロジェクト: kustomzone/phantom
class Phantom_Ui(object):

    def __init__(self):
        self.error_msg = Error_Msg.Error_Msg()
        self.run_method = Run_Method.Run_Method()

    def create_phantom_site(self):

        from Config import config
        from Crypt import CryptBitcoin
        from Site import Site
        import os

        self.config.parse(silent=True)
        if not self.config.arguments:
            self.config.parse()

        self.privatekey = CryptBitcoin.newPrivatekey()
        address = CryptBitcoin.privatekeyToAddress(self.privatekey)

        try:
            os.mkdir("%s/%s" % (self.config.data_dir, address))
            open("%s/%s/index.html" % (self.config.data_dir, address), "w").write("Hello %s!" % address)
        except Exception as e:
            return self.error_msg.error_response("err_create_sitedir")
    
        try:
            self.site = Site(address)
            self.site.content_manager.sign(privatekey=self.privatekey, extend={"postmessage_nonce_security": True})
            self.site.settings["own"] = True
            self.site.saveSettings()
        except Exception as e:
            return self.error_msg.error_response("err_create_site")
        return {"jsonrpc": "2.0", "id": "1", "result": ["true", str(address), str(privatekey)]}


    def validate_postdata(self,postdata):


        try:
            """ 
            Convert the HTTP body json string into a dictionary. A non valid json string will return false.
            """
            postparams = json.loads(postdata)
        except Exception as e:
            return self.error_msg.error_response("invalid_json_req")

        if 'jsonrpc' in postparams and not postparams['jsonrpc'] == '2.0':
            return self.error_msg.error_response("invalid_json_ver")

        if 'method' in postparams and len(postparams['method']) == 0:
            return self.error_msg.error_response("no_method")

        if not 'params' in postparams:
            return self.error_msg.error_response("missing_params")

        return postparams


    def run_method(self,postparams):

        self.res = self.run_method.execute(postparams)
        return self.res


    def get_shiftbase(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_shiftbase()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")


    def get_peercount(self,postparams):
    
        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_peercount()
                if 'result' in self.res:
                    self.res['result'] = str(int(self.res['result'], 16))
                return self.res

            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")



    def get_blocknumber(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_blocknumber()
                if 'result' in self.res:
                    self.res['result'] = str(int(self.res['result'], 16))
                return self.res

            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")


    def get_block_data(self,postparams):

        if len(postparams['params']) == 2:
            if postparams['params'][1] == "true" or postparams['params'][1] == "false":
                try:
                    self.client = IPC_Client.Client()
                    self.res = self.client.get_block_data(postparams['params'][0], postparams['params'][1])
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
            return self.error_msg.error_response("invalid_parameters")
        return self.error_msg.error_response("missing_params")


    def rr_ptr(self,postparams):

        if len(postparams['params']) == 1:
            if not postparams['params'][0][:-6].isalnum() and not postparams[param].endswith('.shift'):
                return self.error_msg.error_response("invalid_domain")
            else:
                pass

        return self.error_msg.error_response("")


    def get_accounts(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_accounts()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")


    def get_balance(self,postparams):

        if len(postparams['params']) == 2:
            self.addr = postparams['params'][0]
            self.when = postparams['params'][1]

            try:
                int(self.addr, 16) 
            except ValueError as e:
                return self.error_msg.error_response("invalid_wallet_addr")

            if self.when == "latest" or self.when == "pending" or self.when == "earliest":

                try:
                    self.client = IPC_Client.Client()
                    self.res = self.client.get_balance(self.addr, self.when)
                    if 'result' in self.res:
                        self.res['result'] = str(int(self.res['result'], 16))
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")
            
 

    def sign_publish_site(self,postparams):

        from Site import Site

        if not len(postparams['params']) == 2 and not len(postparams['params'][0]) == 34:
            return self.error_msg.error_response("sign_missing_params")


        address = postparams['params'][0]
        privatekey = postparams['params'][1]
        site = Site(address, allow_create=False)

        try:
            inner_path="content.json"
            success = site.content_manager.sign(inner_path, privatekey=privatekey, update_changed_files=True)
            if success:
                publisher = main.Actions()
                publisher.sitePublish(address, inner_path=inner_path)
        except Exception as e:
            print e
            return self.error_msg.error_response("err_sign_site")
        

        return {"jsonrpc": "2.0", "id": "1", "result": ["true", str(address)]}



    def unlock_account(self, addr, password):

        try:
            int(addr, 16)
        except ValueError as e:
            return self.error_msg.error_response("invalid_wallet_addr")

        if not len(addr) == 42:
            return self.error_msg.error_response("invalid_wallet_addr")

        elif not len(password) > 0:
            return self.error_msg.error_response("empty_password")

        else:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.unlock_account(addr, password)
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")


    def lock_account(self, addr):

        try:
            int(addr, 16)
        except ValueError as e:
            return self.error_msg.error_response("invalid_wallet_addr")

        try:
            self.client = IPC_Client.Client()
            self.res = self.client.lock_account(addr)
            return self.res
        except Exception as e:
            return self.error_msg.error_response("ipc_call_error")


    def create_site(self,postparams):

        if len(postparams['params']) == 0:
            return self.create_phantom_site()

        return self.error_msg.error_response("")


    def create_account(self,postparams):

        if len(postparams['params']) == 1:
            if len(postparams['params'][0]) == 0:
                return self.error_msg.error_response("empty_password")
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.create_account(postparams['params'][0])
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")


    def net_listening(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = client.net_listening()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")


    def send_transaction(self,postparams):

        if len(postparams['params']) == 1:
            self.pd = postparams['params'][0]
            try:
                int(self.pd['from'], 16)
                int(self.pd['to'], 16)
            except ValueError as e:
                return self.error_msg.error_response("invalid_wallet_addr")

            if not len(self.pd['from']) == 42 or not len(self.pd['to']) == 42:
                self.error_msg.error_response("invalid_wallet_addr")

            try:
                self.pd['amount'] = int(float(self.pd['amount'])*1000000000000000000)
                self.amount = "0x" + format(self.pd['amount'], 'x')
            except Exception as e:
                return self.error_msg.error_response("invalid_amount")

            if 'data' in self.pd and len(self.pd['data']) > 0: self.data = self.pd['data']
            else: self.data = False

            if 'nrg' in self.pd and len(self.pd['nrg']) > 0: self.nrg = self.pd['nrg']
            else: self.nrg = False

            self.client = IPC_Client.Client()

            if 'password' in self.pd and len(self.pd['password']) == 0:
                return self.error_msg.error_response("empty_password")
            else:
                self.res = self.client.unlock_account(self.pd['from'], self.pd['password'])

            try:
                self.res = self.client.send_transaction(self.pd['from'], self.pd['to'], self.amount, self.nrg, self.data)
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")

            return self.res

    def send_rawtransaction(self,postparams):

        if len(postparams['params']) == 1:
            try:
                int(postparams['params'][0], 16)
            except Exception as e:
                self.error_msg.error_response("invalid_hex_string")
        
            try:
                self.res = self.client.send_transaction(postparams['params'][0])
                return res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("invalid_parameters")


    def create_shh_filter(self,postparams):
    
        if len(postparams['params']) == 1:
            self.pd = postparams['params'][0]
            if 'to' in self.pd and 'topics' in self.pd:
                try:
                    int(self.pd['to'], 16)
                except:
                    return self.error_msg.error_response("invalid_hex_string")

                if self.pd['topics'] == "":
                    return self.error_msg.error_response("err_create_filter")
                params = {"to": str(self.pd['to']), "topics": [str(self.pd['topics'][0].encode("hex"))]}
                self.client = IPC_Client.Client()
                try:
                    self.res = self.client.create_shh_filter(params)
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")


    def new_message_ident(self,postparams):

        if len(postparams['params']) == 0:
            self.client = self.IPC_Client.Client()
            try:
                self.res = client.new_message_ident()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")


    def message_ident_exists(self,postparams):
        if len(postparams['params']) == 1:
            try:
                int(postparams['params'][0], 16)
            except:
                self.error_msg.error_response("invalid_hex_string")

            self.client = IPC_Client.Client()
            try:
                self.res = self.client.message_ident_exists(postparams['params'][0])
                return self.res 
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")


    def send_message(self,postparams):

        if len(postparams['params']) == 1:
            self.pd = postparams['params'][0]

            if 'to' in self.pd and 'message' in self.pd and self.pd['message'] != "":
                try:
                    int(self.pd['to'], 16)
                except:
                    self.error_msg.error_response("invalid_hex_string")

                self.from_ident = self.new_message_ident({'params':''})
                if 'result' in self.from_ident and len(self.from_ident['result']) == 2:
                    return self.error_msg.error_response("err_gen_ident")

                self.pd['from'] = self.from_ident['result']
                self.pd['topics'] = ['{"type":"c","store-encrypted":"true"}'.encode("hex")]
                self.pd['priority'] = "0x64"
                self.pd['ttl'] = "0x64"
                self.pd['message'] = self.pd['message'].encode("hex")

                """ Create filter to wait for incoming answers. Use postparams with the unhexed strings. """
                self.res  = self.create_shh_filter(postparams)

                try:
                    int(self.res['result'], 16)
                except:
                    return self.error_msg.error_response("err_create_filter")

                self.phantomdb = self.Phantom_Db.PhantomDb()
                self.store = {'to':self.pd['to'], 'filter_id' : int(self.res['result'], 16)}
                res_datastore = phantomdb.store_filter(store)
                if not self.res_datastore:
                    return self.error_msg.error_response("err_store_data")
                
                try:
                    self.client = IPC_Client.Client()
                    self.res = self.client.send_message(self.pd)
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")


    def get_shh_messages(self,postparams):
    
        if len(postparams['params']) == 1:
            if postparams['params'][0] == "latest_filter":
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.get_latest_filter()
            
                if self.res == False:
                    return self.error_msg.error_response("err_select_data")
                if len(self.res) == 0:
                    return self.error_msg.error_response("no_filters")

                """ By now "res" will always contain a list of tuples that it got from sqlite3 """
                self.filter_id = hex(self.res[0][0])

            else:
                try:
                    self.filter_id = hex(int(postparams['params'][0]))
                except:
                    return self.error_msg.error_response("invalid_parameters")
            
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_shh_messages(filter_id)
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")


    def get_transaction_history(self,postparams):
    
        if len(postparams['params']) == 1:
            try:
                int(postparams['params'][0], 16)
            except:
                self.error_msg.error_response("invalid_hex_string")

            if not len(postparams['params'][0]) == 42: 
                self.error_msg.error_response("invalid_wallet_addr")

            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.get_transaction_hist(postparams['params'][0])
                if self.res and len(self.res) >= 1:
                    return {"jsonrpc": "2.0", "id": "1", "result": list(self.res)}
                return {"jsonrpc": "2.0", "id": "1", "result": []}
            except Exception as e:
                return self.error_msg.error_response("err_trans_hist")
        return self.error_msg.error_response("missing_params")


    def store_address_book(self,postparams):
    
        if len(postparams['params']) == 2:
            try:
                int(postparams['params'][0], 16)
            except:
                self.error_msg.error_response("invalid_hex_string")

            if not len(postparams['params'][0]) == 42: 
                self.error_msg.error_response("invalid_wallet_addr")

            if len(postparams['params'][1]) > 0:
                try:
                    self.phantomdb = Phantom_Db.PhantomDb()
                    res = self.phantomdb.store_address_book(postparams['params'][0], postparams['params'][1])
                    if res:
                        return {"jsonrpc": "2.0", "id": "1", "result": ["true"]}
                except Exception as e:
                    return self.error_msg.error_response("err_store_addrbook")
        return self.error_msg.error_response("missing_params")


    def del_address_book(self,postparams):
    
        if len(postparams['params']) == 1:
            try:
                int(postparams['params'][0], 16)
            except:
                self.error_msg.error_response("invalid_hex_string")

            if not len(postparams['params'][0]) == 42:
                self.error_msg.error_response("invalid_wallet_addr")

            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = phantomdb.del_address_book(postparams['params'][0])
                if self.res:
                    return {"jsonrpc": "2.0", "id": "1", "result": ["true"]}
            except Exception as e:
                return self.error_msg.error_response("err_del_addrbook")
        return self.error_msg.error_response("missing_params")


    def get_address_book(self,postparams):
    
        if len(postparams['params']) == 0:
            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.get_address_book()
                if self.res and len(self.res) >= 1:
                    return {"jsonrpc": "2.0", "id": "1", "result": list(self.res)}
                return {"jsonrpc": "2.0", "id": "1", "result": []}
            except Exception as e:
                return self.error_msg.error_response("err_addr_book")
        return self.error_msg.error_response("no_params_allowed")


    def get_balance_by_block(self,postparams):
    
        if len(self.postparams['params']) == 2:

            try:
                int(self.postparams['params'][0], 16)
            except:
                self.error_msg.error_response("invalid_hex_string")

            if not len(self.postparams['params'][0]) == 42:
                self.error_msg.error_response("invalid_wallet_addr")

            if type(self.postparams['params'][1]) is not list:
                return self.error_msg.error_response("missing_params")

            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.results = []

                for block_number in postparams['params'][1]:
                    if type(postparams['params'][1][0]) is not int:
                        self.error_msg.error_response("invalid_block_number")

                    self.res = self.phantomdb.get_balance_by_block(postparams['params'][0],block_number)
                    if self.res and len(self.res) >= 1:
                        self.results.append(self.res)
            except Exception as e:
                return self.error_msg.error_response("err_get_balance_block")

            return {"jsonrpc": "2.0", "id": "1", "result": self.results}
        return self.error_msg.error_response("missing_params")


    def create_static_nodefile(self):

        self.client = IPC_Client.Client()
        if self.client.create_static_nodefile():
            pass
        else:
            pass
  

    def run(self,postdata):
        self.res = self.validate_postdata(postdata)

        if 'result' in self.res and self.res['result'][0] == "false":
            return self.res
        self.http_response = self.run_method.execute(self.res)
        return self.http_response
コード例 #43
0
 def __init__(self, num_operations, scout_bee=False):
     self.scout_bee = scout_bee
     self.site = Site(num_operations)
コード例 #44
0
ファイル: Mafengwo.py プロジェクト: ictar/daka
 def __init__(self):
     Site.__init__(self, sitename="Mafengwo")
     self.LOGIN_URL = "https://passport.mafengwo.cn/login-popup.html"
コード例 #45
0
ファイル: main.py プロジェクト: davinirjr/ZeroNet
def siteNeedFile(address, inner_path):
    from Site import Site
    site = Site(address)
    site.announce()
    print site.needFile(inner_path, update=True)
コード例 #46
0
ファイル: Readcolor.py プロジェクト: chenzhenguo/daka
	def __init__(self):
		Site.__init__(self,sitename="Readcolor")
		self.LOGIN_URL = r'https://login.sina.com.cn/sso/login.php?client=ssologin.js(v1.4.15)'
コード例 #47
0
ファイル: SFexpress.py プロジェクト: chenzhenguo/daka
	def __init__(self):
		Site.__init__(self,sitename="SFexpress")
		self.LOGIN_URL = "https://i.sf-express.com/sso/login"
コード例 #48
0
 def __init__(self, point, center):
     Site.__init__(self, point)
     self.center = center
コード例 #49
0
ファイル: Hujiang.py プロジェクト: chenzhenguo/daka
	def __init__(self):
		Site.__init__(self,sitename="Hujiang")
		self.INDEX_URL = "http://bulo.hujiang.com/"
		self._callback = "jQuery18307142652559559792_1442495521490"
		self.LOGIN_URL = "http://pass.hujiang.com/quick/synclogin.aspx"
		self.TOKEN_URL = "http://pass.hujiang.com/quick/account/?callback=%s&account=%s&password=%s&code=&act=loginverify&source=bulo_anon&_=%s"
コード例 #50
0
    def __init__(self):
        # Domain is (0,3)x(0,3)X(0,3) length unit
        x_min, y_min, z_min = 1, 1, 1
        x_max, y_max, z_max = 4, 4, 4

        # Single block with 4x4x4 sites, 1 length unit apart
        self.size_in_blocks = (1, 1, 1)
        self.sites_along_block = 6
        self.space_step = 1

        sites = []
        # Requirement: Sites are striped with the z coordinate changing most frequently, i.e. the z coordinate represents the least significant part of the site index within the block.
        for index in np.ndindex(3 * (self.sites_along_block, )):
            x_index, y_index, z_index = index
            if ((x_index < x_min or x_index > x_max)
                    or (y_index < y_min or y_index > y_max)
                    or (z_index < z_min or z_index > z_max)):
                # This site is solid
                sites.append(Site(Site.solid_site, [], None))
            else:
                links = []
                for direction in self.lattice_directions:
                    link_type = Link.no_boundary

                    # Assign an iolet id (the first iolet in the config xml file)
                    iolet_index = 0

                    # In this example, links that cross both wall and inlet/outlet (like the 8 corners of the cube) will be considered non-wall because of the ordering of the if statements below
                    if x_index == x_min and direction[0] == -1:
                        link_type = Link.wall
                    if x_index == x_max and direction[0] == 1:
                        link_type = Link.wall
                    if y_index == y_min and direction[1] == -1:
                        link_type = Link.wall
                    if y_index == y_max and direction[1] == 1:
                        link_type = Link.wall
                    if z_index == z_min and direction[2] == -1:
                        link_type = Link.inlet
                    if z_index == z_max and direction[2] == 1:
                        link_type = Link.outlet

                    # Assume walls are half a lattice away
                    wall_distance = 0.5

                    # iolet_index and wall_distance will be ignored when meaningless
                    links.append(Link(link_type, wall_distance, iolet_index))

                # For sites at the intersection of two cube faces considered wall (i.e. perpendicular to the x or y
                # axes), we arbitrarily choose the normal to lie along the y axis. The logic below must be consistent
                # with Code/unittests/FourCubeLatticeData.h
                normal = None
                if x_index == x_min:
                    normal = np.array([-1, 0, 0])
                if x_index == x_max:
                    normal = np.array([1, 0, 0])
                if y_index == y_min:
                    normal = np.array([0, -1, 0])
                if y_index == y_max:
                    normal = np.array([0, 1, 0])

                sites.append(Site(Site.fluid_site, links, normal))

        # Requirement: Blocks are striped with the z coordinate changing most frequently (i.e. the z coordinate represents the least significant part of the block index) then y and x slowest.
        # This geometry is made of a single block with the sites defined above
        self.blocks = [Block(sites)]

        # Let the parent class do the rest
        super(FourCube, self).__init__()
コード例 #51
0
ファイル: main.py プロジェクト: Lucas-Developer/ZeroNet
    def sitePublish(self,
                    address,
                    peer_ip=None,
                    peer_port=15441,
                    inner_path="content.json",
                    diffs={}):
        global file_server
        from Site import Site
        from Site import SiteManager
        from File import FileServer  # We need fileserver to handle incoming file requests
        from Peer import Peer
        SiteManager.site_manager.load()

        logging.info("Loading site...")
        site = Site(address, allow_create=False)
        site.settings[
            "serving"] = True  # Serving the site even if its disabled

        logging.info("Creating FileServer....")
        file_server = FileServer()
        site.connection_server = file_server
        file_server_thread = gevent.spawn(
            file_server.start,
            check_sites=False)  # Dont check every site integrity
        time.sleep(0.001)

        if not file_server_thread.ready():
            # Started fileserver
            file_server.openport()
            if peer_ip:  # Announce ip specificed
                site.addPeer(peer_ip, peer_port)
            else:  # Just ask the tracker
                logging.info("Gathering peers from tracker")
                site.announce()  # Gather peers
            published = site.publish(5, inner_path,
                                     diffs=diffs)  # Push to peers
            if published > 0:
                time.sleep(3)
                logging.info("Serving files (max 60s)...")
                gevent.joinall([file_server_thread], timeout=60)
                logging.info("Done.")
            else:
                logging.info(
                    "No peers found, sitePublish command only works if you already have visitors serving your site"
                )
        else:
            # Already running, notify local client on new content
            logging.info("Sending siteReload")
            my_peer = Peer("127.0.0.1", config.fileserver_port)
            logging.info(
                my_peer.request("siteReload", {
                    "site": site.address,
                    "inner_path": inner_path
                }))
            logging.info("Sending sitePublish")
            logging.info(
                my_peer.request("sitePublish", {
                    "site": site.address,
                    "inner_path": inner_path,
                    "diffs": diffs
                }))
            logging.info("Done.")
コード例 #52
0
ファイル: main.py プロジェクト: rarbg/ZeroNet
 def siteNeedFile(self, address, inner_path):
     from Site import Site
     site = Site(address)
     site.announce()
     print site.needFile(inner_path, update=True)
コード例 #53
0
ファイル: conftest.py プロジェクト: Deliverability/ZeroNet
def site():
    site = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
    return site
コード例 #54
0
ファイル: Xiami.py プロジェクト: chenzhenguo/daka
	def __init__(self):
		Site.__init__(self,sitename="Xiami")
		self.LOGIN_URL = r"https://login.xiami.com/web/login"
コード例 #55
0
ファイル: Phantom_Ui.py プロジェクト: shiftcurrency/phantom
class Phantom_Ui(object):

    def __init__(self):
        self.error_msg = Error_Msg.Error_Msg()
        self.run_method = Run_Method.Run_Method()

    def create_phantom_site(self):

        from Config import config
        from Crypt import CryptBitcoin
        from Site import Site
        import os

        config.parse(silent=True)
        if not config.arguments:
            config.parse()

        self.private_key = CryptBitcoin.newPrivatekey()
        self.address = CryptBitcoin.privatekeyToAddress(self.private_key)

        try:
            os.mkdir("%s/%s" % (config.data_dir, self.address))
            open("%s/%s/index.html" % (config.data_dir, self.address), "w").write("Hello %s!" % self.address)
        except Exception as e:
            return self.error_msg.error_response("err_create_sitedir")
    
        try:
            self.site = Site(self.address)
            self.site.content_manager.sign(privatekey=self.private_key, extend={"postmessage_nonce_security": True})
            self.site.settings["own"] = True
            self.site.saveSettings()
        except Exception as e:
            print e
            return self.error_msg.error_response("err_create_site")
        return {"jsonrpc": "2.0", "id": "1", "result": ["true", str(self.address), str(self.private_key)]}

    def validate_postdata(self,postdata):


        try:
            """ 
            Convert the HTTP body json string into a dictionary. A non valid json string will return false.
            """
            postparams = json.loads(postdata)
        except Exception as e:
            print e
            return self.error_msg.error_response("invalid_json_req")

        if 'jsonrpc' in postparams and not postparams['jsonrpc'] == '2.0':
            return self.error_msg.error_response("invalid_json_ver")

        if 'method' in postparams and len(postparams['method']) == 0:
            return self.error_msg.error_response("no_method")

        if not 'params' in postparams:
            return self.error_msg.error_response("missing_params")

        return postparams

    def run_method(self,postparams):

        self.res = self.run_method.execute(postparams)
        return self.res

    def get_shiftbase(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_shiftbase()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")

    def get_peercount(self,postparams):
    
        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_peercount()
                if 'result' in self.res:
                    self.res['result'] = str(int(self.res['result'], 16))
                return self.res

            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")

    def get_blocknumber(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_blocknumber()
                if 'result' in self.res:
                    self.res['result'] = str(int(self.res['result'], 16))
                return self.res

            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")

    def get_block_data(self,postparams):

        if len(postparams['params']) == 2:
            if postparams['params'][1] == "true" or postparams['params'][1] == "false":
                try:
                    self.client = IPC_Client.Client()
                    self.res = self.client.get_block_data(postparams['params'][0], postparams['params'][1])
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
            return self.error_msg.error_response("invalid_parameters")
        return self.error_msg.error_response("missing_params")

    def validate_domain(self,domain):

        try:
            if not domain.endswith('.shift') or not domain[:-6].isalnum():
                return False
        except Exception as e:
            return False
        return True

    def get_accounts(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_accounts()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")

    def get_balance(self,postparams):

        if len(postparams['params']) == 2:
            self.addr = postparams['params'][0]
            self.when = postparams['params'][1]

            if not self.verify_wallet_addr(self.addr):
                return self.error_msg.error_response("invalid_wallet_addr")

            if self.when == "latest" or self.when == "pending" or self.when == "earliest":

                try:
                    self.client = IPC_Client.Client()
                    self.res = self.client.get_balance(self.addr, self.when)
                    if 'result' in self.res:
                        self.res['result'] = str(int(self.res['result'], 16))
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")

    def sign_publish_site(self,postparams):

        from Site import Site

        if not len(postparams['params']) == 2 or not len(postparams['params'][0]) == 34:
            return self.error_msg.error_response("sign_missing_params")


        address = postparams['params'][0]
        privatekey = postparams['params'][1]
        site = Site(address, allow_create=False)

        try:
            inner_path="content.json"
            success = site.content_manager.sign(inner_path, privatekey=privatekey, update_changed_files=True)
            if success:
                publisher = main.Actions()
                publisher.sitePublish(address, inner_path=inner_path)
        except Exception as e:
            print e
            return self.error_msg.error_response("err_sign_site")
        

        return {"jsonrpc": "2.0", "id": "1", "result": ["true", str(address)]}

    def unlock_account(self, addr, password):

        if not self.verify_wallet_addr(addr):
            return self.error_msg.error_response("invalid_wallet_addr")

        elif not len(password) > 0:
            return self.error_msg.error_response("empty_password")

        else:
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.unlock_account(addr, password)
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")

    def lock_account(self, addr):

        if not self.verify_wallet_addr(addr):
            return self.error_msg.error_response("invalid_wallet_addr")

        try:
            self.client = IPC_Client.Client()
            self.res = self.client.lock_account(addr)
            return self.res
        except Exception as e:
            return self.error_msg.error_response("ipc_call_error")

    def create_site(self,postparams):

        if len(postparams['params']) == 0:
            return self.create_phantom_site()

        return self.error_msg.error_response("")

    def create_account(self,postparams):

        if len(postparams['params']) == 1:
            if len(postparams['params'][0]) == 0:
                return self.error_msg.error_response("empty_password")
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.create_account(postparams['params'][0])
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")

    def net_listening(self,postparams):

        if len(postparams['params']) == 0:
            try:
                self.client = IPC_Client.Client()
                self.res = client.net_listening()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")

    def verify_wallet_addr(self, addr):
        try:
            int(addr, 16) 
        except ValueError as e:
            return False

        if not len(addr) >= 40: 
            return False
        return True 

    def send_transaction(self,postparams):

        if len(postparams['params']) == 1:
            self.pd = postparams['params'][0]
            
            if not self.verify_wallet_addr(postparams['params'][0]['from']):
                return self.error_msg.error_response("invalid_wallet_addr")

            if not 'to' in self.pd:
                self.pd['to'] = False

            if 'amount' in self.pd:
                try:
                    self.pd['amount'] = int(float(self.pd['amount'])*1000000000000000000)
                    self.pd['amount'] = "0x" + format(self.pd['amount'], 'x')
                except Exception as e:
                    print e
                    return self.error_msg.error_response("invalid_amount")

            if 'data' in self.pd and len(self.pd['data']) == 0:
                self.pd['data'] = False

            if 'gas' in self.pd and len(self.pd['gas']) == 0:
                """ Default gas amount for a transaction """
                self.pd['gas'] = '30000'

            if 'password' in self.pd and len(self.pd['password']) == 0:
                return self.error_msg.error_response("empty_password")

            """ TODO: check unlock success """
            self.res = self.unlock_account(self.pd['from'], self.pd['password'])

            """ Tag the transaction with either create_contract or send_transaction.
                create_contract does not have a reciever """
            if 'method' not in self.pd:
                self.pd['method'] = 'send_transaction'

            self.client = IPC_Client.Client()

            try:
                self.res = self.client.send_transaction(self.pd)
            except Exception as e:
                print e
                return self.error_msg.error_response("ipc_call_error")

            return self.res

    def send_rawtransaction(self,postparams):

        if len(postparams['params']) == 1:
            try:
                int(postparams['params'][0], 16)
            except Exception as e:
                return self.error_msg.error_response("invalid_hex_string")
        
            try:
                self.res = self.client.send_transaction(postparams['params'][0])
                return res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("invalid_parameters")

    def create_shh_filter(self,postparams):
    
        if len(postparams['params']) == 1:
            self.pd = postparams['params'][0]
            if 'to' in self.pd and 'topics' in self.pd:

                if not self.verify_wallet_addr(self.pd['to']):
                    return self.error_msg.error_response("invalid_wallet_addr")

                if self.pd['topics'] == "":
                    return self.error_msg.error_response("err_create_filter")
                params = {"to": str(self.pd['to']), "topics": [str(self.pd['topics'][0].encode("hex"))]}
                self.client = IPC_Client.Client()
                try:
                    self.res = self.client.create_shh_filter(params)
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")

    def new_message_ident(self,postparams):

        if len(postparams['params']) == 0:
            self.client = IPC_Client.Client()
            try:
                self.res = client.new_message_ident()
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("no_params_allowed")

    def message_ident_exists(self,postparams):
        if len(postparams['params']) == 1:
            try:
                int(postparams['params'][0], 16)
            except:
                return self.error_msg.error_response("invalid_hex_string")

            self.client = IPC_Client.Client()
            try:
                self.res = self.client.message_ident_exists(postparams['params'][0])
                return self.res 
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")

    def send_message(self,postparams):

        if len(postparams['params']) == 1:
            self.pd = postparams['params'][0]

            if 'to' in self.pd and 'message' in self.pd and self.pd['message'] != "":

                if not self.verify_wallet_addr(self.pd['to']):
                    return self.error_msg.error_response("invalid_wallet_addr")


                self.from_ident = self.new_message_ident({'params':''})
                if 'result' in self.from_ident and len(self.from_ident['result']) == 2:
                    return self.error_msg.error_response("err_gen_ident")

                self.pd['from'] = self.from_ident['result']
                self.pd['topics'] = ['{"type":"c","store-encrypted":"true"}'.encode("hex")]
                self.pd['priority'] = "0x64"
                self.pd['ttl'] = "0x64"
                self.pd['message'] = self.pd['message'].encode("hex")

                """ Create filter to wait for incoming answers. Use postparams with the unhexed strings. """
                self.res  = self.create_shh_filter(postparams)

                try:
                    int(self.res['result'], 16)
                except:
                    return self.error_msg.error_response("err_create_filter")

                self.phantomdb = Phantom_Db.PhantomDb()
                self.store = {'to':self.pd['to'], 'filter_id' : int(self.res['result'], 16)}
                res_datastore = phantomdb.store_filter(store)
                if not self.res_datastore:
                    return self.error_msg.error_response("err_store_data")
                
                try:
                    self.client = IPC_Client.Client()
                    self.res = self.client.send_message(self.pd)
                    return self.res
                except Exception as e:
                    return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")

    def get_shh_messages(self,postparams):
    
        if len(postparams['params']) == 1:
            if postparams['params'][0] == "latest_filter":
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.get_latest_filter()
            
                if self.res == False:
                    return self.error_msg.error_response("err_select_data")
                if len(self.res) == 0:
                    return self.error_msg.error_response("no_filters")

                """ By now "res" will always contain a list of tuples that it got from sqlite3 """
                self.filter_id = hex(self.res[0][0])

            else:
                try:
                    self.filter_id = hex(int(postparams['params'][0]))
                except:
                    return self.error_msg.error_response("invalid_parameters")
            
            try:
                self.client = IPC_Client.Client()
                self.res = self.client.get_shh_messages(filter_id)
                return self.res
            except Exception as e:
                return self.error_msg.error_response("ipc_call_error")
        return self.error_msg.error_response("missing_params")

    def get_transaction_history(self,postparams):
    
        if len(postparams['params']) == 1:

            if not self.verify_wallet_addr(postparams['params'][0]):
                return self.error_msg.error_response("invalid_wallet_addr")

            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.get_transaction_hist(postparams['params'][0][2:])
                if self.res and len(self.res) >= 1:
                    return {"jsonrpc": "2.0", "id": "1", "result": list(self.res)}
                return {"jsonrpc": "2.0", "id": "1", "result": []}
            except Exception as e:
                return self.error_msg.error_response("err_trans_hist")
        return self.error_msg.error_response("missing_params")

    def store_address_book(self,postparams):
    
        if len(postparams['params']) == 2:

            if not self.verify_wallet_addr(postparams['params'][0]):
                return self.error_msg.error_response("invalid_wallet_addr")

            if len(postparams['params'][1]) > 0:
                try:
                    self.phantomdb = Phantom_Db.PhantomDb()
                    self.res = self.phantomdb.store_address_book(postparams['params'][0][2:], postparams['params'][1])
                    if self.res:
                        return {"jsonrpc": "2.0", "id": "1", "result": ["true"]}
                except Exception as e:
                    return self.error_msg.error_response("err_store_addrbook")
        return self.error_msg.error_response("missing_params")

    def del_address_book(self,postparams):
    
        if len(postparams['params']) == 1:

            if not self.verify_wallet_addr(postparams['params'][0]):
                return self.error_msg.error_response("invalid_wallet_addr")

            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.del_address_book(postparams['params'][0][2:])
                if self.res:
                    return {"jsonrpc": "2.0", "id": "1", "result": ["true"]}
            except Exception as e:
                return self.error_msg.error_response("err_del_addrbook")
        return self.error_msg.error_response("missing_params")

    def get_address_book(self,postparams):
    
        if len(postparams['params']) == 0:
            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.res = self.phantomdb.get_address_book()
                if self.res and len(self.res) >= 1:
                    return {"jsonrpc": "2.0", "id": "1", "result": list(self.res)}
                return {"jsonrpc": "2.0", "id": "1", "result": []}
            except Exception as e:
                return self.error_msg.error_response("err_addr_book")
        return self.error_msg.error_response("no_params_allowed")

    def get_balance_by_block(self,postparams):
    
        if len(self.postparams['params']) == 2:

            if not self.verify_wallet_addr(postparams['params'][0]):
                return self.error_msg.error_response("invalid_wallet_addr")

            if type(self.postparams['params'][1]) is not list:
                return self.error_msg.error_response("missing_params")

            try:
                self.phantomdb = Phantom_Db.PhantomDb()
                self.results = []

                for block_number in postparams['params'][1]:
                    if type(postparams['params'][1][0]) is not int:
                        return self.error_msg.error_response("invalid_block_number")

                    self.res = self.phantomdb.get_balance_by_block(postparams['params'][0],block_number)
                    if self.res and len(self.res) >= 1:
                        self.results.append(self.res)
            except Exception as e:
                return self.error_msg.error_response("err_get_balance_block")

            return {"jsonrpc": "2.0", "id": "1", "result": self.results}
        return self.error_msg.error_response("missing_params")

    def create_contract(self, postparams):

        if len(postparams['params']) == 1 and len(postparams['params'][0]) == 4:

            if 'from_account' in postparams['params'][0]:
                if not self.verify_wallet_addr(postparams['params'][0]['from_account']):
                    return self.error_msg.error_response("invalid_wallet_addr")

            else:
                return self.error_msg.error_response("missing_params")

            """ Source is the compiled EVM source of the contract. """
            if not 'source' in postparams['params'][0] or not len(postparams['params'][0]['source']) > 0:
                return self.error_msg.error_response("missing_params")

            """ Since we do not estimate the gas needed for the contract to be create, every user must specify the amount of gas. """
            if not 'gas' in postparams['params'][0] or not len(postparams['params'][0]['gas']) > 0:
                return self.error_msg.error_response("missing_params")
        
            """ Password is needed to unlock the wallet and pay for the gas. """
            if not 'password' in postparams['params'][0] or not len(postparams['params'][0]['password']) > 0:
                return self.error_msg.error_response("empty_password")

            self.from_addr = postparams['params'][0]['from_account']
            self.source = postparams['params'][0]['source']
            self.gas = postparams['params'][0]['gas']
            self.passwd = postparams['params'][0]['password']

            try:
                from Contract.Contract import ContractCall
                self.contract = ContractCall()
                self.contract_tx = self.contract.create_contract(self.from_addr, self.source, self.gas, self.passwd)
                return {"jsonrpc": "2.0", "id": "1", "result": self.contract_tx}
            except Exception as e:
                return {"jsonrpc": "2.0", "id": "1", "result": e}
        return self.error_msg.error_response("missing_params")

    def set_contract_storage(self, postparams):

        if len(postparams['params']) == 1 and len(postparams['params'][0]) == 6:
            if 'from' in postparams['params'][0] and 'to' in postparams['params'][0] \
                and 'function_signature' in postparams['params'][0] and 'function_argument' in postparams['params'][0] and \
                    'password' in postparams['params'][0] and 'gas' in postparams['params'][0]:

                if not self.verify_wallet_addr(postparams['params'][0]['from']):
                    return self.error_msg.error_response("invalid_wallet_addr")

                if not self.verify_wallet_addr(postparams['params'][0]['to']):
                    return self.error_msg.error_response("invalid_wallet_addr")

                if not len(postparams['params'][0]['function_signature']) > 0:
                    return self.error_msg.error_response("no_function_sign")

                if not len(postparams['params'][0]['password']) > 0:
                    return self.error_msg.error_response("empty_password")

                if not len(postparams['params'][0]['gas']) > 0:
                    return self.error_msg.error_response("err_gas")

                try:
                    from Contract.Contract import ContractCall
                    self.contract = ContractCall()
                    """ from_addr, contract_addr, 'set_s(string)', ['Hello, world'] """
                    self.contract_call_res = self.contract.call_with_transaction(postparams['params'][0])
                    return {"jsonrpc": "2.0", "id": "1", "result": self.contract_call_res}
                except Exception as e:
                    print e
                    return {"jsonrpc": "2.0", "id": "1", "result": e}
        return self.error_msg.error_response("missing_params")

    def get_contract_storage(self, postparams):

        if 'function_signature' in postparams['params'][0] and 'to' in postparams['params'][0] and \
            'function_argument' in postparams['params'][0] and 'return_type' in postparams['params'][0]:

            if not self.verify_wallet_addr(postparams['params'][0]['to']):
                return self.error_msg.error_response("invalid_wallet_addr")

            if not len(postparams['params'][0]['function_signature']) > 0:
                return self.error_msg.error_response("no_function_sign")

            """ TODO: validate more return types. """
            if not postparams['params'][0]['return_type'][0] == 'string':
                return self.error_msg.error_response("no_return_type")
            
            pd = postparams['params'][0]

            from Contract.Contract import ContractCall
            self.contract = ContractCall()

            """ to_address (string), function signature(string), function argument(s)(list of strings), 
                return type(s)(list of strings) """
            res = self.contract.call(pd['to'], pd['function_signature'], pd['function_argument'], pd['return_type'])
            return res
        return self.error_msg.error_response("missing_params")

    def call(self, postparams):

        if 'to' in postparams['params'][0] and 'data' in postparams['params'][0]:

            if not self.verify_wallet_addr(postparams['params'][0]['to']):
                return self.error_msg.error_response("invalid_wallet_addr")

            try:
                self.client = IPC_Client.Client()
                pd = postparams['params'][0]
                res = self.client.call(pd)
                return res
            except Exception as e:
                print e
                return {"jsonrpc": "2.0", "id": "1", "result": e}
        return self.error_msg.error_response("missing_params")

    def create_static_nodefile(self):

        self.client = IPC_Client.Client()
        if self.client.create_static_nodefile():
            pass
        else:
            pass

    def get_tx_receipt(self, postparams):
        
        if len(postparams['params']) == 1:
            self.client = IPC_Client.Client()
            try:
                txrec = self.client.get_tx_reciept(postparams['params'][0])
                if 'result' in txrec:
                    return txrec
                return {"jsonrpc": "2.0", "id": "1", "result": "false"}
            except Exception as e:
                return self.error_msg.error_response("err_get_txrec")
        return self.error_msg.error_response("missing_params")

    def index_phantom_domain(self, postparams):

        if len(postparams['params'][0]) == 5:
            if 'password' not in postparams['params'][0] or len(postparams['params'][0]['password']) == 0:
                return self.error_msg.error_response("empty_password")
            if 'from' not in postparams['params'][0] or not self.verify_wallet_addr(postparams['params'][0]['from']):
                return self.error_msg.error_response("invalid_wallet_addr")
            if 'site_address' not in postparams['params'][0] or not len(postparams['params'][0]['site_address']) == 34: 
                return self.error_msg.error_response("invalid_domain")
            if 'wallet_address' not in postparams['params'][0] or not len(postparams['params'][0]['wallet_address']) >= 40:
                return self.error_msg.error_response("invalid_wallet_addr")
            if 'domain' not in postparams['params'][0] or not self.validate_domain(postparams['params'][0]['domain']):
                return self.error_msg.error_response("invalid_domain")

            try:
                self.passwd = postparams['params'][0]['password']
                self.from_acc = postparams['params'][0]['from']
                self.contract_addr = "0x57b487502392a3f9142c9bebccd6439fce87dd51"
                self.domain = postparams['params'][0]['domain']
                self.site_addr = postparams['params'][0]['site_address']
                self.wallet_addr = postparams['params'][0]['wallet_address']
                self.params = {"params":[{"from":self.from_acc, "to" : self.contract_addr, "function_signature" : "indexSite(string,string,string)",
                                "function_argument" : [str(self.wallet_addr), str(self.domain), str(self.site_addr)], "gas" : "300000", "password" : self.passwd}]}

                result = self.set_contract_storage(self.params)
                return {"jsonrpc": "2.0", "id": "1", "result": result}
            except Exception as e:
                print e
                self.error_msg.error_response("err_index_site")

        return self.error_msg.error_response("missing_params")

    def search_domain_index(self, postparams):

        if len(postparams['params'][0]) == 1:
            if 'wallet_address' not in postparams['params'][0] or not self.verify_wallet_addr(postparams['params'][0]['wallet_address']):
                return self.error_msg.error_response("invalid_wallet_addr")

            self.wallet_address = postparams['params'][0]['wallet_address']
            self.contract_address = "0x57b487502392a3f9142c9bebccd6439fce87dd51"

            try:
                self.params = { "params":[{"to" : self.contract_address, "function_signature" : "searchIndex(string)", 
                                "function_argument" : [str(self.wallet_address)],"return_type" : ["string"]}]}
                result = self.get_contract_storage(self.params)
                return {"jsonrpc": "2.0", "id": "1", "result": result}

            except Exception as e:
                return self.error_msg.error_response("err_resolve_domain")
            return self.error_msg.error_response("missing_params")
                    
    def resolve_phantom_domain(self, postparams):
        if len(postparams['params'][0]) == 1:
            if 'domain' not in postparams['params'][0] or not self.validate_domain(postparams['params'][0]['domain']):
                return self.error_msg.error_response("invalid_domain")

            self.contract_addr = "0xa69818b38011e84dbc98bd0f180e6084855eae2e"
            self.domain = postparams['params'][0]['domain']

            try:
                self.params = { "params":[{"to" : self.contract_addr, "function_signature" : "getRR(string)", "function_argument" : [str(self.domain)], 
                                "return_type" : ["string"]}]}
                result = self.get_contract_storage(self.params)
                return {"jsonrpc": "2.0", "id": "1", "result": result}
            except Exception as e:
                return self.error_msg.error_response("err_resolve_domain")
        return self.error_msg.error_response("missing_params")

    def create_phantom_domain(self, postparams):
        if len(postparams['params'][0]) == 4:
            if 'password' not in postparams['params'][0] or len(postparams['params'][0]['password']) == 0:
                return self.error_msg.error_response("empty_password")
            if 'from' not in postparams['params'][0] or not self.verify_wallet_addr(postparams['params'][0]['from']):
                return self.error_msg.error_response("invalid_wallet_addr")
            if 'domain' not in postparams['params'][0] or not self.validate_domain(postparams['params'][0]['domain']):
                return self.error_msg.error_response("invalid_domain")
            if 'domain_address' not in postparams['params'][0] or not len(postparams['params'][0]['domain_address']) == 34:
                return self.error_msg.error_response("invalid_domain")
                    
            try:
                self.passwd = postparams['params'][0]['password']
                self.from_acc = postparams['params'][0]['from']
                self.contract_addr = "0xa69818b38011e84dbc98bd0f180e6084855eae2e"
                self.domain = postparams['params'][0]['domain']
                self.addr = postparams['params'][0]['domain_address']
                self.params = {"params":[{"from":self.from_acc, "to" : self.contract_addr, "function_signature" : "setRR(string,string)", 
                                "function_argument" : [str(self.domain), str(self.addr)], "gas" : "300000", "password" : self.passwd}]}                
                result = self.set_contract_storage(self.params)
                
                try:
                    self.phantomdb = Phantom_Db.PhantomDb()
                    cache = self.phantomdb.insert_dns_cache(self.domain, self.addr)
                except Exception as e:
                    pass
                return {"jsonrpc": "2.0", "id": "1", "result": result}
            except Exception as e:
                return self.error_msg.error_response("err_create_domain")
        return self.error_msg.error_response("missing_params")

    def get_indexed_domains(self, postparams):
        if len(postparams['params']) == 0:
            try:
                self.domains = self.check_index()
                return {"jsonrpc": "2.0", "id": "1", "result": self.domains}
            except Exception as e:
                print e
        return self.error_msg.error_response("missing_params")

    def check_index(self):

        self.phantomdb = Phantom_Db.PhantomDb()
        address_list = self.phantomdb.get_wallet_addresses()
        found_domains = []
        if address_list:
            for address in address_list:
                if self.verify_wallet_addr(address):
                    postparams = {"params":[{"wallet_address" : str(address)}]}
                    res = self.search_domain_index(postparams)
                    if 'result' in res and len(res['result'][0]) > 0 and res['result'][0] != "false":
                        found_domains.append(res['result'][0])
        return found_domains

    def run(self,postdata):
        self.res = self.validate_postdata(postdata)

        if 'result' in self.res and self.res['result'][0] == "false":
            return self.res
        self.http_response = self.run_method.execute(self.res)
        return self.http_response
コード例 #56
0
ファイル: Zimuzu.py プロジェクト: chenzhenguo/daka
	def __init__(self):
		Site.__init__(self,sitename="Zimuzu")
		self.LOGIN_URL = "http://www.zimuzu.tv/User/Login/ajaxLogin"
コード例 #57
0
    def testFindOptional(self, file_server, site, site_temp):
        file_server.ip_incoming = {}  # Reset flood protection

        # Init source server
        site.connection_server = file_server
        file_server.sites[site.address] = site

        # Init full source server (has optional files)
        site_full = Site("1TeSTvb4w2PWE81S2rEELgmX2GCCExQGT")
        file_server_full = FileServer("127.0.0.1", 1546)
        site_full.connection_server = file_server_full
        gevent.spawn(lambda: ConnectionServer.start(file_server_full))
        time.sleep(0.001)  # Port opening
        file_server_full.sites[site_full.address] = site_full  # Add site
        site_full.storage.verifyFiles(quick_check=True)  # Check optional files
        site_full_peer = site.addPeer("127.0.0.1",
                                      1546)  # Add it to source server
        assert site_full_peer.updateHashfield()  # Update hashfield

        # Init client server
        site_temp.connection_server = ConnectionServer("127.0.0.1", 1545)
        site_temp.announce = mock.MagicMock(
            return_value=True)  # Don't try to find peers from the net
        site_temp.addPeer("127.0.0.1", 1544)  # Add source server

        # Download normal files
        site_temp.download(blind_includes=True).join(timeout=5)

        # Download optional data/optional.txt
        optional_file_info = site_temp.content_manager.getFileInfo(
            "data/optional.txt")
        assert not site_temp.storage.isFile("data/optional.txt")
        assert not site.content_manager.hashfield.hasHash(
            optional_file_info["sha512"]
        )  # Source server don't know he has the file
        assert site_full_peer.hashfield.hasHash(
            optional_file_info["sha512"]
        )  # Source full peer on source server has the file
        assert site_full.content_manager.hashfield.hasHash(
            optional_file_info["sha512"])  # Source full server he has the file

        with Spy.Spy(FileRequest, "route") as requests:
            # Request 2 file same time
            threads = []
            threads.append(
                site_temp.needFile("data/optional.txt", blocking=False))
            threads.append(
                site_temp.needFile(
                    "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif",
                    blocking=False))
            gevent.joinall(threads)

            assert len([
                request for request in requests if request[0] == "findHashIds"
            ]) == 1  # findHashids should call only once

        assert site_temp.storage.isFile("data/optional.txt")
        assert site_temp.storage.isFile(
            "data/users/1CjfbrbwtP8Y2QjPy12vpTATkUT7oSiPQ9/peanut-butter-jelly-time.gif"
        )

        assert site_temp.storage.deleteFiles()
        file_server_full.stop()
        [connection.close() for connection in file_server.connections]