Rusty's Website

A place for wanky stuff, weird JavaScript and warm-ish takes

About Source


decentralized mmoindexinjector


Source Code

So, I have finally made the html "injector" I wanted to make for ages before I could really start working on this website...

I guess it ain't really an "Injector", but rather it detects a special <INJECT> tag in html files, and replaces them in what lies between the opening and closing tag, so something like:
<INJECT>echo Hello world<∖INJECT>
will result in the text:
Hello world
which allows me to use bash and THE POWER OF UNIX TERMINAL to auto update things on my website(like a unified header, footer and such).

It also provides 3 env variables with useful values:

This allows me to do stuff like injecting the files in the directory the current page sits in, and, because it runs the command in bash, I also get to pipe it around,
letting me tranform the output of ls for example, to simple <a> tags using a simple python script
and a call to python3 (the actual commands are in the top of the source code of this page for example)

But, can't it leak critical information to the outside world?

I am not a security expert, but you have full control over the commands, and they are run on the server/compiling machine during compile time
so unless you let random people push compiling web pages, it shouldn't have any risks involved.

If your website is open source(like mine) or source available,
you can just use commands that are in the same directory as the compiling websites (like i keep the build scripts in the bscripts folder).

Interesting notes from making it using Rust

Overall, it is a 188 lines main file, using 0 dependencies(apart from std),
I did a really simple arguments parser, which will prob be a pain for people who aren't me.

Running a command/process is really nice when using the Command struct, with fun builder functions(and easily lets you read its output)

The whole OsStr vs str/String is really annoying, and made me do a lot of to_str().unwrap()

Generally speaking tho, I have 31 unwrap()s in my code,
which I WILL need to remove(at least most of them),
I also have 3 unsafe blocks, 2 for using a static variable, and another 1 for lossly converting a [u8] to &str.

The original plan

The original plan was different, I initially wanted a fully real time thingy, with specific items in mind,
and only yesterday(10/6/22) I decided to just have simple commands,
which later(roughly 3 minutes after finishing the first draft)
I decided to make into a bash commands, to better have what I aimed for

Rust can be annoing sometimes

Rust can be a bitch when it comes to handling strings, especially when you compare it to C,
where every string is a byte array, and you just handle it as such...

Yes, I know this is due to characters not being uniform in length when using UTF-8,
and I know that C can fuck everything up if you dont watch out for multiple length bytes,
but it's just soo easy destroying strings there and you can just manipulate a string so easily,
without any extra functions or allocations or anything really...

Still glad I used Rust

I'm kind of a Rust fanboy(catgirl), because it lets you not worry about a lot of things, and mostly because of it STRONG type system, so it aint a surprise I used it
(and glad because of it)

The repetuar of my languages isn't big, it's actually kinda small, I know Rust well, I can do C quite easily(although I will need a lot of debugging), I have a lot of experience with C#, and can do JavaScript, Java(tho not really), Python and probably some more but very slowly.also want to rely on it less and less
(i can also do GDScript if you consider it, as it can only run, afaik, in Godot)

So it is usually either using Rust, or C, since I will (hopefully) wont use python for something big(more than 50 lines of code), and C# feels locked away on linux(and I don't want to use it outside of work).