Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kutt Integration with ShareX #67

Closed
xianx opened this issue Jun 19, 2018 · 46 comments · Fixed by ShareX/ShareX#3650
Closed

Kutt Integration with ShareX #67

xianx opened this issue Jun 19, 2018 · 46 comments · Fixed by ShareX/ShareX#3650
Labels
enhancement New feature or request

Comments

@xianx
Copy link

xianx commented Jun 19, 2018

Hello,

I am trying to integrate Kutt https://github.com/thedevs-network/kutt#api with shareX with Custom Short URL https://github.com/ShareX/CustomUploaders like Yourls https://github.com/ShareX/CustomUploaders/blob/master/yourls.org.sxcu

but could not figure out how to do that and what to enter which field on Custom ShortURL making interface see the screenshot https://zdrive.techtunes.com.bd/s/JYr9qcJWk2orPC3

I have also generate API key and passed the value as Header Value of X-API-Key see the screenshot https://zdrive.techtunes.com.bd/s/N2r3bF3k6XD78PS

In debug window its showing {"error":"No target has been provided."}
https://zdrive.techtunes.com.bd/s/4MeEReQrd2TP9cX

How to integrate Kutt with ShareX properly?

@xianx xianx closed this as completed Jun 19, 2018
@xianx xianx reopened this Jun 19, 2018
@Jaex
Copy link

Jaex commented Jun 19, 2018

ShareX custom uploader support can supply arguments either as multipart/form-data or url query. But Kutt API requires them as JSON data therefore it not gonna work like this:

{
  "DestinationType": "URLShortener",
  "RequestURL": "https://kutt.it/api/url/submit",
  "Arguments": {
    "target": "$input$"
  },
  "Headers": {
    "X-API-Key": "YOUR API KEY HERE"
  }
}

@trgwii
Copy link
Member

trgwii commented Jun 19, 2018

Kutt technically supports urlencoded POST data as well (key1=value1&key2=value2 in the request body), but this won't work until ShareX supports one of:

  • POST with application/x-www-form-urlencoded
  • POST with application/json

Closing for now!

@trgwii trgwii closed this as completed Jun 19, 2018
@xianx
Copy link
Author

xianx commented Jun 19, 2018

@Jaex how to make it work? Any solution?

@nightah
Copy link

nightah commented Jul 2, 2018

I got this working with Kutt behind an NGINX reverse proxy by modifying the location block to add the headers and elements that ShareX doesn't support.

NGINX config:

    location / {
        proxy_pass http://kutt:3000;
        include /config/nginx/proxy.conf;
    }

    location /api/url/submit {
        proxy_pass http://kutt:3000;
        include /config/nginx/proxy.conf;
        proxy_set_header Content-Type application/json;
        proxy_set_body $http_target;
    }

ShareX URL Shortener config:

{
  "Name": "kutt",
  "DestinationType": "URLShortener",
  "RequestURL": "https://example.com/api/url/submit",
  "Headers": {
    "X-API-Key": "yourapikeyhere",
    "Target": "{\"target\":\"$input$\"}"
  },
  "URL": "$json:shortUrl$"
}

@poeti8 poeti8 added the enhancement New feature or request label Jul 2, 2018
@poeti8
Copy link
Member

poeti8 commented Jul 2, 2018

Reopening the issue because I might add support for URL query in the future.
For now, @nightah solution should work if you have hosted this app yourself.

@poeti8 poeti8 reopened this Jul 2, 2018
@xianx
Copy link
Author

xianx commented Jul 12, 2018

Any update. We are using kutt for our team but without shareX support we are not doing day to day sharing.

@xianx
Copy link
Author

xianx commented Jul 12, 2018

@nightah but how to make it work with custom domain? We are running self hosted Kutt and using with custom domain behind a nGinx Proxy.

@nightah
Copy link

nightah commented Jul 13, 2018

@xianx: The configuration I provided above is for exactly that type of a scenario, a self-hosted kutt behind an nginx reverse proxy.

This is the relevant location block you need to include within your nginx configuration:

    location /api/url/submit {
        proxy_pass http://kutt:3000;
        include /config/nginx/proxy.conf;
        proxy_set_header Content-Type application/json;
        proxy_set_body $http_target;
    }

Obviously replacing your proxy_pass to be whatever the location of your self-hosted Kutt instance, you probably already have a variant of the proxy.conf or headers you apply to the standard reverse proxy of the kutt instance, make sure that's included too.

Finally you need to configure ShareX Custom URL shortener with the following config:

{
  "Name": "kutt",
  "DestinationType": "URLShortener",
  "RequestURL": "https://example.com/api/url/submit",
  "Headers": {
    "X-API-Key": "yourapikeyhere",
    "Target": "{\"target\":\"$input$\"}"
  },
  "URL": "$json:shortUrl$"
}

Replace your RequestURL with whatever the location of your Custom Kutt instance and also replace your X-API-Key with your relevant API key.

@poeti8
Copy link
Member

poeti8 commented Jul 14, 2018

@xianx
Copy link
Author

xianx commented Jul 26, 2018

@nightah @poeti8 After adding nginx rules ShareX is working but kutt web interface is showing error and not making the url short.

