Exemple #1
0
    def upload(self, screenshot, name):
        self.loadSettings()
        #Save to memory buffer
        ba = QByteArray()
        buf = QBuffer(ba)
        buf.open(QIODevice.ReadWrite)
        screenshot.save(buf, ScreenCloud.getScreenshotFormat())
        #Create folder if not exists
        folders = self.driveService.files().list(
            q="name='%s' and mimeType='application/vnd.google-apps.folder' and trashed=false"
            % (self.folderName)).execute()["files"]
        exists = len(folders) > 0
        if not exists:
            folderMetadata = {
                'name': self.folderName,
                'mimeType': 'application/vnd.google-apps.folder'
            }
            folder = self.driveService.files().create(body=folderMetadata,
                                                      fields='id').execute()
        else:
            folder = folders[0]
        #Upload
        fileMetadata = {'name': name, 'parents': [folder["id"]]}
        media = MediaInMemoryUpload(ba.data(),
                                    mimetype='image/' +
                                    ScreenCloud.getScreenshotFormat())
        file = self.driveService.files().create(
            body=fileMetadata, media_body=media,
            fields='webViewLink, id').execute()
        if self.copyLink:
            webViewLink = file.get('webViewLink')
            ScreenCloud.setUrl(webViewLink)

        return True
Exemple #2
0
	def upload(self, screenshot, name):
		self.loadSettings()

		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		ftp = ftplib.FTP()
		ftp.connect(self.host, self.port)
		ftp.login(self.username, self.password)
		f = open(tmpFilename, 'rb')
		try:
			ftp.cwd(self.folder)
		except ftplib.error_perm as err:
			ScreenCloud.setError(err.message)
			return False
		try:
			ftp.storbinary('STOR ' + name, f)
		except ftplib.error_perm as err:
			ScreenCloud.setError(err.message)
			return False
		ftp.quit()
		f.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True
Exemple #3
0
    def upload(self, screenshot, name):
        self.loadSettings()
        if self.loggedIn:
            self.client.auth_provider.refresh_token()
        #Save to temporary file
        timestamp = time.time()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        #Workaround to get id of app folder
        import requests, json
        endpoint = "https://api.onedrive.com/v1.0/drives/me/special/approot"
        headers = {
            "Authorization": "Bearer " + self.client.auth_provider.access_token
        }
        response = requests.get(endpoint, headers=headers).json()
        appfolder_id = response["id"]
        #Upload
        uploaded_item = self.client.item(drive='me', id=appfolder_id).children[
            ScreenCloud.formatFilename(name)].upload(tmpFilename)
        print(uploaded_item, " ".join(dir(uploaded_item)), str(uploaded_item),
              uploaded_item.id, uploaded_item.image)
        if self.copyLink:
            permission = self.client.item(
                id=uploaded_item.id).create_link("view").post()
            ScreenCloud.setUrl(permission.link.web_url)

        return True
Exemple #4
0
	def upload(self, screenshot, name):
		self.loadSettings()

		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		ftp = ftplib.FTP()
		ftp.connect(self.host, self.port)
		ftp.login(self.username, self.password)
		f = open(tmpFilename, 'rb')
		try:
			ftp.cwd(self.folder)
		except ftplib.error_perm as err:
			ScreenCloud.setError(err.message)
			return False
		try:
			ftp.storbinary('STOR ' + name, f)
		except ftplib.error_perm as err:
			ScreenCloud.setError(err.message)
			return False
		ftp.quit()
		f.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True
