MyBB Community Forums

Full Version: Using myCode to call to cgi or php scripts?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I have a C application I've written for a polygraphic-substitution cipher. I want to implement this on my forum in custom myCode with

[encode][/encode]
and
[decode][/decode]

I want to replace the variable "$1" with the encoded or decoded text respectively, but I would have to call an external script; something like a cgi or a php script to call the C application. I'm not sure if MyBB supports this or how it would be done. To be more clear, can I specify php code inside of the myCode replacement, or is it just HTML. I'm also looking to pipe the encrypted or decrypted strings into something like the code tag. So if I typed something like

"[encode]This is a secret message[/encode]"

E047F086E086D113B131F087G116C132D065E134G116B073G076D106G078B112C132B093F077F115G116F067F085G078C233

Only instead of "CODE" have it say "ENCRYPTED" or "DECRYPTED" respectively.

I assume I can just use the code class from my CSS and a div or span tag, but my templates are a bit customized, so I'm not sure.

Any help with this would be very appreciated. I mostly just need details on how the myCode replacement works, but if anyone has any suggestions on how to do this in php or cgi with POST (important because the encrypted segments are very large ) method calls, let me know. My C applications reads from standard input or a file and writes to standard output or a file, so I think it should work will with a php script or perhaps even a simple bash script.

I can post the applications themselves, but not the source code; I don't wish to release that to anyone yet. This cipher is mostly a pet project of mine, but considering the sensitive nature of encryption like this, I wouldn't want someone to use the source, change the key, and then use the structure of my cipher for anything mischievous. If it's closed-source, at least any code generated with it won't ever be used for wrong-doing because of how easily decrypted it would be. I thought it might be useful on my forum however, because we often share bits and pieces of programming code, and this often leads to many webcrawlers scanning the code. Any search engine or crawler will simply see this random code instead of anything anything else.
You can use the php function exec() and you can build a plugin to link that call into MyCode
Tikitiki Wrote:You can use the php function exec() and you can build a plugin to link that call into MyCode
Any good tutorials you know for doing this?
I would actually suggest either:
1) Rewriting it in PHP. PHP's syntax is very similar to C's, so you shouldn't need to change too many things
2) Writing a PHP extension - dunno, but I feel it safer and more efficient than calling exec() all the time

For exec() http://au.php.net/function.exec
ZiNga BuRgA Wrote:I would actually suggest either:
1) Rewriting it in PHP. PHP's syntax is very similar to C's, so you shouldn't need to change too many things
2) Writing a PHP extension - dunno, but I feel it safer and more efficient than calling exec() all the time

For exec() http://au.php.net/function.exec

Well, unfortunately I don't know enough about PHP to translate it from C. This is why I was hoping I could just a php script to call the C application itself. The problems I've having now are

1. Sending the information to the program in POST form from the myCode dialog
2. Making this something that will replace the call with the output

I'm not sure of what HTML tags I could use for this or what kind of script I'd need to return the data. I had used an <iframe> tag with the source set as a .cgi script, but that was using the GET method, so the whole thing looked like

<iframe src=encode.cgi?=$1>

The problem is that the web-parsing that happens to the link in the GET methods caused things like, "%3D" to be encoded instead of the real character. Another problem is that if the URL is too large, Apache won't accept it.

I'm wondering if anyone could write me a quick php function that pipes $1 into a system command, somewhat like the system() function in C. The only issue here is that my programs read from standard input or a file, so the data in $1 would have to be piped in from standard input. Thus the system command would have to look something like this

 echo $1( or whatever needed in the respective language to refer to it ) | encode 

Unfortunately, I know very little about php to know whether this would be simple or not.