When user is logged-in its showing

"No target has been provided."

and when not logged-in showing

"reCAPTCHA is not valid. Try again."

You can see this video for clarity https://techtun.es/xPEJ5e You can also try by yourself by visiting https://techtun.es/ url.

Below is my full nginx configuration file. (Some text has been replace with sudo text for security)

server {

  listen 80;

  server_name domainname.com;
  include conf.d/letsencrypt.inc;
  # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
  return 301 https://$host$request_uri;

}

server {

  listen 443 ssl http2;

  ssl_certificate /etc/letsencrypt/live/domainname.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/domainname.com/privkey.pem;

  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:50m;
  ssl_session_tickets off;

  # Diffie-Hellman parameter for DHE ciphersuites
  ssl_dhparam /mydir/ssl/dhparam.pem;

  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_ciphers "LONG Ciphers CODE";
  ssl_prefer_server_ciphers on;
  ssl_ecdh_curve secp521r1:secp384r1:prime256v1;

  # HSTS (15768000 seconds = 6 months)
  add_header Strict-Transport-Security max-age=15768000;

  # OCSP Stapling ---
  # fetch OCSP records from URL in ssl_certificate and cache them
  ssl_stapling on;
  ssl_stapling_verify on;

  root /var/www/theapp;
  server_name domainname.com;
  index index.html;
  resolver 172.17.0.1 valid=60s ipv6=off;
  set $backend theapp;
  include conf.d/letsencrypt.inc;
  
  
  location ~ /\.git {
    deny all;
  }

  try_files $uri/index.html $uri @app;
  
  
  location @app {
    proxy_pass        http://$backend:3000;
    proxy_redirect    off;
    proxy_set_header  Upgrade $http_upgrade;
    proxy_set_header  Connection "upgrade";
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
  }
  
  
  location /api/url/submit {
    proxy_pass        http://$backend:3000;
    proxy_redirect    off;
    proxy_set_header  Upgrade $http_upgrade;
    proxy_set_header  Connection "upgrade";
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_set_header Content-Type application/json;
    proxy_set_body $http_target;
  }
 
}

How to make it work both for ShareX and Kutt?

Thanks in advance.

@xianx
Copy link
Author

xianx commented Jul 27, 2018

@nightah @poeti8 Any solution to above nginx file?

@nightah
Copy link

nightah commented Jul 30, 2018

Didn't really think about the frontend app because I don't particularly use it.
You can easily fix the problem by changing your endpoint for ShareX.

server {

  listen 80;

  server_name domainname.com;
  include conf.d/letsencrypt.inc;
  # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
  return 301 https://$host$request_uri;

}

server {

  listen 443 ssl http2;

  ssl_certificate /etc/letsencrypt/live/domainname.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/domainname.com/privkey.pem;

  ssl_session_timeout 1d;
  ssl_session_cache shared:SSL:50m;
  ssl_session_tickets off;

  # Diffie-Hellman parameter for DHE ciphersuites
  ssl_dhparam /mydir/ssl/dhparam.pem;

  ssl_protocols TLSv1.2 TLSv1.3;
  ssl_ciphers "LONG Ciphers CODE";
  ssl_prefer_server_ciphers on;
  ssl_ecdh_curve secp521r1:secp384r1:prime256v1;

  # HSTS (15768000 seconds = 6 months)
  add_header Strict-Transport-Security max-age=15768000;

  # OCSP Stapling ---
  # fetch OCSP records from URL in ssl_certificate and cache them
  ssl_stapling on;
  ssl_stapling_verify on;

  root /var/www/theapp;
  server_name domainname.com;
  index index.html;
  resolver 172.17.0.1 valid=60s ipv6=off;
  set $backend theapp;
  include conf.d/letsencrypt.inc;
  
  
  location ~ /\.git {
    deny all;
  }

  try_files $uri/index.html $uri @app;
  
  
  location @app {
    proxy_pass        http://$backend:3000;
    proxy_redirect    off;
    proxy_set_header  Upgrade $http_upgrade;
    proxy_set_header  Connection "upgrade";
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
  }
  
  
  location /api/url/sharex {
    proxy_pass        http://$backend:3000/api/url/submit;
    proxy_redirect    off;
    proxy_set_header  Upgrade $http_upgrade;
    proxy_set_header  Connection "upgrade";
    proxy_set_header  Host $host;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    proxy_set_header Content-Type application/json;
    proxy_set_body $http_target;
  }
 
}

Make sure to change your ShareX config to this:

{
  "Name": "kutt",
  "DestinationType": "URLShortener",
  "RequestURL": "https://example.com/api/url/sharex",
  "Headers": {
    "X-API-Key": "yourapikeyhere",
    "Target": "{\"target\":\"$input$\"}"
  },
  "URL": "$json:shortUrl$"
}

@poeti8
Copy link
Member

poeti8 commented Jul 30, 2018

Thank you @xianx. It works fine for me.
I added a wiki page and a section in readme.
https://github.com/thedevs-network/kutt/wiki/ShareX

Closing the issue.

@poeti8 poeti8 closed this as completed Jul 30, 2018
@xianx
Copy link
Author

