Looks great - good job! I would like to integrate this into m0n0wall 1.8.x if that's OK with you; not just as an extension, but as an integral part (perhaps under the "Services" section). Assuming that you agree with this, could you please post the code somewhere?
Regards,
Manuel
I'd really appreciate that! I've been a bit busy the last two days so I wasn't able to continue the work. How would you like to proceed?
The php files for adding/deleting/editing "jobs" aren't ready yet and I'm still using placeholders for the configuration because I don't have a configuration file for now. So my idea would be that I take a look at your function for writing/reading the xml configuration file and try to use it. Then I'll finish the php files and let you integrate them. In this state the php files would require a lot of work from you that I am willing to do.Already done. As stated above I've used your function to write into the xml configuration file. Now it's just about adding the jobs. I'll probably do that tomorrow.
However, there is one thing I'd like to skip for now which is implementing the enable/disable wireless feature because I guess this isn't as easy to write as a "reboot" feature and I'd rather finish the webinterface scripts. Maybe you have a suggestion how to implement this feature easily.
Something that probably won't change anymore is the croen daemon which basically is a modified version of minicron.c. Here it is:
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
/* usage: croen 1:job 2:interval 3:pidfile 4:cmd 5:silent */
int main(int argc, char *argv[]) {
/* not enough arguments? exit! */
if (argc < 6)
exit(1);
/* define vars */
int interval, silent;
FILE *pidfd;
interval = atoi(argv[2]);
silent = atoi(argv[5]);
/* interval 0? exit! */
if (interval == 0)
exit(1);
/* unset loads of CGI environment variables */
unsetenv("CONTENT_TYPE"); unsetenv("GATEWAY_INTERFACE");
unsetenv("REMOTE_USER"); unsetenv("REMOTE_ADDR");
unsetenv("AUTH_TYPE"); unsetenv("SCRIPT_FILENAME");
unsetenv("CONTENT_LENGTH"); unsetenv("HTTP_USER_AGENT");
unsetenv("HTTP_HOST"); unsetenv("SERVER_SOFTWARE");
unsetenv("HTTP_REFERER"); unsetenv("SERVER_PROTOCOL");
unsetenv("REQUEST_METHOD"); unsetenv("SERVER_PORT");
unsetenv("SCRIPT_NAME"); unsetenv("SERVER_NAME");
/* go into background */
if (daemon(0, 0) == -1)
exit(1);
/* write PID to file */
pidfd = fopen(argv[3], "w");
if (pidfd) {
fprintf(pidfd, "%d\n", getpid());
fclose(pidfd);
}
/* wait... */
sleep(interval);
/* write syslog message if required */
if (!silent) {
openlog("croen daemon", 0, LOG_NOTICE);
syslog(LOG_NOTICE, "Job %s executed", argv[1]);
closelog();
}
/* remove PID file */
remove(argv[3]);
/* execute */
char command[100];
sprintf(command, "/usr/local/bin/php %s", argv[4]);
system(command);
}
And don't worry, the script will not just calculate the seconds to the next schedule and run the daemon.
Edit: See strikethrough lines.