[Tutorial] Your own screenshot server

Discussion in 'Security Discussion' started by BoTz, Apr 16, 2016.

  1. BoTz

    BoTz Member

    So, actually this tutorial is about ShareX, you can download it here https://getsharex.com/
    If u want to go simple, you can use imgur or a another standard host.
    But if you want a own screenshot server, you can use this tutorial.

    What you need:
    - a webserver (apache2 or something else)
    - php
    - ShareX
    A VPS with Debian is perfectly for this.

    Tutorial:
    Edit your upload.php and change "yourdomain.com" to your own domain.
    Edit yourkey to a password
    upload.php
    Code:
    <?php
    $key            = "yourkey";
    $redirect       = "http://yourdomain.com/";
    $domain         = "yourdomain.com";
    $filenamelength = 8;
    #Comment this next line if you want Robots to index this site.
    if ($_SERVER["REQUEST_URI"] == "/robot.txt") {
        die("User-agent: *\nDisallow: /");
    }
    #Don't edit below this line inless you know what you are doing...
    $urldata = explode("/", $_SERVER["REQUEST_URI"]);
    
    if (isset($_POST['k'])) {
        if ($_POST['k'] != $key) {
            echo ('Error Key wrong.');
            die();
        }
    }
    
    function createthumb($name, $filename, $new_w, $new_h)
    {
        $system  = explode('.', $name);
        $src_img = imagecreatefromstring(file_get_contents($name));
        $old_x   = imageSX($src_img);
        $old_y   = imageSY($src_img);
        if ($old_x > $old_y) {
            $thumb_w = $new_w;
            $thumb_h = $old_y * ($new_h / $old_x);
        }
        if ($old_x < $old_y) {
            $thumb_w = $old_x * ($new_w / $old_y);
            $thumb_h = $new_h;
        }
        if ($old_x == $old_y) {
            $thumb_w = $new_w;
            $thumb_h = $new_h;
        }
        $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h);
        imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y);
        if (preg_match("/png/", $system[1])) {
            imagepng($dst_img, $filename);
        } else {
            imagejpeg($dst_img, $filename);
        }
        imagedestroy($dst_img);
        imagedestroy($src_img);
    }
    if (isset($_GET['tn'])) {
        if (!file_exists('tn_' . $_GET['tn'])) {
            createthumb($_GET['tn'], 'tn_' . $_GET['tn'], 100, 100);
        }
        header('Location: http://' . $domain . '/tn_' . $_GET['tn']);
        die();
    }
    
    if (isset($_GET['k'])) {
        if ($_GET['k'] == $key) {
            if (isset($_GET['delete'])) {
                if (file_exists($_GET['delete'])) {
                    if (isset($_GET['delete'])) {
                        if (file_exists('tn_' . $_GET['delete'])) {
                            unlink('tn_' . $_GET['delete']);
                        }
                        unlink($_GET['delete']);
                        echo "Your uploaded file has been deleted";
                        die();
                    } else {
                        echo "Your file you want deleted does not exist";
                    }
                }
            }
        }
    }
    if (isset($_POST['k'])) {
        if ($_POST['k'] == $key) {
            header("Content-Type: application/json");
            if (isset($_GET['up'])) {
                $target = getcwd() . "/" . basename($_FILES['d']['name']);
                if (move_uploaded_file($_FILES['d']['tmp_name'], $target)) {
                    $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength) . "." . end(explode(".", $_FILES["d"]["name"]));
                    while (file_exists($filename)) {
                        $filename = substr(str_shuffle("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"), 0, $filenamelength) . "." . end(explode(".", $_FILES["d"]["name"]));
                    }
                    rename(getcwd() . "/" . basename($_FILES['d']['name']), getcwd() . "/" . $filename);
                    echo json_encode(array(
                        'filename' => $filename,
                        'key' => $key
                    ));
                } else {
                    echo "Sorry, there was a problem uploading your file.";
                }
            }
        } else {
            echo ('404');
        }
    } else {
        echo ('Welcome.');
    }
    ?>
    
    .htaccess
    Code:
    <Files *.php>
        php_flag engine off
        AddType text/plain php
    </Files>
    
    <Files index.php>
        Order Allow,Deny
        Allow from all
        php_flag engine on
        RemoveType text/plain php
    </Files>
    Upload both files to your ftp and give them full rights (777)
    Go to ShareX - Destinations - Destination Settings - Scroll down to custom uploaders - Click on add and change everything to this ->[/COLOR]
    https://img.botz.cc/05DryOvK.png

    http://yourdomain.com/upload.php/?up=

    \"domain\":\"(.+?)\"
    \"key\":\"(.+?)\"
    \"filename\":\"(.+?)\"


    http://yourdomain.com/$json:filename$
    http://yourdomain.com/?tn=$json:filename$
    http://yourdomain.com/?k=$json:key$&delete=$json:filename$

    Click on Update to save it. (At the left site, not in the middle)
    Change your Destination settings to your new uploader
    https://img.botz.cc/76FEpGTI.png

    If you have any questions, let me know.
    Credits:

    BoTz
    radat
     
    Last edited by a moderator: Dec 27, 2016
    B1uscr34m, zafai, Kleberstoff and 4 others like this.
  2. skokkk

    skokkk Contributor

    I would have used this.. but that means compiling it for linux. Good tutorial btw. +1
     
    talha123 likes this.
  3. ItsiAdam

    ItsiAdam Member

    yaourt -S screencloud
     
    talha123 and skokkk like this.
  4. EscuderoKevin

    EscuderoKevin Active Member


    Its for backup server ? , you can use zip + dropbox uploader
     
    talha123 likes this.
  5. skokkk

    skokkk Contributor

    Just needed to know what to search for, thanks! :D
     
    talha123 likes this.
  6. talha123

    talha123 Restricted

    Great share.
     
  7. Shockru

    Shockru New Member

  8. spartaaaa5

    spartaaaa5 New Member

  9. Ch4ch4rR4t0

    Ch4ch4rR4t0 Member

    Thanks bro :D
    more i have error!

    Code:
    Error: Failed.
    Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.
       in Newtonsoft.Json.JsonTextReader.ParseValue()
       in Newtonsoft.Json.JsonTextReader.Read()
        in Newtonsoft.Json.Linq.JToken.ReadFrom(JsonReader reader, JsonLoadSettings settings)
        in Newtonsoft.Json.Linq.JToken.Parse(String json, JsonLoadSettings settings)
        in ShareX.HelpersLib.Helpers.ParseJSON(String text, String jsonPath)
        in ShareX.UploadersLib.CustomUploaderItem.ParseURL(String url)
        in ShareX.UploadersLib.CustomUploaderItem.ParseResponse(UploadResult result, Boolean isShortenedURL)
        in ShareX.UploadersLib.ImageUploaders.CustomImageUploader.Upload(Stream stream, String fileName)
    
     
  10. spartaaaa5

    spartaaaa5 New Member

    i gave up after several hours trying, :c
     
  11. Ch4ch4rR4t0

    Ch4ch4rR4t0 Member

    how to fix? thx for reply
     
  12. spartaaaa5

    spartaaaa5 New Member

    Well if you can read.. i gave up ! i did not fix it
     
  13. Swok

    Swok Member

    How did you do with screencloud ?
     
  14. PAY-BACK

    PAY-BACK New Member

    StackTrace:
    When System.Net.HttpWebRequest.GetRequestStream (TransportContext & context)
    When System.Net.HttpWebRequest.GetRequestStream ()
    When ShareX.UploadersLib.Uploader.UploadData (Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String contentType, String metadata)
    1438-03-17 01: 22: 19.218 - Task failed. Filename: chrome_2016-12-16_01-22-17.png, Errors:
    Message:
    Unable to run the name resolution: 'picture.sauuu.us.us'

    StackTrace:
    When System.Net.HttpWebRequest.GetRequestStream (TransportContext & context)
    When System.Net.HttpWebRequest.GetRequestStream ()
    When ShareX.UploadersLib.Uploader.UploadData (Stream dataStream, String url, String fileName, String fileFormName, Dictionary`2 arguments, NameValueCollection headers, CookieCollection cookies, ResponseType responseType, HttpMethod method, String contentType, String metadata)
    1438-03-17 01: 22: 19.326 - UploadersConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ UploadersConfig.json
    1438-03-17 01: 22: 19.326 - UploadersConfig save started: C: \ Users \ **** \ Documents \ ShareX \ UploadersConfig.json
    1438-03-17 01: 22: 19.326 - ApplicationConfig save started: C: \ Users \ **** \ Documents \ ShareX \ ApplicationConfig.json
    1438-03-17 01: 22: 19.326 - HotkeysConfig save started: C: \ Users \ **** \ Documents \ ShareX \ HotkeysConfig.json
    1438-03-17 01: 22: 19.338 - HotkeysConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ HotkeysConfig.json
    1438-03-17 01: 22: 19.365 - ApplicationConfig save successful: C: \ Users \ **** \ Documents \ ShareX \ ApplicationConfig.json
    1438-03-17 01: 22: 25.590 - Executing: Open main window
    ^
    Help please ?
     
  15. Kleberstoff

    Kleberstoff Knowledge Seeker Member of the Month

    picture.sauuu.us.us should be picture.sauuu.us
    Also, please use spoilers or code to make it more readable
     
  16. PAY-BACK

    PAY-BACK New Member

    sorry i will use it next time <3
     
    Kleberstoff likes this.
  17. PAY-BACK

    PAY-BACK New Member

  18. Kleberstoff

    Kleberstoff Knowledge Seeker Member of the Month

    PAY-BACK likes this.
  19. PAY-BACK

    PAY-BACK New Member

  20. ehthe

    ehthe Super Mod TS3 Dev-Team

Share This Page