Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
config.cfg
.s3cfg
*.pyc
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GtkGrab - Screenshot Uploader

Version 0.2.0 Created by Evan Coury
Version 0.3.0 Created by Evan Coury

## Update Notice

Expand Down Expand Up @@ -39,8 +39,15 @@ Gnome and KDE as well as on Mac OSX.
handler.php and chmod it to 777.
* Copy the appropriate config.cfg-sample-{os} to config.cfg. Set the username
and password to match handler.php and posturl to be the URL to handler.php.

Create a new top level section in `config.cfg` and pass the section name
into `screenshot` as the first parameter to use different configuration
settings


* Follow any platform-specific instructions below.


### Amazon S3 Upload Support
* Alternatively, GtkGrab supports using `s3cmd` (available in ruby-gems) to
upload screenshots to Amazon S3.
Expand Down Expand Up @@ -78,7 +85,8 @@ choosing via System -> Preferences -> Keyboard Shortcuts.

### Mac Installation

* Install Growl and growlnotify from http://growl.info/
* Install Terminal Notifier from https://github.com/julienXX/terminal-notifier/releases
* Copy config.cfg-sample-mac to config.cfg and update as appropriate
* Use automator to run **`GtkGrab/screenshot`** via the keyboard shortcut
of your choice. Instructions for this can be found
[here](http://www.macosxautomation.com/services/learn/tut01/index.html),
Expand Down
5 changes: 4 additions & 1 deletion config.cfg-sample-mac
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ username=myuser
password=mypass
posturl=http://yourhost.tld/gtkgrab/handler.php
command=screencapture -i %s
notifyCommand=/usr/local/bin/growlnotify -m "Copied url to clipboard: %s" -n "GtkGrab"
; If you want to capture the current window without using the mouse, use
; https://github.com/vorgos/QuickGrab and this command:
; command=/usr/local/bin/quickgrab -file %s
notifyCommand=/usr/local/bin/terminal-notifier.app/Contents/MacOS/terminal-notifier -message "Copied URL to clipboard: %s" -title "GtkGrab"
capPath=/tmp/ss.png
69 changes: 69 additions & 0 deletions delete-old-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#!/usr/bin/env bash

# Delete PNG files older than 15 months
# Usage: ./delete_old_pngs.sh [directory] [--dry-run] [--verbose]

DIRECTORY=""
DRY_RUN=false
VERBOSE=false
MONTHS=20
DAYS=$((MONTHS * 30)) # Calculate days from months (approximate)

# Parse arguments
while [[ $# -gt 0 ]]; do
case $1 in
--dry-run)
DRY_RUN=true
shift
;;
--verbose|-v)
VERBOSE=true
shift
;;
-*)
echo "Unknown option $1"
exit 1
;;
*)
DIRECTORY="$1"
shift
;;
esac
done

# Default to current directory if not specified
if [[ -z "$DIRECTORY" ]]; then
DIRECTORY="."
fi

# Check if directory exists
if [[ ! -d "$DIRECTORY" ]]; then
echo "Error: Directory '$DIRECTORY' does not exist"
exit 1
fi

echo "Looking for PNG files older than $MONTHS months in: $DIRECTORY"

if [[ "$DRY_RUN" == true ]]; then
echo "DRY RUN - files that would be deleted:"
find "$DIRECTORY" -name "*.png" -mtime +$DAYS -print
else
# Count files before deletion
count=$(find "$DIRECTORY" -name "*.png" -mtime +$DAYS | wc -l)

if [[ $count -eq 0 ]]; then
echo "No PNG files older than $MONTHS months found"
exit 0
fi

echo "Found $count PNG file(s) older than $MONTHS months"

# Delete files
if [[ "$VERBOSE" == true ]]; then
find "$DIRECTORY" -name "*.png" -mtime +$DAYS -print -delete
else
find "$DIRECTORY" -name "*.png" -mtime +$DAYS -delete
fi

echo "Deleted $count PNG file(s)"
fi
Binary file added gtkgrab-current.scpt
Binary file not shown.
Binary file added gtkgrab.scpt
Binary file not shown.
8 changes: 5 additions & 3 deletions handler.php
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@
// write the file
function generateFilename()
{
return substr(md5(microtime()),0,6);
return substr(md5(microtime() . mt_rand()),0,8);
}
do {
$filename = 'caps/'.generateFilename().'.png';
$filename = generateFilename().'.png';
} while(file_exists($filename));

file_put_contents($filename, base64_decode($input));
chmod($filename, 0664);

if (isset($_SERVER['FCGI_ROLE'])) {
$path = $_SERVER['REQUEST_URI'];
Expand All @@ -57,4 +58,5 @@ function generateFilename()
$path .= '/';
}

echo 'http://' . $_SERVER['HTTP_HOST'] . '/' . $path . $filename;
header("Content-Type: text/plain");
echo 'https://' . $_SERVER['HTTP_HOST'] . '/' . $path . $filename;
66 changes: 48 additions & 18 deletions screenshot
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python
#!/usr/bin/python3

# !/usr/bin/env python3

# This file is part of GtkGrab.
#
# GtkGrab is free software: you can redistribute it and/or modify
Expand All @@ -19,28 +22,49 @@
# @copyright Copyright 2010-2013 Pieter Kokx (http://kokx.nl/)
# @package Client

import ConfigParser, sys, urllib2, os, base64, hashlib, pyperclip, time
import configparser, sys, urllib.request as urllib2, os, base64, hashlib, pyperclip, time

config = ConfigParser.ConfigParser()
config.readfp(open(os.path.dirname(sys.argv[0]) + '/config.cfg'))
config = configparser.ConfigParser()
config.read_file(open(os.path.dirname(__file__) + '/config.cfg'))

user = config.get('GtkGrab','username')
token = config.get('GtkGrab','password')
postURL = config.get('GtkGrab','posturl')
command = config.get('GtkGrab','command')
configSection = 'GtkGrab'
if len(sys.argv) > 1 and sys.argv[1] != 'gif':
configSection = sys.argv[1]

user = config.get(configSection,'username', raw=True)
token = config.get(configSection,'password', raw=True)
postURL = config.get(configSection,'posturl', raw=True)
notifyCommand = config.get(configSection,'notifyCommand', raw=True)
path = config.get(configSection,'capPath', raw=True)

# determine command to run
command = config.get(configSection,'command', raw=True)
if len(sys.argv) > 1 and sys.argv[1] == 'gif':
command = os.path.dirname(__file__) + '/' + config.get('GtkGrab','gifCommand')
command = os.path.dirname(__file__) + '/' + config.get(configSection,'gifCommand', raw=True)
if len(sys.argv) > 2 and sys.argv[2] == 'gif':
command = os.path.dirname(__file__) + '/' + config.get(configSection,'gifCommand', raw=True)


notifyCommand = config.get('GtkGrab','notifyCommand')
# Delete cap file if it currently exists
if os.path.exists(path) == True:
os.remove(path)

path = config.get('GtkGrab','capPath')
# Perform capture
returnval = os.system(command.replace("%s", path))

if (returnval != 0 and returnval != 256) or os.path.exists(path) == False:
# no cap file created
# os.system(notifyCommand.replace('%s', f"{returnval} {path} Cancelled!!!"))
sys.exit(1)


# if convertCommand:
# os.system(convertCommand.replace("%s", path))

os.system(command.replace("%s", path))

if postURL == 's3':
bucket = config.get('GtkGrab', 's3bucket')
prefix = config.get('GtkGrab', 's3prefix')
bucket = config.get(configSection, 's3bucket', raw=True)
prefix = config.get(configSection, 's3prefix', raw=True)
filename = hashlib.sha1()
filename.update(str(time.time()))
filename = filename.hexdigest()
Expand All @@ -52,19 +76,25 @@ if postURL == 's3':
os.system(uploadCommand)
url = "http://"+bucket+".s3.amazonaws.com/caps/"+filename+".png"
else:
os.system(notifyCommand.replace('%s', f"Uploading"))
# encode the screenshot with base64
data = base64.b64encode(open(path, 'r').read())
data = base64.b64encode(open(path, 'rb').read())
# hash the data with the user's secret token and send that as header
hash = hashlib.sha1()
hash.update(data)
hash.update(token)
hash.update(token.encode('UTF-8'))
headers = {'X-Username': user, 'X-Signature': hash.hexdigest(), 'Content-Type': 'text/xml'}
# upload the url and give the screenshot url to the user
print(postURL)
url = urllib2.urlopen(urllib2.Request(postURL, data, headers)).read()
url = url.decode(encoding='utf-8', errors='strict')

# remove the file
os.remove(path)
if os.path.exists(path) == True:
os.remove(path)

pyperclip.copy(url)

os.system(notifyCommand.replace('%s', url))
os.system(notifyCommand.replace('%s', 'Copied URL to clipboard: ' + url))

os.system(f"open {url}")