]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/misc-progs/ipfirereboot.c
2 * This file is part of the IPCop Firewall.
4 * IPCop is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * IPCop is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with IPCop; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Copyright (C) 2005-10-25 Franck Bourdonnec
20 * $Id: ipcopreboot.c,v 1.1.2.2 2005/10/24 23:05:50 franck78 Exp $
30 /* define operations */
31 #define OP_REBOOT "boot"
32 #define OP_REBOOT_FS "bootfs" // add filesystem check option (not yet in GUI)
33 #define OP_SHUTDOWN "down"
34 #define OP_SCHEDULE_ADD "cron+"
35 #define OP_SCHEDULE_REM "cron-"
36 #define OP_SCHEDULE_GET "cron?"
38 int main(int argc
, char**argv
)
44 // Check what command is asked
47 fprintf (stderr
, "Missing reboot command!\n");
51 if (argc
==2 && strcmp(argv
[1], OP_SHUTDOWN
)==0)
53 safe_system("/sbin/shutdown -h now");
57 if (argc
==2 && strcmp(argv
[1], OP_REBOOT
)==0)
59 safe_system("/sbin/shutdown -r now");
63 if (argc
==2 && strcmp(argv
[1], OP_REBOOT_FS
)==0)
65 safe_system("/sbin/shutdown -F -r now");
69 // output schedule to stdout
70 if (argc
==2 && strcmp(argv
[1], OP_SCHEDULE_GET
)==0)
72 safe_system("/bin/grep /sbin/shutdown /var/spool/cron/root.orig");
76 if (argc
==2 && strcmp(argv
[1], OP_SCHEDULE_REM
)==0)
78 safe_system("/usr/bin/perl -i -p -e 's/^.*\\/sbin\\/shutdown.*$//s' /var/spool/cron/root.orig");
79 safe_system("/usr/bin/fcrontab -u root -z");
83 if (argc
==6 && strcmp(argv
[1], OP_SCHEDULE_ADD
)==0)
86 if (!( strlen(argv
[2])<3 &&
87 strspn(argv
[2], "0123456789") == strlen (argv
[2]) &&
89 strspn(argv
[3], "0123456789") == strlen (argv
[3]) &&
91 strspn(argv
[4], "1234567,*") == strlen (argv
[4]) &&
92 ((strcmp(argv
[5], "-r")==0) || //reboot
93 (strcmp(argv
[5], "-h")==0)) ) //hangup
95 fprintf (stderr
, "Bad cron+ parameters!\n");
100 safe_system("/usr/bin/perl -i -p -e 's/^.*\\/sbin\\/shutdown.*$//s' /var/spool/cron/root.orig");
104 if ((fd
= fopen("/var/spool/cron/root.orig", "a")))
106 fprintf (fd
,"%s %s * * %s /sbin/shutdown %s 1\n",argv
[2],argv
[3],argv
[4],argv
[5]);
111 safe_system("/usr/bin/fcrontab -u root -z");
115 fprintf (stderr
, "Bad reboot command!\n");