Exemple #5
0
 def upload(self, screenshot, name):
     self.loadSettings()
     #Make sure we have a up to date token
     if not self.uploadAnon:
         try:
             self.imgur.refresh_access_token()
         except Exception as e:
             ScreenCloud.setError("Failed to refresh imgur access token. " +
                                  e.message)
             return False
     #Save to a temporary file
     timestamp = time.time()
     try:
         tmpFilename = QDesktopServices.storageLocation(
             QDesktopServices.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     except AttributeError:
         from PythonQt.QtCore import QStandardPaths  #fix for Qt5
         tmpFilename = QStandardPaths.writableLocation(
             QStandardPaths.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
     #Upload!
     try:
         uploaded_image = self.imgur.upload_image(
             tmpFilename, title=ScreenCloud.formatFilename(name, False))
     except Exception as e:
         ScreenCloud.setError("Failed to upload to imgur. " + e.message)
         return False
     if self.copyLink:
         if self.copyDirectLink:
             ScreenCloud.setUrl(uploaded_image.link)
         else:
             ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id)
     return True
Exemple #6
0
	def upload(self, screenshot, name):
		self.loadSettings()
		#Make sure we have a up to date token
		if not self.uploadAnon:
			try:
				self.imgur.refresh_access_token()
			except Exception as e:
				ScreenCloud.setError("Failed to refresh imgur access token. " + e.message)
				return False
		#Save to a temporary file
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		#Upload!
		try:
			uploaded_image = self.imgur.upload_image(tmpFilename, title=ScreenCloud.formatFilename(name, False))
		except Exception as e:
			ScreenCloud.setError("Failed to upload to imgur. " + e.message)
			return False
		if self.copyLink:
			if self.copyDirectLink:
				ScreenCloud.setUrl(uploaded_image.link)
			else:
				ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id)
		return True
    def upload(self, screenshot, name):
        ba = QByteArray()
        buf = QBuffer(ba)
        buf.open(QIODevice.WriteOnly)
        screenshot.save(
            buf, ScreenCloud.getScreenshotFormat())  #writes image into ba
        buf.close()

        json_data = json.dumps({'image': ba.toBase64().data()})
        request = urllib2.Request(self.zapier_url, json_data,
                                  {"Content-Type": "application/json"})
        try:
            reply = urllib2.urlopen(request)
        except Exception as e:
            ScreenCloud.setError("Could not upload to: " + self.zapier_url +
                                 "\n" + e.message)
            return False
        try:
            replyText = reply.read()
            ScreenCloud.setUrl(json.loads(replyText).link)
        except Exception as e:
            ScreenCloud.setError("Could not upload to: " + self.zapier_url +
                                 "\n" + e.message)
            return False
        return True
Exemple #8
0
    def upload(self, screenshot, name):
        q_byte_array = QByteArray()
        q_buffer = QBuffer(q_byte_array)
        q_buffer.open(QIODevice.WriteOnly)
        screenshot.save(q_buffer, ScreenCloud.getScreenshotFormat()) # writes image to byte array
        q_buffer.close()

        json_data = json.dumps({'image': str(q_byte_array.toBase64())})
        #f = open('/tmp/zapier', 'w')
        #f.write("{}\n{}\n\n".format(self.zapier_url, json_data))
        #f.close()
        response = requests.post(url=self.zapier_url,
                                 data=json_data,
                                 headers={'Content-Type': 'application/json'})

        try:
            response.raise_for_status()
        except Exception as e:
            ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message)
            return False

        try:
            ScreenCloud.setUrl(response.json()['link'])
        except Exception as e:
            ScreenCloud.setError("Upload to {} worked, but response was invalid: {}\n{}".format(self.zapier_url, response.content, e.message))
            return False

        return True
Exemple #9
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        f = open(tmpFilename, 'rb')
        response = self.client.files_upload(
            f, '/' + ScreenCloud.formatFilename(name))
        f.close()
        os.remove(tmpFilename)
        if self.copy_link:
            share = self.client.sharing_create_shared_link(
                '/' + ScreenCloud.formatFilename(name), short_url=True)
            ScreenCloud.setUrl(share.url)

        return True
	def upload(self, screenshot, name):
		self.loadSettings()
		#Save to a temporary file
		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		#Connect to server
		transport = paramiko.Transport((self.host, self.port))
		if self.authMethod == "Password":
			try:
				transport.connect(username = self.username, password = self.password)
			except paramiko.AuthenticationException:
				ScreenCloud.setError("Authentication failed (password)")
				return False
		else:
			try:
				private_key = paramiko.RSAKey.from_private_key_file(self.keyfile, password=self.passphrase)
				transport.connect(username=self.username, pkey=private_key)
			except paramiko.AuthenticationException:
				ScreenCloud.setError("Authentication failed (key)")
				return False
		sftp = paramiko.SFTPClient.from_transport(transport)
		try:
			sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name))
		except IOError:
			ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.")
			return False
		sftp.close()
		transport.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True