xianx commented Jul 30, 2018

@poeti8 in wiki there should be hint that one need to setup Kutt behind an NGINX reverse proxy else it will not be work now as kutt do not have support for URL query to work with ShareX now. It will be added in next version but one can setup their own Kutt behind an NGINX reverse proxy and use the proxy configuration on nginx.

Thanks.

@xianx
Copy link
Author

xianx commented Jul 30, 2018

@nightah now working both on both front-end and ShareX. Thanks a lot.

@Jaex
Copy link

Jaex commented Oct 2, 2018

I added Kutt support to ShareX now:

I was only be able to test it with kutt.it but probably it will work same with custom hosted ones too.

@nightah
Copy link

nightah commented Oct 3, 2018

@Jaex I'd be happy to test but there's been no release since you added this. Let me know when it is and I'll give it a try.

@Jaex
Copy link

Jaex commented Oct 3, 2018

You can test it like this: https://getsharex.com/docs/dev-builds

@nightah
Copy link

nightah commented Oct 3, 2018

@Jaex: I can confirm this works with custom hosted instances too.
@poeti8: You can probably change the wiki perhaps when there's a stable release of ShareX including this, no more webserver trickery required.

@MKRhere
Copy link
Member

MKRhere commented Oct 6, 2018

@Jaex Does this mean ShareX now supports application/json?

@Jaex
Copy link

Jaex commented Oct 6, 2018

ShareX supports, custom uploaders not.

@DananFlander
Copy link

Has anyone tested using Kutt through ShareX with a custom host? I can't seem to get it to work and only get thrown kutt.it links instead of my custom danan.gg attempts.

chrome_2020-07-02_18-14-50

@adx74
Copy link

adx74 commented Jul 25, 2020

same problem as @DananFlander if anyone can help us please :D

@DananFlander
Copy link

@nightah @Jaex send help

@Jaex
Copy link

Jaex commented Jul 29, 2020

Without be able to test it I can't implement it.

@adx74
Copy link

adx74 commented Jul 29, 2020

What do you need to be able to test it ?

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

@Jaex you can sign up and set domain in settings. Also Kutt now uses API v2: https://docs.kutt.it, so please use this one since v1 is deprecated.

@Jaex
Copy link

Jaex commented Jul 29, 2020

I can't scroll that docs page, it keep scrolling to top automatically. (Chrome 84.0.4147.105)

@Jaex
Copy link

Jaex commented Jul 29, 2020

Video showing the issue: https://jaex.getsharex.com/2020/07/zukKAvCJLv.mp4

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

I see, seems like redoc has issues. Can you use another browser for the time being?

@Jaex
Copy link

Jaex commented Jul 29, 2020

I implemented API v2 now but request fails:

Request URL:
https://kutt.it/api/v2/links

Status code:
(500) Internal Server Error

Response text:
{"error":"An error occurred."}

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

Can you send your request body here?

@Jaex
Copy link

Jaex commented Jul 29, 2020

{"target":"https://jaex.getsharex.com/2020/07/Tpd0TsJi3z.png","password":null,"customurl":null,"reuse":false,"domain":null}

@Jaex
Copy link

Jaex commented Jul 29, 2020

API v2 diff: ShareX/ShareX@f685dd1

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

Updated the server. Now null values should be allowed too. Please try again now.

@Jaex
Copy link

Jaex commented Jul 29, 2020

Now it gives:

{"error":"Password length must be between 3 and 64."}

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

Seems like you're sending empty string instead of null. I updated the API again to allow empty string as well. Try now.

@Jaex
Copy link

Jaex commented Jul 29, 2020

Neither from web UI or API I can't make Kutt return custom domain which starts with https:// prefix, instead it removes prefix and returns url with http:// prefix instead.

@Jaex
Copy link

Jaex commented Jul 29, 2020

Seems like you're sending empty string instead of null. I updated the API again to allow empty string as well. Try now.

Actually by default setting values are null but after edit password from UI then that value becomes empty string.

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

yes custom domain is http:// only right now as we don't have the feature to add certificates to custom domains yet.

@Jaex
Copy link

Jaex commented Jul 29, 2020

yes custom domain is http:// only right now as we don't have the feature to add certificates to custom domains yet.

But if I edit URL and add https:// prefix manually, then URL opens fine. See: https://kutt.getsharex.com/6I86Qi

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

It's because you're using subdomain and hosting and handling SSL certs. Most domains in Kutt don't have certs except a few I manually added.

@Jaex
Copy link

Jaex commented Jul 29, 2020

If I didn't handle SSL certs for my own domain then why would I want to use https:// link at all with custom domain feature. So I don't get what you mean.

@poeti8
Copy link
Member

poeti8 commented Jul 29, 2020

I am not sure what's your point either. In Kutt, normal links -> https:// links with custom domain -> http:// since Kutt is usually responsible for providing SSL certs and we don't do at the moment.

@Jaex
Copy link

Jaex commented Jul 29, 2020

By the way description parameter is missing in API docs.

@poeti8
Copy link
Member

poeti8 commented Jul 30, 2020

Thanks, added now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants