Found. Redirected when using codimd import
MelBourbon opened this issue · 12 comments
If the following environment variables are set
CMD_ALLOW_ANONYMOUS=false
CMD_ALLOW_EMAIL_REGISTER=false
import with cli is not possible. Found. Redirected
is output.
If environment variable are set to true
import is possible but ownership of imported note is not the user who logged in before by cli.
Can you try running this command directly and pasting the output here:
curl -v -XPOST -H 'Content-Type: text/markdown' --data-binary path/to/file.md "https://your-server.de/new"
I did some further investigation and it's related to the environmental variables I set. I had set
CMD_ALLOW_ANONYMOUS=false
CMD_ALLOW_FREEURL=false
CMD_DEFAULT_PERMISSION=private
CMD_ALLOW_PDF_EXPORT=true
CMD_ALLOW_EMAIL_REGISTER=false
If I comment these out import is possible.
The only issue I have then is that I need to open the note with the ID first to get it shown in the history and that the permission for this note is freely and I can not change it. So the note is not owned by me. Do I need to extend the import command to ensure this?
Is the curl output still needed for further investigation which variable the reason behind this is?
I updated the first post to reflect the now more precise issue.
Fixed in hackmdio/hackmd-cli@063634d.
Let me know if works.
First, environmental variables need still to be set to
CMD_ALLOW_ANONYMOUS=false
CMD_ALLOW_EMAIL_REGISTER=false
Otherwise error is Found.Redirected
.
With that import is possible. But note has permissions "freely" which can not be changed since note is not owned by user logged in (in cli). In addition note does not show up in history of user who imported.
Hmm that's strange because it should be using whatever cookies you set when you did codimd login
. I'm not sure what's causing it not to authenticate when using the new note endpoint.
Can you confirm that your $CODIMD_COOKIES_FILE
has valid cookies set in it after logging in?
Check the file manually and use the codimd profile
command to confirm it.
Ah, I was just about to report the same. For me neither import nor export are working. Other commands like history and profile are still working.
I have recently upgraded to codimd 1.3.0, not sure if this is related to this.
PS: I have started doing some refactoring work on codimd-cli before hitting this issue. my current wip can be found at hackmdio/hackmd-cli@master...fbartels:refactor
That refactoring looks great, PR anytime and I'll review + merge it. I'm still unable to reproduce this personally (could be because I'm still on an older HackMD version).
I still need this curl output from either of you to debug the failing import:
curl -v -c path/to/cookies.txt -XPOST -H 'Content-Type: text/markdown' --data-binary path/to/file.md "https://your-server.here/new"
Sure, not quite done yet with the refactor, though. Will open a pr once I am happy with it myself.
Here is the output of the command you asked for:
$ curl -v -c $HOME/.config/codimd-cli/key.conf -XPOST -H 'Content-Type: text/markdown' --data-binary path/to/file.md "https://codimd.9wd.eu/new"
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 94.16.123.209...
* Connected to codimd.9wd.eu (94.16.123.209) port 443 (#0)
* found 148 certificates in /etc/ssl/certs/ca-certificates.crt
* found 592 certificates in /etc/ssl/certs
* ALPN, offering http/1.1
* SSL connection using TLS1.2 / ECDHE_RSA_AES_256_GCM_SHA384
* server certificate verification OK
* server certificate status verification SKIPPED
* common name: codimd.9wd.eu (matched)
* server certificate expiration date OK
* server certificate activation date OK
* certificate public key: RSA
* certificate version: #3
* subject: CN=codimd.9wd.eu
* start date: Sat, 23 Feb 2019 10:00:34 GMT
* expire date: Fri, 24 May 2019 10:00:34 GMT
* issuer: C=US,O=Let's Encrypt,CN=Let's Encrypt Authority X3
* compression: NULL
* ALPN, server accepted to use http/1.1
> POST /new HTTP/1.1
> Host: codimd.9wd.eu
> User-Agent: curl/7.47.0
> Accept: */*
> Content-Type: text/markdown
> Content-Length: 15
>
* upload completely sent off: 15 out of 15 bytes
< HTTP/1.1 302 Found
< Server: nginx/1.10.3 (Ubuntu)
< Date: Sat, 09 Mar 2019 08:25:59 GMT
< Content-Type: text/plain; charset=utf-8
< Content-Length: 43
< Connection: keep-alive
< X-Powered-By: Express
< Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
< Content-Security-Policy: default-src 'self'; script-src 'self' vimeo.com https://gist.github.com www.slideshare.net https://query.yahooapis.com 'unsafe-eval' https://disqus.com https://*.disqus.com https://*.disquscdn.com https://www.google-analytics.com 'nonce-f34c3254-901d-42ea-bfbd-0f452079b496' 'sha256-Lc+VnBdinzYTTAkFrIoUqdoA9EQFeS1AF9ybmF+LLfM='; img-src *; style-src 'self' 'unsafe-inline' https://github.githubassets.com https://*.disquscdn.com; font-src 'self' data: https://public.slidesharecdn.com https://*.disquscdn.com; object-src *; media-src *; child-src *; connect-src *
< X-Content-Security-Policy: default-src 'self'; script-src 'self' vimeo.com https://gist.github.com www.slideshare.net https://query.yahooapis.com 'unsafe-eval' https://disqus.com https://*.disqus.com https://*.disquscdn.com https://www.google-analytics.com 'nonce-f34c3254-901d-42ea-bfbd-0f452079b496' 'sha256-Lc+VnBdinzYTTAkFrIoUqdoA9EQFeS1AF9ybmF+LLfM='; img-src *; style-src 'self' 'unsafe-inline' https://github.githubassets.com https://*.disquscdn.com; font-src 'self' data: https://public.slidesharecdn.com https://*.disquscdn.com; object-src *; media-src *; child-src *; connect-src *
< X-WebKit-CSP: default-src 'self'; script-src 'self' vimeo.com https://gist.github.com www.slideshare.net https://query.yahooapis.com 'unsafe-eval' https://disqus.com https://*.disqus.com https://*.disquscdn.com https://www.google-analytics.com 'nonce-f34c3254-901d-42ea-bfbd-0f452079b496' 'sha256-Lc+VnBdinzYTTAkFrIoUqdoA9EQFeS1AF9ybmF+LLfM='; img-src *; style-src 'self' 'unsafe-inline' https://github.githubassets.com https://*.disquscdn.com; font-src 'self' data: https://public.slidesharecdn.com https://*.disquscdn.com; object-src *; media-src *; child-src *; connect-src *
< CodiMD-Version: 1.3.0
< Location: https://codimd.9wd.eu
< Vary: Accept, Accept-Encoding
* Added cookie connect.sid="cookie" for domain codimd.9wd.eu, path /, expire 1553329559
< set-cookie: connect.sid=cookie; Path=/; Expires=Sat, 23 Mar 2019 08:25:59 GMT; HttpOnly
< Strict-Transport-Security: max-age=15768000
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Download-Options: noopen
< X-Content-Type-Options: nosniff
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: no-referrer-when-downgrade
<
* Connection #0 to host codimd.9wd.eu left intact
I think the problem is that there is a typo in the "import_note" function (line 39-41). The curl -q -c
should be curl -q -b
.
function import_note() {
curl -q -b $CODIMD_COOKIES_FILE -XPOST -H 'Content-Type: text/markdown' --data-binary "@$1" "$CODIMD_SERVER/new" 2>/dev/null | perl -pe 's/Found. Redirecting to \/(.+?)$/$1\n/gs'
}
It fixes the ownership and permission problems. But the note cannot show in your account history records. You need to open the note first, and then it will be in your history. I checked the backend psql database. After importing with codimd import
, a new note was generated in the Notes
table, but it's not linked in the Users
table. I don't know how to fix this.
Thanks for pointing out that typo @frankyan, just pushed a patch for that mistaken argument in two places: hackmdio/hackmd-cli@adf97bc
Closing for now since a few fixes have been pushed. Let me know if you’re still having issues on the latest master and I’ll reopen this.