Exemple #11
0
    def upload(self, screenshot, name):
        self.loadSettings()
        # Save to a temporary file
        timestamp = time.time()
        try:
            tmpFilename = (
                QDesktopServices.storageLocation(QDesktopServices.TempLocation)
                + "/"
                + ScreenCloud.formatFilename(str(timestamp))
            )
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  # fix for Qt5

            tmpFilename = (
                QStandardPaths.writableLocation(QStandardPaths.TempLocation)
                + "/"
                + ScreenCloud.formatFilename(str(timestamp))
            )
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        # Connect to server
        try:
            transport = paramiko.Transport((self.host, self.port))
        except Exception as e:
            ScreenCloud.setError(e.message)
            return False
        if self.authMethod == "Password":
            try:
                transport.connect(username=self.username, password=self.password)
            except paramiko.AuthenticationException:
                ScreenCloud.setError("Authentication failed (password)")
                return False
        else:
            try:
                private_key = paramiko.RSAKey.from_private_key_file(self.keyfile, password=self.passphrase)
                transport.connect(username=self.username, pkey=private_key)
            except paramiko.AuthenticationException:
                ScreenCloud.setError("Authentication failed (key)")
                return False
            except paramiko.SSHException as e:
                ScreenCloud.setError("Error while connecting to " + self.host + ":" + str(self.port) + ". " + e.message)
                return False
            except Exception as e:
                ScreenCloud.setError("Unknown error: " + e.message)
                return False
        sftp = paramiko.SFTPClient.from_transport(transport)
        try:
            sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name))
        except IOError:
            ScreenCloud.setError(
                "Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions."
            )
            return False
        sftp.close()
        transport.close()
        if self.url:
            ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
        return True
