Skip to content

fix: cookies removed on failed connection - #5

Open
soodoh wants to merge 1 commit into
myanonamouse:mainfrom
soodoh:fix-cookies
Open

fix: cookies removed on failed connection#5
soodoh wants to merge 1 commit into
myanonamouse:mainfrom
soodoh:fix-cookies

Conversation

@soodoh

@soodoh soodoh commented Aug 7, 2025

Copy link
Copy Markdown

Fixes issue:
#2

Potentially fixes #1, but could not reproduce.

Made some formatting, readability changes as well, but can move to a separate PR if preferred.
So far this is working for me when building the image locally and dropping it in as a replacement in my compose file.

Superseded previous PR: #3

Comment thread wrapper.sh

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly some opinionated formatting changes here to improve readability. Can revert anything if preferred.

Comment thread wrapper.sh
Comment on lines +8 to +11
OLD_IP_FILE=/tmp/MAM.ip
RESPONSE_FILE=/tmp/MAM.output
TEMP_COOKIE_FILE=/tmp/MAM.cookies
COOKIE_FILE=/config/MAM.cookies

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed variables to have more meaning. For example, there are multiple temporary, cached files, so CACHEFILE would be confusing. Also using SCREAMING_SNAKE_CASE since I find this easier to read instead of concatenating words together.

Comment thread wrapper.sh
echo "New IP detected"
# Save cookie jar to temporary file, to not overwrite
# with empty cookies on failed requests
curl -s -b $COOKIE_FILE -c $TEMP_COOKIE_FILE https://t.myanonamouse.net/json/dynamicSeedbox.php > $RESPONSE_FILE

@soodoh soodoh Aug 7, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the crux of the fix. When using the -c flag with curl, it writes all the cookies to the file passed here (even on failed requests, it will write empty cookies). Here's a relevant snippet from man curl:

       -c, --cookie-jar <filename>
              (HTTP) Specify to which file you want curl to write all cookies after a completed operation. curl  writes
              all  cookies  from  its  in-memory  cookie storage to the given file at the end of operations. Even if no
              cookies are known, a file is created so that it removes any formerly existing cookies from the file.  The
              file  uses  the  Netscape cookie file format. If you set the filename to a single minus, "-", the cookies
              are written to stdout.

Comment thread wrapper.sh
Comment on lines +93 to +94
# Update COOKIE_FILE only on successful requests
mv $TEMP_COOKIE_FILE $COOKIE_FILE

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other relevant part of this fix. Everything else is formatting or variable name changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Last change too recent treated as a fatal error on first run

1 participant