privacy.sexy icon indicating copy to clipboard operation
privacy.sexy copied to clipboard

Ideas for cleaner code

Open couleurm opened this issue 2 years ago • 2 comments

Problem description

Repetitive and very long code for disabling services with PowerShell

Proposed solution

  • Batch functions, add at the end of the file if the user ticked any script that use it so it can be CALLed

  • Switch to using PowerShell using a batchfile that opens posh to run itself: One solution I made for a similar project I'm working on is to have one function per file, then use CI to add up every file to one single file that can then be imported in the current PowerShell session with one command:

Invoke-RestMethod https://github.com/couleur-tweak-tips/TweakList/raw/master/Master.ps1 | Invoke-Expression

The advantage is that it can be used from the command-line with auto-completion, you can also paste multiple lines at once, and it looks pretty You could also add an option to make an self contained/offline package that adds the functions declared in the script itself so the script doesn't need internet access.

Additional information

This is not a clear feature request, I'm just sharing some of my thoughts that you may find useful

couleurm avatar Jun 14 '22 05:06 couleurm

Thank you for your feedback. These discussions have real value. Here are my opinions, but do not take my opinions as any decision made or objective truth, but more like my subjective points that can guide the ideas.

  • Using PowerShell functions would not work because we wrap PowerShell scripts inside batchfile commands. The reason is that batch (as a wrapper) is used because it is more generally available and works on computers that do not allow running PowerShell scripts directly. 
  • I consider offline functions a requirement. Our goal is to increase privacy. It would not be privacy-enhancing to enforce online usage of remote scripts. It adds potential vulnerabilities (like a remote script doing unexpected stuff) and sends data to GitHub. Furthermore, it cannot be used by offline computers. 
  • Using batch functions would be fine. But as batchfile is probably the worst scripting language that's still available, I don't know how much it would help other administrators. Does anyone want to re-use these functions if they're not PowerShell?
  • Adding function calls would remove the "independently executable scripts" approach that privacy.sexy has. It means that any script created can be copied and will work without analyzing complex calls. I'm not sure if it is something that the community appreciates though; I never got any feedback on that. 
  • It would increase the complexity of generating the script and necessitate more logic on the compiler's part to determine whether to include the functions in the generated script.

Sophia script is a great project that probably does what privacy.sexy is not doing on this matter. We're just solving different problems using different approaches.

undergroundwires avatar Oct 17 '22 17:10 undergroundwires

computers that do not allow running PowerShell scripts directly.

Execution policy only annoys you when running .ps1 files, I don't think I need to mention the countless ways to bypass it

I consider offline functions a requirement.

As I said, you can add them up to a single file with CI

Sophia script is a great project

Love farag's project, made this to import it's functions easily


As I'm working on TweakList I asked a friend of mine (@RichardDorian) to make a web-ui similar to privacy.sexy so people can use my module's functions without having to dive into the docs to learn all the syntax,

My functions will have lots of parameters to tune for the user, so I made a second CI script to generate manifests for the documented functions for all the parameters and their quirks.

To generate the GUI my friend places where the JSON values will be put. Then it loops over all manifest values to generate a page for each of them. When the user selects it it'll build up function call with parameters

When exporting it'll have the option to either make a very small online script or to have all the required functions declared in a much longer but offline file

Sharing this since we do something similar, we might give eachother good ideas 👍

couleurm avatar Nov 05 '22 22:11 couleurm