Exemple #12
0
 def upload(self, screenshot, name):
     self.loadSettings()
     #Save to a temporary file
     timestamp = time.time()
     try:
         tmpFilename = QDesktopServices.storageLocation(
             QDesktopServices.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     except AttributeError:
         from PythonQt.QtCore import QStandardPaths  #fix for Qt5
         tmpFilename = QStandardPaths.writableLocation(
             QStandardPaths.TempLocation
         ) + "/" + ScreenCloud.formatFilename(str(timestamp))
     screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
     #Connect to server
     try:
         transport = paramiko.Transport((self.host, self.port))
     except Exception as e:
         ScreenCloud.setError(e.message)
         return False
     if self.authMethod == "Password":
         try:
             transport.connect(username=self.username,
                               password=self.password)
         except paramiko.AuthenticationException:
             ScreenCloud.setError("Authentication failed (password)")
             return False
     else:
         try:
             private_key = paramiko.RSAKey.from_private_key_file(
                 self.keyfile, password=self.passphrase)
             transport.connect(username=self.username, pkey=private_key)
         except paramiko.AuthenticationException:
             ScreenCloud.setError("Authentication failed (key)")
             return False
         except paramiko.SSHException as e:
             ScreenCloud.setError("Error while connecting to " + self.host +
                                  ":" + str(self.port) + ". " + e.message)
             return False
         except Exception as e:
             ScreenCloud.setError("Unknown error: " + e.message)
             return False
     sftp = paramiko.SFTPClient.from_transport(transport)
     try:
         sftp.put(tmpFilename,
                  self.folder + "/" + ScreenCloud.formatFilename(name))
     except IOError:
         ScreenCloud.setError("Failed to write " + self.folder + "/" +
                              ScreenCloud.formatFilename(name) +
                              ". Check permissions.")
         return False
     sftp.close()
     transport.close()
     if self.url:
         ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
     return True
Exemple #13
0
    def upload(self, screenshot, name):
        self.loadSettings()

        q_ba = QByteArray()
        q_buff = QBuffer(q_ba)

        q_buff.open(QIODevice.WriteOnly)
        screenshot.save(q_buff, ScreenCloud.getScreenshotFormat())
        q_buff.close()

        url = (self.host + '/upload').replace('//upload', '/upload')

        form = MultiPartForm()
        form.add_field('token', self.token)
        form.add_file('file', self.getFilename(), q_ba.data())
        data = bytes(form)

        r = urllib.request.Request(url,
                                   data,
                                   headers={
                                       'Content-Type': form.get_content_type(),
                                       'Content-Length': len(data),
                                       'User-Agent':
                                       'XBackBone/Screencloud-client'
                                   })

        try:
            res = urllib.request.urlopen(r)
            response = json.loads(res.read().decode('utf-8'))
            url = response.get('url')

            if not url:
                raise Exception(response.get('message'))

            ScreenCloud.setUrl(url)

        except urllib.error.HTTPError as e:
            response = json.loads(e.read())
            ScreenCloud.setError('Error while connecting to: ' + self.host +
                                 '\n' + response.get('message'))
            return False

        except Exception as e:
            try:
                ScreenCloud.setError('Could not upload to: ' + self.host +
                                     '\nError: ' + str(e))
            except AttributeError:
                ScreenCloud.setError('Unexpected error while uploading:\n' +
                                     traceback.format_exc())
            return False

        return True
Exemple #14
0
    def upload(self, screenshot, name):
        Headers = {"User-Agent": "ScreenCloud-Cloudup"}

        try:
            FilePath = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(time.time()))
            screenshot.save(QFile(FilePath), ScreenCloud.getScreenshotFormat())

            # Has a stream been specified or should we create on?
            if self.Stream:
                Stream = self.Stream
            else:
                # Create stream
                s = requests.post("https://api.cloudup.com/1/streams?access_token=" + self.Key, data = {"title": name}, headers = Headers)
                c = s.json()

                Stream = c["id"]

            # Create item inside the stream
            i = requests.post("https://api.cloudup.com/1/items?access_token=" + self.Key, data = {"filename": FilePath, "stream_id": Stream}, headers = Headers)
            j = json.loads(i.text)

            # Upload
            requests.post(j["s3_url"], files = {"file": open(FilePath, "rb")}, data = {
                "key": j["s3_key"],
                "acl": "public-read",
                "policy": j["s3_policy"],
                "signature": j["s3_signature"],
                "AWSAccessKeyId": j["s3_access_key"],

                "Content-Type": "image/png",
                "Content-Length": os.path.getsize(FilePath)
            }, headers = Headers)

            # Completion signal
            requests.patch("https://api.cloudup.com/1/items/" + j["id"] + "?access_token=" + self.Key, json.dumps({u"complete": True}), headers = {
                "Content-Type": "application/json",
                "User-Agent": "ScreenCloud-Cloudup"
            })

            # Does the user want the Cloudup item link?
            if self.copyCloudup:
                ScreenCloud.setUrl(j["url"])

            # Does the user want the direct link?
            if self.copyDirect:
                ScreenCloud.setUrl(j["direct_url"])
        except requests.exceptions.RequestException as E:
            ScreenCloud.setError("Failued to upload to Cloudup: " + E.message)
            return False

        return True
	def upload(self, screenshot, name):
		self.loadSettings()
		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		f = open(tmpFilename, 'rb')
		response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f)
		f.close()
		os.remove(tmpFilename)
		if self.copy_link:
			share = self.client.share('/' + ScreenCloud.formatFilename(name))
			ScreenCloud.setUrl(share['url'])

		return True
Exemple #16
0
    def upload(self, screenshot, name):
        temp = QDesktopServices.storageLocation(QDesktopServices.TempLocation)
        file = temp + '/' + name

        screenshot.save(QFile(file), ScreenCloud.getScreenshotFormat())

        ns = NoelShack()

        try:
            url = ns.upload(file)
        except NoelShackError as e:
            ScreenCloud.setError(str(e))
            return False

        ScreenCloud.setUrl(url)
        return True
Exemple #17
0
    def upload(self, screenshot, name):

        temp = QDesktopServices.storageLocation(QDesktopServices.TempLocation)
        file = temp + '/' + name

        screenshot.save(QFile(file), ScreenCloud.getScreenshotFormat())

        register_openers()

        datagen, headers = multipart_encode({'file': open(file, 'rb')})
        req = urllib2.Request('https://vgy.me:443/upload', datagen, headers)

        res = json.loads(urllib2.urlopen(req).read())

        ScreenCloud.setUrl(res['url'])
        return True
    def upload(self, screenshot, name):
        temp = QDesktopServices.storageLocation(QDesktopServices.TempLocation)
        file = temp + '/' + name

        screenshot.save(QFile(file), ScreenCloud.getScreenshotFormat())

        ns = NoelShack()

        try:
            url = ns.upload(file)
        except NoelShackError as e:
            ScreenCloud.setError(str(e))
            return False

        ScreenCloud.setUrl(url)
        return True
Exemple #19
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()

        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation
            ) + "/" + ScreenCloud.formatFilename(str(timestamp))

        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        try:
            oc = nextcloud.Client(self.url)
            oc.login(self.username, self.password)

            remotePath = ""

            if self.remotePath:
                remotePath = self.remotePath

                try:
                    oc.file_info(remotePath)
                except Exception:
                    oc.mkdir(remotePath)

            uploaded_image = oc.put_file(
                remotePath + "/" + ScreenCloud.formatFilename(name, False),
                tmpFilename)

            if self.copyLink:
                link_info = oc.share_file_with_link(
                    remotePath + "/" + ScreenCloud.formatFilename(name, False))
                share_link = link_info.get_link()

                if self.copyDirectLink:
                    share_link = share_link + "/download"

                ScreenCloud.setUrl(share_link)
            return True
        except Exception as e:
            ScreenCloud.setError("Failed to upload to NextCloud. " + e.message)
            return False
Exemple #20
0
 def upload(self, screenshot, name):
     self.loadSettings()
     tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(time.time()))
     screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
     data = {"name": name}
     files = {"file": open(tmpFilename, "rb")} 
     
     try:
         response = requests.post("http://uguu.se/api.php?d=upload-tool", data=data, files=files)
         response.raise_for_status()
         if self.copyLink:
             ScreenCloud.setUrl(response.text)
     except RequestException as e:
         ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message)
         return False
     
     return True
Exemple #21
0
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()
        tmpFilename = QDesktopServices.storageLocation(
            QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(
                str(timestamp))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        f = open(tmpFilename, 'rb')
        response = self.client.put_file('/' + ScreenCloud.formatFilename(name),
                                        f)
        f.close()
        os.remove(tmpFilename)
        if self.copy_link:
            share = self.client.share('/' + ScreenCloud.formatFilename(name))
            ScreenCloud.setUrl(share['url'])

        return True
Exemple #22
0
	def upload(self, screenshot, name):
		self.loadSettings()
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		f = open(tmpFilename, 'rb')
		response = self.client.files_upload(f, '/' + ScreenCloud.formatFilename(name))
		f.close()
		os.remove(tmpFilename)
		if self.copy_link:
			share = self.client.sharing_create_shared_link('/' + ScreenCloud.formatFilename(name), short_url=True)
			ScreenCloud.setUrl(share.url)

		return True
Exemple #23
0
	def upload(self, screenshot, name):
		self.loadSettings()
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		f = open(tmpFilename, 'rb')
		response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f)
		f.close()
		os.remove(tmpFilename)
		if self.copy_link:
			share = self.client.share('/' + ScreenCloud.formatFilename(name), False)
			ScreenCloud.setUrl(share['url'].replace('dl=0', 'raw=1'))

		return True
Exemple #24
0
    def upload(self, screenshot, name):
        self.loadSettings()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation) + "/" + name
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation) + "/" + name
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        command = string.Formatter().vformat(self.commandFormat, (),
                                             defaultdict(str, s=tmpFilename))
        try:
            command = command.encode(sys.getfilesystemencoding())
        except UnicodeEncodeError:
            ScreenCloud.setError("Invalid characters in command '" + command +
                                 "'")
            return False
        try:
            if self.outputIsUrl:
                pipe = subprocess.PIPE
            else:
                pipe = None

            p = subprocess.Popen(command, shell=True, stdout=pipe)
            p.wait()
            if p.returncode > 0:
                ScreenCloud.setError(
                    "Command %s returned %d, but 0 was expected" %
                    (str(command), int(p.returncode)))
                return False
            elif self.outputIsUrl:
                result = bytes.decode(p.stdout.read())
                result = result.strip()
                ScreenCloud.setUrl(result)

        except OSError:
            ScreenCloud.setError("Failed to run command " + command)
            return False

        return True
Exemple #25
0
    def upload(self, screenshot, name):
        self.loadSettings()
        tmpFilename = QStandardPaths.writableLocation(
            QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(
                str(time.time()))
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        data = {"name": name}
        files = {"file": open(tmpFilename, "rb")}

        try:
            response = requests.post("https://uguu.se/api.php?d=upload-tool",
                                     data=data,
                                     files=files)
            response.raise_for_status()
            if self.copyLink:
                ScreenCloud.setUrl(response.text)
        except RequestException as e:
            ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message)
            return False

        return True
Exemple #26
0
	def upload(self, screenshot, name):
		ba = QByteArray()
		buf = QBuffer(ba)
		buf.open(QIODevice.WriteOnly)
		screenshot.save( buf, ScreenCloud.getScreenshotFormat() ) #writes image into ba
		buf.close()

		json_data = json.dumps({'image': ba.toBase64().data()})
		request = urllib2.Request(self.zapier_url, json_data, {"Content-Type": "application/json"})
		try:
			reply = urllib2.urlopen(request)
		except Exception as e:
			ScreenCloud.setError("Could not upload to: "+ self.zapier_url + "\n" + e.message)
			return False
		try:
			replyText = reply.read()
			ScreenCloud.setUrl(json.loads(replyText).link)
		except Exception as e:
			ScreenCloud.setError("Could not upload to: "+ self.zapier_url + "\n" + e.message)
			return False
		return True
    def upload(self, screenshot, name):
        self.loadSettings()
        try:
            tmpFilename = QDesktopServices.storageLocation(
                QDesktopServices.TempLocation) + "/" + name
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths  #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(
                QStandardPaths.TempLocation) + "/" + name
        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
        base_path = os.path.dirname(os.path.realpath(__file__)) + '/'
        command = "bash " + base_path + "puush.sh " + self.apiKey + " " + tmpFilename
        try:
            command = command.encode(sys.getfilesystemencoding())
        except UnicodeEncodeError:
            ScreenCloud.setError("Invalid characters in command '" + command +
                                 "'")
            return False
        try:
            if self.outputIsUrl:
                pipe = subprocess.PIPE
            else:
                pipe = None

            p = subprocess.Popen(command, shell=True, stdout=pipe)
            p.wait()
            if p.returncode > 0:
                ScreenCloud.setError("Command " + command +
                                     " did not return 0")
                return False
            elif self.outputIsUrl:
                result = p.stdout.read()
                result = result.strip()
                ScreenCloud.setUrl(result)

        except OSError:
            ScreenCloud.setError("Failed to run command " + command)
            return False

        return True
    def upload(self, screenshot, name):
        self.loadSettings()
        timestamp = time.time()

        try:
            tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
        except AttributeError:
            from PythonQt.QtCore import QStandardPaths #fix for Qt5
            tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))

        screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

        try:
            oc = owncloud.Client(self.url)
            oc.login(self.username, self.password)

            remotePath = ""

            if self.remotePath:
                remotePath = self.remotePath

                try:
                    oc.file_info(remotePath)
                except Exception:
                    oc.mkdir(remotePath)

            uploaded_image = oc.put_file(remotePath + "/" + ScreenCloud.formatFilename(name, False), tmpFilename)

            if self.copyLink:
                link_info = oc.share_file_with_link(remotePath + "/" + ScreenCloud.formatFilename(name, False))
                share_link = link_info.get_link()

                if self.copyDirectLink:
                    share_link = share_link + "/download"

                ScreenCloud.setUrl(share_link)
            return True
        except Exception as e:
            ScreenCloud.setError("Failed to upload to OwnCloud. " + e.message)
            return False
