Score:0

Substitute a string into timestamp

cn flag

I want to use mod_substitute or mod_ext_filter to replace a string with the current timestamp in miliseconds.

I tried so far, but it's not working.

Substitute "1s/myString/&$(date +"%T.%3N")/"

ExtFilterDefine testfilter mode=output intype=text/html cmd=/bin/echo "$(sed -E "1s/myString/&$(date +"%T.%3N")/")"

Does someone has the idea to get this running? I was also thinking about, to combine it with ssi, but also not working.

Score:0
cn flag

From reading the mod_substitute documentation, I cannot find a single reference as to why you would think it would work with executing an external process (or forking a shell, or anything of that sort). So I would not consider this route to be a viable one.

mod_ext_filter, on the other hand, seems adapted to what you wish to do. However, to quote its documentation:

This filtering mechanism is much slower than using a filter which is specially written for the Apache API and runs inside of the Apache server process

So, if I were you, I'd consider using a dynamic language such as PHP (which was initially written for this very use case), or eventually writing a very small C program to do what you want, as it would end up much faster, and it isn't too hard.


Now, if you want to persist with your idea, don't use /bin/echo. The substitution you wrote in "$(sed -E "1s/myString/&$(date +"%T.%3N")/")" requires a shell, and /bin/echo will not spawn one. Therefore, you need to either write a script (solution I would recommend), or at least call /bin/sh (or /bin/bash if you're so inclined) with the proper arguments: -c 'var="$(date +"%T.%3N")"; sed -E "1s/myString/&$var/"'.

It's really hacky, and I maintain a PHP script or a C program would be simpler in the long run, but to each their own.

the_floor avatar
cn flag
@ 7heo.tk: thanks a lot. Some more input, why I want to do it. My goal is to prevent hacker tools like WPSCAN to detect my version number and more informations. This tool scans lot of css and js files. So I want to use this filter, to add a simple timestamp in miliseconds, just before the file input will be delivered to the browser etc. This way I can change the md5 hash and WPSCAN can't get my details. Could you give me more details, to do it in php? I don't want to change the file permantly, I want just to add some extra output, if someone or something send a request to this files.
the_floor avatar
cn flag
I tried to follow your advice: But after adding your code, I can' restart the apache server - I get an error. ```ExtFilterDefine testfilter mode=output intype=text/html cmd="/bin/bash -c 'var="$(date +"%T.%3N")"; sed -E "1s/Ninja/&$var/""``` ```SetOutputFilter testfilter```. Did I set the wrong quotes?
cn flag
Yes, I believe those quotes are wrong. Given the amount of quoting, I would personally put all that in a script, and just set the script to executable for all (`chmod a+x`), and then put the full path (something like [`/usr/local/bin/myapachefilter`](http://paste.debian.net/hidden/b381a2c0/)) in the `cmd` field. On another note, we should avoid discussing in the comments, so maybe we should start a chat session?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.