hello
i had a nasty challenge today, my case problem was having to assemble a web interface to shell scripts.
what better to use other than cgi-bin, yeah yeah, there are pros and cons to that but in this case, this
was the most feasable option to go with.
the first challenge, was the reason why i need to use the shell scripts. the server acts as a gateway client to an external system, in other words there is a shell client set of tools/commands to control external hardware systems. now due to propriatary reasons, the client tools (binaries) are not installed under /bin /usr/bin or /sbin etc. they get installed in their own path /opt/app/bin/command. in addition, the binaries are hardened not get executed or yeld results unless exclusivelly ran as root (lets not debate on this, this is how it is).
so, the first challenge was to bypass the root account limitation, how? by using cgi-bin and including the apache deamon account "httpd" in the /etc/sudoers.
the next trick was to use the software configuration file to allow httpd username execute commands thru sudo.
the third and most challenging part concerned apache itself. apache deamon environmental variable PATH includes the basic set: /usr/bin:/sbin:/usr/sbin. so how was that a challenge? well the challenge was that i did not want to write static paths to the commands in the scripts e.g. /opt/myapp/mycommand -arg1 -arg2 but to get to just use mycommand -arg1 -arg2. why so? simply not to have to rewrite a hell of a lot of scripts to include static paths (which in the long run, with software updates would cause headaches). i didnt want to create symbolic links to /usr/sbin or other existing path due to the same reason, as not to get broken links and followsymlink issues with apache. so what to do?.... after striving with this the whole day, the end result was to hack /usr/sbin/apachectl to include PATH=$PATH:/opt/myapp. now this alone did not resolve everything. for some reason, the default apache init script doesnt note this hack when executing stop/start but a graceful option works. this is easy to hack fix in the init script, just anoying having to hack an init file.
so now i got my /opt/myapp path included to the apache default path variable.
the last trick that i did was ..
instead of ending my scripts with .sh or .pl or whatever, i used .txt? did you guess why? for a very simple reason, different browsers behave in a different way, most of them indentify from the file suffix (.pl/.sh/php/.txt) what file is in question and parses the return stream in accordance. so when i used .txt as a suffice, i avoided having to use html tags and the browser was able to properly interpret \r\n.
so all in all, i got my thing to work and now i can use existing shell scripts with the propriattary software thru cgi-bin without having to hack the scripts and little effort from the server side.
i just hope i will remember these hacks the next time i have to do this again...
i had a nasty challenge today, my case problem was having to assemble a web interface to shell scripts.
what better to use other than cgi-bin, yeah yeah, there are pros and cons to that but in this case, this
was the most feasable option to go with.
the first challenge, was the reason why i need to use the shell scripts. the server acts as a gateway client to an external system, in other words there is a shell client set of tools/commands to control external hardware systems. now due to propriatary reasons, the client tools (binaries) are not installed under /bin /usr/bin or /sbin etc. they get installed in their own path /opt/app/bin/command. in addition, the binaries are hardened not get executed or yeld results unless exclusivelly ran as root (lets not debate on this, this is how it is).
so, the first challenge was to bypass the root account limitation, how? by using cgi-bin and including the apache deamon account "httpd" in the /etc/sudoers.
the next trick was to use the software configuration file to allow httpd username execute commands thru sudo.
the third and most challenging part concerned apache itself. apache deamon environmental variable PATH includes the basic set: /usr/bin:/sbin:/usr/sbin. so how was that a challenge? well the challenge was that i did not want to write static paths to the commands in the scripts e.g. /opt/myapp/mycommand -arg1 -arg2 but to get to just use mycommand -arg1 -arg2. why so? simply not to have to rewrite a hell of a lot of scripts to include static paths (which in the long run, with software updates would cause headaches). i didnt want to create symbolic links to /usr/sbin or other existing path due to the same reason, as not to get broken links and followsymlink issues with apache. so what to do?.... after striving with this the whole day, the end result was to hack /usr/sbin/apachectl to include PATH=$PATH:/opt/myapp. now this alone did not resolve everything. for some reason, the default apache init script doesnt note this hack when executing stop/start but a graceful option works. this is easy to hack fix in the init script, just anoying having to hack an init file.
so now i got my /opt/myapp path included to the apache default path variable.
the last trick that i did was ..
instead of ending my scripts with .sh or .pl or whatever, i used .txt? did you guess why? for a very simple reason, different browsers behave in a different way, most of them indentify from the file suffix (.pl/.sh/php/.txt) what file is in question and parses the return stream in accordance. so when i used .txt as a suffice, i avoided having to use html tags and the browser was able to properly interpret \r\n.
so all in all, i got my thing to work and now i can use existing shell scripts with the propriattary software thru cgi-bin without having to hack the scripts and little effort from the server side.
i just hope i will remember these hacks the next time i have to do this again...