Troubleshooting

From Jesse's Wiki
Revision as of 23:36, 22 July 2021 by Jesse (talk | contribs) (added cryptography)
Jump to navigation Jump to search

This page aims to record the solutions to obscure problems.

GitHub

To delete a release, do not click on "Edit", instead click the release title name. Then the "Delete" button will be available.

Citrix

Use the web version when possible. To download a file, use the "download" icon which should appear. It may not be possible to use the Windows Explorer interface anymore.

Cryptography

Windows has RijndaelManaged (AES) built in. For some reason I thought it would be my first attempt on learning encrypting/decrypting The method needs an Initial Vector (IV) and a random key. Both of these are generated and used to encrypt. They must be saved with the encrypted data or else it cannot be decrypted. The IV isn't important and can be public. The key should not be public. This is similar to Public-Key cryptography but not the same.

For my purposes I'm just encrypting a password on a local machine

https://crypto.stackexchange.com/questions/3965/what-is-the-main-difference-between-a-key-an-iv-and-a-nonce

https://www.titanwolf.org/Network/q/cc102a94-8ad9-4d8e-8da4-379b6fb92dad/y

https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.rijndaelmanaged?view=net-5.0

Simultaneously I'm learning how to use ADODB stream object for the first time

objStream.Type = 1 'adTypeBinary
	objStream.Open
	objStream.Write(mykey)	
	objStream.savetofile "key"

Make sure the type is set to 1 and Write is used. Both are for binary which is what the AES IV and KEY are.

HTA

When using HTA to open a vbscipt with cscript.exe, you can communicate directly with the script using the Stdout property. So long as the script was launched using shell.exec method. shell.run method is acceptable but it only returns an error level.

exec method to work needs to have the shell set to an object. blah = shell.exec ( blah blah). Then use blah.Stdout.ReadLine() or ReadAll().

This seems most useful for quick scripts where I want to return a single value. I can't seem to get live updates synchronously with the script as described here

It would be better to have live read outs update to the HTA so the console screen can be avoided entirely, giving the HTA a more "program" feel.


This explains when you want the window to stay open, e.g. use pause for the "press any key to continue" or just keep it alive until they click on the x.


Okay apparently using setInterval in the HTA will allow me to read the Stdout without locking the application...

       setInterval(function(){ document.getElementById(6).innerHTML = blah.StdOut.ReadLine(); }, 1000);

MSDN


But now I can't run the shell minimized or stop it from taking focus.

Run vs Exec comparison [1]

Shell.run needs path in quotes for folders and file names with spaces. FSO requires the path to not have quotes at all.

javascript (and vbscript) is synchronous. Therefore I need to use a web api function to act asynchronously https://www.freecodecamp.org/news/thrown-for-a-loop-understanding-for-loops-and-timeouts-in-javascript-558d8255d8a4/#:~:text=Every%20time%20we%20loop%2C%20setTimeout%20%28%29%20is%20passed,loop%2C%20followed%20by%20console.log%20%28%E2%80%98The%20loop%20is%20done%21%E2%80%99%29.

Bash Shell

Here's me trying to rename tv shows...

https://wiki.bash-hackers.org/syntax/pattern

for file in *.mp4; do echo mv "$file" "${file//./ }"; done

for file in *.mp4; do echo mv "$file" "${file//.[!.mp4]/ }"; done

for file in *.mp4; do echo mv "$file" "${file[^.mp4]}"; done

for file in *.mp4; do echo mv "$file" "${file/*.S??E*/ }"; done




for file in *.mp4; do echo mv "$file" "${file/.S??E??*}"; done

for file in *.mp4; do echo mv "$file" "${file/.S??E??*/${file%S??E??}}"; done

for file in *.mp4; do echo mv "$file" "${file%%.S??E??*}"; done

for file in *.mp4; do echo mv "$file" "${file%%\?*}"; done

.HTACCESS

https://httpd.apache.org/docs/current/mod/mod_rewrite.html

not for redirecting, but for changing the appearance of URLs. My website has the format jjjp.ca/1/22/whatever, where the 1/22 is accepted as a valid URL by the HTACCESS RewriteRule. The actual redirect is done by the php file.

In reality my website's url is jjjp.ca/single.php?post=22. The RewriteRule translates it for the outside. Internally the php sees the real url.


So when trying to import my old website, I thought I could just use my index.php to send the old urls to the single.php. What I now have figured out is that it's index.php's job to do the entire redirect. So jjjp.ca/?p=blablah is received by index.php which performs the redirect to jjjp.ca/0/blablah. It's HTACCES's job to register that as a valid url and to translate it internally as jjjp.ca/single.php?oldwebsitepost=blablah.


In order for that to work I had to adjust the RewriteRule to include any character between the two forward slashes, otherwise it wouldn't recognize a URL more than 4 characters between the slashes, like the RewriteRule for my current website's posts.

RewriteRule   "^0/(.*)(/.+)?$"   "/single.php?oldwebsitepost=$1" [NC,L]