Exemple #29
0
	def upload(self, screenshot, name):
		self.loadSettings()
		url = self.url_address

		if not url.startswith('http'):
			ScreenCloud.setError('Invalid url!')
			return False

		timestamp = time.time()
		tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())

		reply = requests.post(url,
							  files={'image': open(tmpFilename, 'rb')}
							  ).json()

		try:
			ScreenCloud.setUrl(reply['href'])
		except Exception as e:
			ScreenCloud.setError("Could not upload to: " + self.url_address + "\nError: " + e.message)
			return False
		return True
Exemple #30
0
    def upload(self, screenshot, name):
        path = self.save(screenshot, name)

        if not path:
            ScreenCloud.setError('Failed to save screenshot')
            return False

        with open(path, 'rb') as file:
            files = {
                'c': ('c', file, 'image/' + ScreenCloud.getScreenshotFormat())
            }

            try:
                res = requests.post(self.remote_url, files=files)
                res.raise_for_status()

                if self.copy_link:
                    ScreenCloud.setUrl(res.text)
            except requests.exceptions.HTTPError as e:
                ScreenCloud.setError('\n' + str(e))
                return False

        return True
Exemple #31
0
	def upload(self, screenshot, name):
		self.loadSettings()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename))
		try:
			command = command.encode(sys.getfilesystemencoding())
		except UnicodeEncodeError:
			ScreenCloud.setError("Invalid characters in command '" + command + "'")
			return False
		try:
			if self.outputIsUrl:
				pipe = subprocess.PIPE
			else:
				pipe = None


			p = subprocess.Popen(command, shell=True, stdout=pipe)
			p.wait()
			if p.returncode > 0:
				ScreenCloud.setError("Command %s returned %d, but 0 was expected" % (str(command), int(p.returncode)))
				return False
			elif self.outputIsUrl:
				result = bytes.decode(p.stdout.read())
				result = result.strip()
				ScreenCloud.setUrl(result)

		except OSError:
			ScreenCloud.setError("Failed to run command " + command)
			return False

		return True
Exemple #32
0
    def upload(self, screenshot, name):
        name = fix_filename(name)
        path = self.save(screenshot, name)

        if not path:
            ScreenCloud.setError('Failed to save screenshot')
            return False

        dav = WebDAV(self.dav_address)
        dav.auth(self.username, self.password)

        if not dav.exists('ScreenCloud'):
            dav.mkdir('ScreenCloud')

        print(name)

        if not dav.upload('ScreenCloud/' + name, path):
            ScreenCloud.setError('Failed to upload screenshot')
            return False

        if self.copy_link:
            ScreenCloud.setUrl(self.host_address + '/' + name)

        return True
Exemple #33
0
	def upload(self, screenshot, name):
		self.loadSettings()
		f = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(name)
		screenshot.save(QFile(f), ScreenCloud.getScreenshotFormat())

		now = datetime.datetime.now()
		date = "/%s/%02d/%02d" % (now.year, now.month, now.day)
		path = "/%s/%02d/%02d/%s" % (now.year, now.month, now.day, ScreenCloud.formatFilename(name))

		if self.type == "SFTP":
			transport = paramiko.Transport((self.host, self.port))
			transport.connect(username = self.username, password = self.password)

			sftp = paramiko.SFTPClient.from_transport(transport)
			try:
				sftp.chdir(os.path.normpath(self.path) + date)
			except IOError:
				sftp.mkdir(os.path.normpath(self.path) + date)

			try:
				sftp.put(f, os.path.normpath(self.path) + path)
			except IOError:
				ScreenCloud.setError("Failed to write file")
			
			sftp.close()
			transport.close()
		elif self.type == "FTP":
			ftp = ftplib.FTP()
			ftp.connect(self.host, self.port)
			ftp.login(self.username, self.password)
			
			if os.path.normpath(self.path) in ftp.nlst():
				try:
					ftp.cwd(os.path.normpath(self.path))
				except ftplib.error_perm as err:
					ScreenCloud.setError(err.message)
					return False

			year = "%02d" % now.year
			month = "%02d" % now.month
			day = "%02d" % now.day

			if year in ftp.nlst():
				ftp.cwd(year)
			else:
				ftp.mkd(year)
				ftp.cwd(year)

			if month in ftp.nlst():
				ftp.cwd(month)
			else:
				ftp.mkd(month)
				ftp.cwd(month)

			if day in ftp.nlst():
				ftp.cwd(day)
			else:
				ftp.mkd(day)
				ftp.cwd(day)

			#borrowed from screencloud ftp plugin
			fs = open(f, 'rb')
			try:
				ftp.storbinary('STOR ' + name, fs)
			except ftplib.error_perm as err:
				ScreenCloud.setError(err.message)
				return False

			ftp.quit()
			fs.close()

		url = "%s%s/%s/%s/%s" % (self.url, now.year, now.month, now.day, ScreenCloud.formatFilename(name))
		ScreenCloud.setUrl(self.url.strip("/") + path)

		return True
Exemple #34
0
	def upload(self, screenshot, name):
		self.loadSettings()
		#Save to a temporary file
		timestamp = time.time()
		try:
			tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		except AttributeError:
			from PythonQt.QtCore import QStandardPaths #fix for Qt5
			tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp))
		screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat())
		#Connect to server
		try:
			sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
			sock.connect((self.host, self.port))
			session = Session()
			session.handshake(sock)
		except Exception as e:
			ScreenCloud.setError(e.message)
			return False
		if self.authMethod == "Password":
			try:
				session.userauth_password(self.username, self.password)
			except ssh2.exceptions.AuthenticationError:
				ScreenCloud.setError("Authentication failed (password)")
				return False
		else:
			try:
				session.userauth_publickey_fromfile(self.username, self.keyfile, passphrase=self.passphrase)
			except ssh2.exceptions.AuthenticationError:
				ScreenCloud.setError("Authentication failed (key)")
				return False
			except Exception as e:
				ScreenCloud.setError("Unknown error: " + e.message)
				return False
		sftp = session.sftp_init()
		mode = LIBSSH2_SFTP_S_IRUSR | \
			LIBSSH2_SFTP_S_IWUSR | \
			LIBSSH2_SFTP_S_IRGRP | \
			LIBSSH2_SFTP_S_IROTH
		f_flags = LIBSSH2_FXF_CREAT | LIBSSH2_FXF_WRITE
		try:
			try:
				sftp.opendir(self.folder)
			except ssh2.exceptions.SFTPError:
				sftp.mkdir(self.folder, mode | LIBSSH2_SFTP_S_IXUSR)
			(filepath, filename) = os.path.split(ScreenCloud.formatFilename(name))
			if len(filepath):
				for folder in filepath.split("/"):
					try:
						sftp.mkdir(folder)
					except IOError:
						pass
			source = tmpFilename
			destination = self.folder + "/" + ScreenCloud.formatFilename(filename)
			with open(source, 'rb') as local_fh, sftp.open(destination, f_flags, mode) as remote_fh:
				for data in local_fh:
					remote_fh.write(data)
		except IOError:
			ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.")
			return False
		sock.close()
		if self.url:
			ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name))
		return True