--- /dev/null
+#!/usr/bin/perl
+#
+# Library file for Connection Scheduler AddOn
+#
+# This code is distributed under the terms of the GPL
+#
+
+package CONNSCHED;
+
+$CONNSCHED::maxprofiles = 5;
+
+@CONNSCHED::weekdays = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' );
+@CONNSCHED::weekdays_pr = ( 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday' );
+
+%CONNSCHED::config;
+$CONNSCHED::configfile = "/var/ipfire/connscheduler/connscheduler.conf";
+&ReadConfig;
+
+
+1;
+
+#
+# load the configuration file
+#
+sub ReadConfig
+{
+ # datafileformat:
+ # active,action,profilenr,time,daystype,days,weekdays,,comment
+
+ @CONNSCHED::config = ();
+
+ my @tmpfile = ();
+ if ( open(FILE, "$configfile") )
+ {
+ @tmpfile = <FILE>;
+ close (FILE);
+ }
+
+ foreach $line ( @tmpfile )
+ {
+ chomp($line); # remove newline
+ my @temp = split(/\,/,$line,9);
+ if ( ($temp[0] ne 'on') && ($temp[0] ne 'off') ) { next; }
+
+ my $weekdays_pr = '';
+ for (my $i = 0; $i < 7; $i++)
+ {
+ if ( index($temp[6], $CONNSCHED::weekdays[$i]) != -1 )
+ {
+ $weekdays_pr .= "$Lang::tr{$CONNSCHED::weekdays_pr[$i]} ";
+ }
+ }
+
+ push @CONNSCHED::config, { ACTIVE => $temp[0], ACTION => $temp[1], PROFILENR => $temp[2], TIME => $temp[3],
+ DAYSTYPE => $temp[4], DAYS => $temp[5], WEEKDAYS => $temp[6], WEEKDAYS_PR => $weekdays_pr, COMMENT => $temp[8] };
+ }
+}
+
+#
+# write the configuration file
+#
+sub WriteConfig
+{
+ open(FILE, ">$configfile") or die 'hosts datafile error';
+
+ for my $i ( 0 .. $#CONNSCHED::config )
+ {
+ if ( ($CONNSCHED::config[$i]{'ACTIVE'} ne 'on') && ($CONNSCHED::config[$i]{'ACTIVE'} ne 'off') ) { next; }
+
+ print FILE "$CONNSCHED::config[$i]{'ACTIVE'},$CONNSCHED::config[$i]{'ACTION'},$CONNSCHED::config[$i]{'PROFILENR'},";
+ print FILE "$CONNSCHED::config[$i]{'TIME'},$CONNSCHED::config[$i]{'DAYSTYPE'},";
+ print FILE "$CONNSCHED::config[$i]{'DAYS'},$CONNSCHED::config[$i]{'WEEKDAYS'},,$CONNSCHED::config[$i]{'COMMENT'}\n";
+ }
+ close FILE;
+
+ &ReadConfig();
+}
+++ /dev/null
-sub genmenu
-{
- ... snip ...
- if ( ! -e "${General::swroot}/proxy/enable" && ! -e "${General::swroot}/proxy/enable_blue" ) {
- splice (@{$menu{'2.status'}{'subMenu'}}, 4, 1);
- splice (@{$menu{'7.mainlogs'}{'subMenu'}}, 2, 1);
- }
-
- # Read additionnal menus entry
- # this have to be hardened and accepted. To be extended.
- opendir (DIR, "${General::swroot}/addon-menu");
- while (my $menuitem = readdir (DIR)) {
-
- if ( $menuitem =~ /^menu\.([1-6]\..*)\..*/) { #model is "menu.(N.submenu).filename"
- my $submenu = $1;
- open (FILE,"${General::swroot}/addon-menu/$menuitem") or die;
- while (my $text = <FILE>) { # file may content many entry
- splice (@{$menu{$submenu}{'subMenu'}} ,-1,0, [ eval($text) ] );
- }
- close (FILE);
- }
- }
- closedir (DIR);
-}
'title' => "$tr{'aliases'}",
'enabled' => 0,
};
+ $subnetwork->{'80.wakeonlan'} = {
+ 'caption' => $tr{'WakeOnLan'},
+ 'uri' => '/cgi-bin/wakeonlan.cgi',
+ 'title' => "$tr{'WakeOnLan'}",
+ 'enabled' => 1,
+ };
my %subserviceshash = ();
my $subservices = \%subserviceshash;
if (! blue_used()) {
$menu->{'05.firewall'}{'subMenu'}->{'30.wireless'}{'enabled'} = 0;
}
- if (! $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
+ if ( $ethsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $ethsettings{'RED_TYPE'} eq 'STATIC' ) {
$menu->{'03.network'}{'subMenu'}->{'70.aliases'}{'enabled'} = 1;
}
}
#
-# $Id: crontab,v 1.9.2.5 2005/08/16 05:39:23 gespinasse Exp $
+# crontab for ipfire
#
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
find /var/log/logwatch/ -ctime +${LOGWATCH_KEEP=56} -exec rm -f '{}' ';'
# hddshutdown
-00 * * * * /usr/local/bin/hddshutdown >/dev/null
+02 * * * * /usr/local/bin/hddshutdown >/dev/null
# URL Filter
%nightly * 3-5 /var/ipfire/urlfilter/autoupdate/cron.daily
%weekly * 3-5 /var/ipfire/urlfilter/autoupdate/cron.weekly
%monthly * 3-5 * /var/ipfire/urlfilter/autoupdate/cron.monthly
+
+# connection-scheduler
+*/5 * * * * /usr/local/bin/connscheduler timer > /dev/null
--- /dev/null
+#!/usr/bin/perl
+#
+# IPCop Connection Scheduler Web-Iface
+#
+# This code is distributed under the terms of the GPL
+#
+
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+require '/var/ipfire/connscheduler/lib.pl';
+
+my $buttontext = $Lang::tr{'add'};
+my $hiddenvalue = 'add';
+my $day;
+my $hour;
+my $minute;
+my %temppppsettings=();
+my @profilenames=();
+
+
+#
+# defaults for settings
+#
+my $selected_hour = '00';
+my $selected_minute = '00';
+my $checked_connect = "checked='checked'";
+my $checked_profile = '';
+my %selected = ();
+$selected{'reconnect'} = '';
+$selected{'dial'} = '';
+$selected{'hangup'} = '';
+$selected{'reboot'} = '';
+$selected{'shutdown'} = '';
+my $selected_profile = 1;
+my $checked_days = "checked='checked'";
+my $selected_daystart = 1;
+my $selected_dayend = 31;
+my $checked_weekdays = '';
+my $checked_mon = "checked='checked'";
+my $checked_tue = "checked='checked'";
+my $checked_wed = "checked='checked'";
+my $checked_thu = "checked='checked'";
+my $checked_fri = "checked='checked'";
+my $checked_sat = "checked='checked'";
+my $checked_sun = "checked='checked'";
+my $comment = '';
+
+my %cgiparams = ();
+
+$cgiparams{'ACTION'} = ''; # add/edit/update/remove/wakeup
+$cgiparams{'ACTION_ACTION'} = ''; # CONNECT/PROFILE
+$cgiparams{'ACTION_CONNECT'} = ''; # connect/disconnect/reconnect
+$cgiparams{'ACTION_PROFILENR'} = 0;
+$cgiparams{'ACTION_HOUR'} = '';
+$cgiparams{'ACTION_MINUTE'} = '';
+$cgiparams{'ACTION_DAYSTYPE'} = '';
+$cgiparams{'ACTION_DAYSTART'} = 1;
+$cgiparams{'ACTION_DAYEND'} = 31;
+$cgiparams{'Mon'} = '';
+$cgiparams{'Tue'} = '';
+$cgiparams{'Wed'} = '';
+$cgiparams{'Thu'} = '';
+$cgiparams{'Fri'} = '';
+$cgiparams{'Sat'} = '';
+$cgiparams{'Sun'} = '';
+$cgiparams{'ACTION_COMMENT'} = '';
+
+&Header::getcgihash(\%cgiparams);
+
+
+# read the profile names
+my $i=0;
+for ($i = 1; $i <= $CONNSCHED::maxprofiles; $i++)
+{
+ %temppppsettings = ();
+ $temppppsettings{'PROFILENAME'} = $Lang::tr{'empty'};
+ &General::readhash("${General::swroot}/ppp/settings-$i", \%temppppsettings);
+ $profilenames[$i] = $temppppsettings{'PROFILENAME'};
+}
+
+&Header::showhttpheaders();
+&Header::openpage($Lang::tr{'connscheduler'}, 1, '');
+&Header::openbigbox('100%', 'left', '', '');
+
+
+# Found this usefull piece of code in BlockOutTraffic AddOn 8-)
+# fwrules.cgi
+###############
+# DEBUG DEBUG
+#&Header::openbox('100%', 'left', 'DEBUG');
+#my $debugCount = 0;
+#foreach my $line (sort keys %cgiparams) {
+# print "$line = $cgiparams{$line}<br />\n";
+# $debugCount++;
+#}
+#print " Count: $debugCount\n";
+#&Header::closebox();
+# DEBUG DEBUG
+###############
+
+
+if ( $cgiparams{'ACTION'} eq 'toggle' )
+{
+ if ( $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} eq 'on' )
+ {
+ $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = 'off';
+ }
+ else
+ {
+ $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = 'on';
+ }
+
+ &CONNSCHED::WriteConfig;
+}
+
+if ( ($cgiparams{'ACTION'} eq 'add') || ($cgiparams{'ACTION'} eq 'update') )
+{
+ my $l_action = $cgiparams{'ACTION_CONNECT'};
+ my $l_profilenr = '';
+ my $l_days = '';
+ my $l_weekdays = '';
+
+ if ( $cgiparams{'ACTION'} eq 'add' )
+ {
+ $i = $#CONNSCHED::config + 1;
+ $CONNSCHED::config[$i]{'ACTIVE'} = 'on';
+ }
+ else
+ {
+ $i = $cgiparams{'UPDATE_ID'};
+ }
+
+ if ( $cgiparams{'ACTION_ACTION'} eq 'PROFILE')
+ {
+ $l_action = 'select profile';
+ $l_profilenr = $cgiparams{'ACTION_PROFILENR'};
+ }
+
+ if ( $cgiparams{'ACTION_DAYSTYPE'} eq 'WEEKDAYS' )
+ {
+ if ( $cgiparams{'Mon'} eq 'on' ) { $l_weekdays .= 'Mon '; }
+ if ( $cgiparams{'Tue'} eq 'on' ) { $l_weekdays .= 'Tue '; }
+ if ( $cgiparams{'Wed'} eq 'on' ) { $l_weekdays .= 'Wed '; }
+ if ( $cgiparams{'Thu'} eq 'on' ) { $l_weekdays .= 'Thu '; }
+ if ( $cgiparams{'Fri'} eq 'on' ) { $l_weekdays .= 'Fri '; }
+ if ( $cgiparams{'Sat'} eq 'on' ) { $l_weekdays .= 'Sat '; }
+ if ( $cgiparams{'Sun'} eq 'on' ) { $l_weekdays .= 'Sun '; }
+ }
+ else
+ {
+ $l_days = "$cgiparams{'ACTION_DAYSTART'} - $cgiparams{'ACTION_DAYEND'}";
+ }
+
+ $CONNSCHED::config[$i]{'ACTION'} = $l_action;
+ $CONNSCHED::config[$i]{'PROFILENR'} = $l_profilenr;
+ $CONNSCHED::config[$i]{'TIME'} = "$cgiparams{'ACTION_HOUR'}:$cgiparams{'ACTION_MINUTE'}";
+ $CONNSCHED::config[$i]{'DAYSTYPE'} = lc($cgiparams{'ACTION_DAYSTYPE'});
+ $CONNSCHED::config[$i]{'DAYS'} = $l_days;
+ $CONNSCHED::config[$i]{'WEEKDAYS'} = $l_weekdays;
+ $CONNSCHED::config[$i]{'COMMENT'} = &Header::cleanhtml($cgiparams{'ACTION_COMMENT'});
+
+ &CONNSCHED::WriteConfig;
+}
+
+if ( $cgiparams{'ACTION'} eq 'edit' )
+{
+ $i = $cgiparams{'ID'};
+
+ $selected_hour = substr($CONNSCHED::config[$i]{'TIME'},0,2);
+ $selected_minute = substr($CONNSCHED::config[$i]{'TIME'},3,2);
+
+ if ( $CONNSCHED::config[$i]{'ACTION'} eq 'select profile' )
+ {
+ $checked_connect = '';
+ $checked_profile = "checked='checked'";
+ $selected_profile = $CONNSCHED::config[$i]{'PROFILENR'};
+ }
+ else
+ {
+ $selected{"$CONNSCHED::config[$i]{'ACTION'}"} = "selected='selected'";
+ }
+
+ if ( $CONNSCHED::config[$i]{'DAYSTYPE'} eq 'days' )
+ {
+ my @temp = split(/-/,$CONNSCHED::config[$i]{'DAYS'},2);
+
+ $selected_daystart = substr($temp[0], 0, -1);
+ $selected_dayend = substr($temp[1], 1);
+ }
+ else
+ {
+ my $wd = $CONNSCHED::config[$i]{'WEEKDAYS'};
+ $checked_mon = '' if ( index($wd, 'Mon') == -1 ) ;
+ $checked_tue = '' if ( index($wd, 'Tue') == -1 ) ;
+ $checked_wed = '' if ( index($wd, 'Wed') == -1 ) ;
+ $checked_thu = '' if ( index($wd, 'Thu') == -1 ) ;
+ $checked_fri = '' if ( index($wd, 'Fri') == -1 ) ;
+ $checked_sat = '' if ( index($wd, 'Sat') == -1 ) ;
+ $checked_sun = '' if ( index($wd, 'Sun') == -1 ) ;
+
+ $checked_days = '';
+ $checked_weekdays = "checked='checked'";
+ }
+
+ $comment = $CONNSCHED::config[$cgiparams{'ID'}]{'COMMENT'};
+
+ $buttontext = $Lang::tr{'update'};
+ $hiddenvalue = 'update';
+}
+
+if ( $cgiparams{'ACTION'} eq 'remove' )
+{
+ # simply set ACTIVE to empty, WriteConfig will handle the gory details
+ $CONNSCHED::config[$cgiparams{'ID'}]{'ACTIVE'} = '';
+ &CONNSCHED::WriteConfig;
+}
+if ( ($cgiparams{'ACTION'} eq 'down') || ($cgiparams{'ACTION'} eq 'up') )
+{
+ my $action = @CONNSCHED::config[$cgiparams{'ID'}];
+ my $newpos = 0;
+
+ splice(@CONNSCHED::config, $cgiparams{'ID'}, 1);
+
+ if ( ($cgiparams{'ACTION'} eq 'down') )
+ {
+ $newpos = $cgiparams{'ID'} + 1;
+ }
+ else
+ {
+ $newpos = $cgiparams{'ID'} - 1;
+ }
+
+ splice(@CONNSCHED::config, $newpos, 0, $action);
+
+ &CONNSCHED::WriteConfig;
+}
+
+
+#
+# Add / Edit Box
+#
+
+&Header::openbox('100%', 'left', $Lang::tr{'add action'});
+
+print <<END
+<form method='post' name='addevent' action='$ENV{'SCRIPT_NAME'}'>
+<table width='100%' border='0' cellspacing='6' cellpadding='0'>
+<tr>
+<td width='15%' class='base'>$Lang::tr{'connscheduler time'}</td>
+<td><select name='ACTION_HOUR'>
+END
+;
+for ($hour = 0; $hour <= 23; $hour++)
+{
+ my $hour00 = $hour < 10 ? "0$hour" : $hour;
+ if ( $hour00 eq $selected_hour )
+ {
+ print "<option value='$hour00' selected='selected'>$hour00</option>";
+ }
+ else
+ {
+ print "<option value='$hour00'>$hour00</option>";
+ }
+}
+print "</select> : <select name='ACTION_MINUTE'>";
+for ($minute = 0; $minute <= 55; $minute += 5)
+{
+ my $minute00 = $minute < 10 ? "0$minute" : $minute;
+ if ( $minute00 eq $selected_minute )
+ {
+ print "<option value='$minute00' selected='selected'>$minute00</option>";
+ }
+ else
+ {
+ print "<option value='$minute00'>$minute00</option>";
+ }
+}
+
+print <<END
+</select></td></tr>
+<tr><td colspan='2'><hr /></td></tr>
+<tr><td width='15%' class='base'>$Lang::tr{'connscheduler action'}</td><td>
+<input type='radio' value='CONNECT' name='ACTION_ACTION' $checked_connect /> <select name='ACTION_CONNECT'>
+<option value='reconnect' $selected{'reconnect'}>$Lang::tr{'reconnect'}</option>
+<option value='dial' $selected{'dial'}>$Lang::tr{'dial'}</option>
+<option value='hangup' $selected{'hangup'}>$Lang::tr{'hangup'}</option>
+<option value='reboot' $selected{'reboot'}>$Lang::tr{'reboot'}</option>
+<option value='shutdown' $selected{'shutdown'}>$Lang::tr{'shutdown'}</option>
+</select></td></tr>
+<tr><td width='15%' class='base'> </td>
+<td><input type='radio' value='PROFILE' name='ACTION_ACTION' $checked_profile /> $Lang::tr{'change profile title'} <select name='ACTION_PROFILENR'>
+END
+;
+for ($i = 1; $i <= $CONNSCHED::maxprofiles; $i++)
+{
+ if ( $i == $selected_profile )
+ {
+ print "<option value='$i' selected='selected'>$i. $profilenames[$i]</option>";
+ }
+ else
+ {
+ print "<option value='$i'>$i. $profilenames[$i]</option>";
+ }
+}
+print <<END
+</select></td></tr>
+<tr><td colspan='2'><hr /></td></tr>
+<tr><td width='15%' class='base'>$Lang::tr{'connscheduler days'}</td>
+<td><input type='radio' value='DAYS' name='ACTION_DAYSTYPE' $checked_days /> <select name='ACTION_DAYSTART'>
+END
+;
+for ($day = 1; $day <= 31; $day++)
+{
+ if ( $day == $selected_daystart )
+ {
+ print "<option value='$day' selected='selected'>$day</option>";
+ }
+ else
+ {
+ print "<option value='$day'>$day</option>";
+ }
+}
+print "</select> - <select name='ACTION_DAYEND'>";
+for ($day = 1; $day <= 31; $day++)
+{
+ if ( $day == $selected_dayend )
+ {
+ print "<option value='$day' selected='selected'>$day</option>";
+ }
+ else
+ {
+ print "<option value='$day'>$day</option>";
+ }
+}
+
+print <<END
+</select></td></tr>
+<tr><td width='15%' class='base'> </td><td><input type='radio' value='WEEKDAYS' name='ACTION_DAYSTYPE' $checked_weekdays /> $Lang::tr{'connsched weekdays'}<br />
+ <input type='checkbox' name='Mon' $checked_mon />$Lang::tr{'monday'}<br />
+ <input type='checkbox' name='Tue' $checked_tue />$Lang::tr{'tuesday'}<br />
+ <input type='checkbox' name='Wed' $checked_wed />$Lang::tr{'wednesday'}<br />
+ <input type='checkbox' name='Thu' $checked_thu />$Lang::tr{'thursday'}<br />
+ <input type='checkbox' name='Fri' $checked_fri />$Lang::tr{'friday'}<br />
+ <input type='checkbox' name='Sat' $checked_sat />$Lang::tr{'saturday'}<br />
+ <input type='checkbox' name='Sun' $checked_sun />$Lang::tr{'sunday'}
+</td></tr>
+<tr><td colspan='2'><hr /></td></tr>
+<tr><td width='15%' class='base'>$Lang::tr{'remark title'} <img src='/blob.gif' alt='*' /></td>
+<td><input type='text' name='ACTION_COMMENT' size='40' value='$comment' /></td></tr></table>
+<hr />
+<table width='100%'><tr>
+ <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
+ <td width='55%' class='base'>$Lang::tr{'this field may be blank'}</td>
+ <td width='40%' align='center'><input type='submit' name='SUBMIT' value='$buttontext' />
+ <input type='hidden' name='ACTION' value='$hiddenvalue' /></td>
+ <input type='hidden' name='UPDATE_ID' value='$cgiparams{'ID'}' /></td>
+</tr></table>
+</form>
+
+END
+;
+
+&Header::closebox();
+
+#
+# Box with List of events
+#
+
+&Header::openbox('100%', 'left', $Lang::tr{'scheduled actions'});
+print <<END
+<table width='100%' border='0' cellspacing='1' cellpadding='0'>
+<tr>
+<td align='center' width='10%'><b>$Lang::tr{'time'}</b></td>
+<td width='15%'> </td>
+<td align='center' width='60%'><b>$Lang::tr{'remark'}</b></td>
+<td align='center' colspan='5' width='5%'><b>$Lang::tr{'action'}</b></td>
+</tr>
+END
+;
+
+for my $id ( 0 .. $#CONNSCHED::config )
+{
+ my $trcolor;
+
+ if ( ($cgiparams{'ACTION'} eq 'edit') && ($id == $cgiparams{'ID'}) )
+ {
+ $trcolor = "<tr bgcolor='${Header::colouryellow}'>";
+ }
+ elsif ( $id % 2 )
+ {
+ $trcolor = "<tr bgcolor='$Header::table2colour'>";
+ }
+ else
+ {
+ $trcolor = "<tr bgcolor='$Header::table1colour'>";
+ }
+
+print <<END
+$trcolor
+<td align='center'>$CONNSCHED::config[$id]{'TIME'}</td>
+<td>$Lang::tr{"$CONNSCHED::config[$id]{'ACTION'}"} $CONNSCHED::config[$id]{'PROFILENR'}</td>
+<td>$CONNSCHED::config[$id]{'COMMENT'}</td>
+<td align='center'>
+ <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='toggle' />
+ <input type='image' name='$Lang::tr{'toggle enable disable'}' src='/images/$CONNSCHED::config[$id]{'ACTIVE'}.gif' alt='$Lang::tr{'toggle enable disable'}' title='$Lang::tr{'toggle enable disable'}' />
+ <input type='hidden' name='ID' value='$id' />
+ </form>
+</td>
+<td align='center'>
+ <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='edit' />
+ <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
+ <input type='hidden' name='ID' value='$id' />
+ </form>
+</td>
+<td align='center'>
+ <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='remove' />
+ <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
+ <input type='hidden' name='ID' value='$id' />
+ </form>
+</td>
+<td align='center'>
+ <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='up' />
+ <input type='image' name='$Lang::tr{'up'}' src='/images/up.gif' alt='$Lang::tr{'up'}' title='$Lang::tr{'up'}' />
+ <input type='hidden' name='ID' value='$id' />
+ </form>
+</td>
+<td align='center'>
+ <form method='post' name='frm$id' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='down' />
+ <input type='image' name='$Lang::tr{'down'}' src='/images/down.gif' alt='$Lang::tr{'down'}' title='$Lang::tr{'down'}' />
+ <input type='hidden' name='ID' value='$id' />
+ </form>
+</td>
+</tr>
+$trcolor
+<td> </td>
+<td colspan='7'>$CONNSCHED::config[$id]{'DAYS'}$CONNSCHED::config[$id]{'WEEKDAYS_PR'} </td>
+</tr>
+END
+;
+}
+
+print <<END
+</table>
+<br />
+<hr />
+<table width='100%'>
+<tr>
+ <td> </td>
+ <td align='right'>
+ <b><small><a href="http://www.ban-solms.de/t/IPCop.html" target="_blank">Connection Scheduler $CONNSCHED::version</a></small></b>
+ </td>
+</tr>
+</table>
+END
+;
+
+
+&Header::closebox();
+
+&Header::closebigbox();
+&Header::closepage();
--- /dev/null
+#!/usr/bin/perl
+#
+# IPFire WakeOnLan-AddOn CGI
+#
+# This code is distributed under the terms of the GPL
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+#use warnings;
+#use CGI::Carp 'fatalsToBrowser';
+
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+
+# remove comment from next line to get wakeup info in seperate page
+my $refresh = 'yes';
+# remove comment from next line to get wakeup info as inline box
+#my $refresh = '';
+
+
+#workaround to suppress a warning when a variable is used only once
+my @dummy = ( ${Header::colouryellow} );
+undef (@dummy);
+my $line;
+my $i;
+
+my @wol_devices = ();
+#configfile
+our $datafile = "/var/ipfire/wakeonlan/clients.conf";
+&ReadConfig;
+
+my %netsettings = ();
+&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
+my %cgiparams = ();
+
+$cgiparams{'ACTION'} = ''; # add/edit/update/remove/wakeup
+$cgiparams{'ID'} = ''; # points to record for ACTION (edit/update/remove)
+$cgiparams{'CLIENT_MAC'} = '';
+$cgiparams{'CLIENT_IFACE'} = '';
+$cgiparams{'CLIENT_COMMENT'} = '';
+&Header::getcgihash(\%cgiparams);
+
+my %selected = ();
+$selected{'CLIENT_IFACE'}{'green'} = '';
+$selected{'CLIENT_IFACE'}{'blue'} = '';
+$selected{'CLIENT_IFACE'}{'orange'} = '';
+$selected{'CLIENT_IFACE'}{'red'} = '';
+
+&Header::showhttpheaders();
+
+my $errormessage = "";
+
+if ( $cgiparams{'ACTION'} eq 'add' )
+{
+ # add a device, check for valid and non-duplicate MAC
+ if ( $cgiparams{'CLIENT_MAC'} eq '' )
+ {
+ goto ADDEXIT;
+ }
+
+ $cgiparams{'CLIENT_MAC'} =~ tr/-/:/;
+
+ unless( &General::validmac($cgiparams{'CLIENT_MAC'}) )
+ {
+ $errormessage = $Lang::tr{'invalid mac address'};
+ goto ADDEXIT;
+ }
+
+ for $i ( 0 .. $#wol_devices )
+ {
+ if ( lc($cgiparams{'CLIENT_MAC'}) eq lc($wol_devices[$i]{'MAC'}) )
+ {
+ $errormessage = $Lang::tr{'duplicate mac'};
+ goto ADDEXIT;
+ }
+ }
+
+ unless ( $errormessage )
+ {
+ push @wol_devices, { MAC => uc($cgiparams{'CLIENT_MAC'}), IFace => $cgiparams{'CLIENT_IFACE'}, Comment => $cgiparams{'CLIENT_COMMENT'} };
+ &WriteConfig;
+ undef %cgiparams;
+ }
+
+ADDEXIT:
+# jump here to keep cgiparams!
+}
+
+if ( $cgiparams{'ACTION'} eq 'update' )
+{
+ # update a device, check for valid and non-duplicate MAC
+ if ( $cgiparams{'CLIENT_MAC'} eq '' )
+ {
+ goto UPDATEEXIT;
+ }
+
+ $cgiparams{'CLIENT_MAC'} =~ tr/-/:/;
+
+ unless( &General::validmac($cgiparams{'CLIENT_MAC'}) )
+ {
+ $errormessage = $Lang::tr{'invalid mac address'};
+ goto UPDATEEXIT;
+ }
+
+ for $i ( 0 .. $#wol_devices )
+ {
+ if ( $i == $cgiparams{'ID'} ) { next; }
+ if ( lc($cgiparams{'CLIENT_MAC'}) eq lc($wol_devices[$i]{'MAC'}) )
+ {
+ $errormessage = $Lang::tr{'duplicate mac'};
+ goto UPDATEEXIT;
+ }
+ }
+
+ unless ( $errormessage )
+ {
+ $wol_devices[$cgiparams{'ID'}]{'MAC'} = $cgiparams{'CLIENT_MAC'};
+ $wol_devices[$cgiparams{'ID'}]{'IFace'} = $cgiparams{'CLIENT_IFACE'};
+ $wol_devices[$cgiparams{'ID'}]{'Comment'} = $cgiparams{'CLIENT_COMMENT'};
+ &WriteConfig;
+ undef %cgiparams;
+ }
+
+UPDATEEXIT:
+# jump here to keep cgiparams!
+}
+
+if ( $cgiparams{'ACTION'} eq 'remove' )
+{
+ # simply set MAC to empty, WriteConfig will handle the gory details
+ $wol_devices[$cgiparams{'ID'}]{'MAC'} = '';
+ &WriteConfig;
+}
+
+if ( ($cgiparams{'ACTION'} ne 'wakeup') || ($refresh ne 'yes') )
+{
+ &Header::openpage($Lang::tr{'WakeOnLan'}, 1, '');
+ &Header::openbigbox('100%', 'left', '', $errormessage);
+}
+
+if ( $cgiparams{'ACTION'} eq 'wakeup' )
+{
+ # wakey wakey
+ my $mac = $wol_devices[$cgiparams{'ID'}]{'MAC'};
+ my $iface = uc($wol_devices[$cgiparams{'ID'}]{'IFace'}).'_DEV';
+ $iface = $netsettings{"$iface"};
+
+ undef %cgiparams;
+
+ system("/usr/local/sbin/launch-ether-wake $mac $iface");
+
+ # make a box with info, 'refresh' to normal screen after 5 seconds
+ if ( $refresh eq 'yes' )
+ {
+ &Header::openpage($Lang::tr{'WakeOnLan'}, 1, "<meta http-equiv='refresh' content='3;url=/cgi-bin/wakeonlan-gui.cgi'");
+ &Header::openbigbox('100%', 'left');
+ }
+ &Header::openbox('100%', 'left', $Lang::tr{'WakeOnLan'});
+ print "<p>$Lang::tr{'magic packet send to:'} $mac ($iface)</p>";
+ &Header::closebox();
+
+ if ( $refresh eq 'yes' )
+ {
+ &Header::closebigbox();
+ &Header::closepage();
+ # that's all folks
+ exit;
+ }
+}
+
+#print "Action: $cgiparams{'ACTION'}<br />";
+#print "ID: $cgiparams{'ID'}<br />";
+#print "MAC: $cgiparams{'CLIENT_MAC'}<br />";
+#print "IFace: $cgiparams{'CLIENT_IFACE'}<br />";
+#print "Rem: $cgiparams{'CLIENT_COMMENT'}<br />";
+
+if ( $errormessage )
+{
+ # some error from add / update
+ &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+ print "<class name='base'>$errormessage\n";
+ print " </class>\n";
+ &Header::closebox();
+}
+
+print "<form method='post' action='$ENV{'SCRIPT_NAME'}'>\n";
+
+$selected{'CLIENT_IFACE'}{$cgiparams{'CLIENT_IFACE'}} = "selected='selected'";
+my $buttontext = $Lang::tr{'add'};
+if ( $cgiparams{'ACTION'} eq 'edit' )
+{
+ &Header::openbox('100%', 'left', "$Lang::tr{'edit device'}");
+ $buttontext = $Lang::tr{'update'};
+ $cgiparams{'CLIENT_MAC'} = $wol_devices[$cgiparams{'ID'}]{'MAC'};
+ $selected{'CLIENT_IFACE'}{$wol_devices[$cgiparams{'ID'}]{'IFace'}} = "selected='selected'";
+ $cgiparams{'CLIENT_COMMENT'} = $wol_devices[$cgiparams{'ID'}]{'Comment'};
+}
+elsif ( $cgiparams{'ACTION'} eq 'update' )
+{
+ &Header::openbox('100%', 'left', "$Lang::tr{'edit device'}");
+ $buttontext = $Lang::tr{'update'};
+}
+else
+{
+ &Header::openbox('100%', 'left', "$Lang::tr{'add device'}");
+}
+
+print <<END
+<table width='100%'>
+<tr>
+ <td width='15%' class='base'>$Lang::tr{'mac address'}: </td>
+ <td width='40%'><input type='text' name='CLIENT_MAC' value='$cgiparams{'CLIENT_MAC'}' size='25' /></td>
+ <td width='10%' class='base'>$Lang::tr{'interface'}: </td>
+ <td align='left'>
+ <select name='CLIENT_IFACE'>
+END
+;
+
+print "<option value='green' $selected{'CLIENT_IFACE'}{'green'}>$Lang::tr{'green'}</option>";
+if (&haveBlueNet())
+{
+ print "<option value='blue' $selected{'CLIENT_IFACE'}{'blue'}>$Lang::tr{'blue'}</option>";
+}
+if (&haveOrangeNet())
+{
+ print "<option value='orange' $selected{'CLIENT_IFACE'}{'orange'}>$Lang::tr{'orange'}</option>";
+}
+# red for some testing purposes only
+# print "<option value='red' $selected{'CLIENT_IFACE'}{'red'}>$Lang::tr{'red'}</option>";
+print <<END
+ </select>
+ </td>
+</tr>
+<tr>
+ <td width='15%' class='base'>$Lang::tr{'remark'}: <img src='/blob.gif' alt='*' /></td>
+ <td colspan='4' align='left'><input type='text' name='CLIENT_COMMENT' value='$cgiparams{'CLIENT_COMMENT'}' size='40' /></td>
+</tr>
+</table>
+<hr />
+<table width='100%'>
+<tr>
+ <td class='base' valign='top'><img src='/blob.gif' alt='*' /></td>
+ <td width='55%' class='base'>$Lang::tr{'this field may be blank'}</td>
+ <td width='40%' align='center'>
+END
+;
+
+if ( ($cgiparams{'ACTION'} eq 'edit') || ($cgiparams{'ACTION'} eq 'update') )
+{
+ print "<input type='hidden' name='ID' value='$cgiparams{'ID'}' />\n";
+ print "<input type='hidden' name='ACTION' value='update' />";
+}
+else
+{
+ print "<input type='hidden' name='ACTION' value='add' />";
+}
+print "<input type='submit' name='SUBMIT' value='$buttontext' /></td></tr></table>";
+
+&Header::closebox();
+
+print "</form>\n";
+
+#######################################
+#
+# now list already configured devivces
+#
+#######################################
+&Header::openbox('100%', 'left', "$Lang::tr{'current devices'}");
+
+print <<END
+<table width='100%'>
+<tr>
+<td align='center' width='20%'><b>$Lang::tr{'mac address'}</b></td>
+<td align='center' width='10%'><b>$Lang::tr{'interface'}</b></td>
+<td align='center' width='60%'><b>$Lang::tr{'remark'}</b></td>
+<td align='center' colspan='2'><b>$Lang::tr{'action'}</b></td>
+</tr>
+END
+;
+
+for $i ( 0 .. $#wol_devices )
+{
+ my $wol_mac = $wol_devices[$i]{'MAC'};
+ my $wol_iface = $wol_devices[$i]{'IFace'};
+ my $wol_txt = &Header::cleanhtml($wol_devices[$i]{'Comment'});
+
+ if ( (($cgiparams{'ACTION'} eq 'edit') || ($cgiparams{'ACTION'} eq 'update')) && ($i == $cgiparams{'ID'}) )
+ {
+ print "<tr bgcolor='${Header::colouryellow}'>";
+ }
+ elsif ( $i % 2)
+ {
+ print "<tr bgcolor='$Header::table2colour'>";
+ }
+ else
+ {
+ print "<tr bgcolor='$Header::table1colour'>";
+ }
+
+ print <<END
+<td align='center'>$wol_mac</td>
+<td align='center'>$Lang::tr{"$wol_iface"}</td>
+<td align='left'>$wol_txt</td>
+<td align='center'>
+END
+;
+ if ( (($wol_iface eq 'blue') && ! &haveBlueNet())
+ || (($wol_iface eq 'orange') && ! &haveOrangeNet()) )
+ {
+ # configured IFace (momentarily) not available -> now wakeup button/image
+ print " ";
+ }
+ else
+ {
+ print <<END
+<form method='post' name='frma$i' action='$ENV{'SCRIPT_NAME'}'>
+<input type='hidden' name='ACTION' value='wakeup' />
+<input type='image' name='wakeup' src='/images/wakeup.gif' alt='$Lang::tr{'wol wakeup'}' title='$Lang::tr{'wol wakeup'}' />
+<input type='hidden' name='ID' value='$i' />
+</form>
+END
+;
+ }
+ print <<END
+</td>
+<td align='center'>
+ <form method='post' name='frmb$i' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='edit' />
+ <input type='image' name='$Lang::tr{'edit'}' src='/images/edit.gif' alt='$Lang::tr{'edit'}' title='$Lang::tr{'edit'}' />
+ <input type='hidden' name='ID' value='$i' />
+ </form>
+</td>
+<td align='center'>
+ <form method='post' name='frmc$i' action='$ENV{'SCRIPT_NAME'}'>
+ <input type='hidden' name='ACTION' value='remove' />
+ <input type='image' name='$Lang::tr{'remove'}' src='/images/delete.gif' alt='$Lang::tr{'remove'}' title='$Lang::tr{'remove'}' />
+ <input type='hidden' name='ID' value='$i' />
+ </form>
+</td>
+END
+;
+ print "</tr>\n";
+}
+
+print "</table>";
+
+&Header::closebox();
+
+&Header::closebigbox();
+&Header::closepage();
+
+#
+# load the configuration file
+#
+sub ReadConfig
+{
+ # datafileformat:
+ # ID,MAC,IFACE,,Comment
+ #
+ my @tmpfile = ();
+ if ( open(FILE, "$datafile") )
+ {
+ @tmpfile = <FILE>;
+ close (FILE);
+ }
+
+ @wol_devices = ();
+
+ # populate devices list
+ foreach $line ( @tmpfile )
+ {
+ chomp($line); # remove newline
+ my @temp = split(/\,/,$line,5);
+ if ( $temp[1] eq '' ) { next; }
+ unless(&General::validmac($temp[1])) { next; }
+
+ push @wol_devices, { ID => $temp[0], MAC => $temp[1], IFace => $temp[2], Comment => $temp[4] };
+ }
+}
+
+#
+# write the configuration file
+#
+sub WriteConfig
+{
+ my $line;
+ my @temp;
+
+ my @tmp_clients;
+
+ for $i ( 0 .. $#wol_devices )
+ {
+ unless(&General::validmac($wol_devices[$i]{'MAC'})) { next; }
+ unshift (@tmp_clients, uc($wol_devices[$i]{'MAC'}).",$wol_devices[$i]{'IFace'},,$wol_devices[$i]{'Comment'}");
+ }
+
+ # sort tmp_clients on MAC
+ @tmp_clients = sort ( @tmp_clients );
+
+ open(FILE, ">$datafile") or die 'hosts datafile error';
+
+ my $count = 0;
+ foreach $line (@tmp_clients)
+ {
+ print FILE "$count,$line\n";
+ $count++;
+ }
+ close FILE;
+
+ &ReadConfig;
+}
+
+
+#
+# copied these from dmzholes.cgi (thnx dotzball)
+# seems to be the way to do this :-S
+#
+sub haveOrangeNet
+{
+ if ($netsettings{'CONFIG_TYPE'} == 1) {return 1;}
+ if ($netsettings{'CONFIG_TYPE'} == 3) {return 1;}
+ if ($netsettings{'CONFIG_TYPE'} == 5) {return 1;}
+ if ($netsettings{'CONFIG_TYPE'} == 7) {return 1;}
+ return 0;
+}
+
+sub haveBlueNet
+{
+ if ($netsettings{'CONFIG_TYPE'} == 4) {return 1;}
+ if ($netsettings{'CONFIG_TYPE'} == 5) {return 1;}
+ if ($netsettings{'CONFIG_TYPE'} == 6) {return 1;}
+ if ($netsettings{'CONFIG_TYPE'} == 7) {return 1;}
+ return 0;
+}
'mbmon temp' => 'Temperature',
'mbmon temp in' => 'Temperature in',
'mbmon volt' => 'Voltage',
+'current devices' => 'Schnittstellen',
+'invalid mac address' => 'Ungültige MAC-Adresse',
+'WakeOnLan' => 'Wake On LAN',
+'wol wakeup' => 'WakeUp',
+'magic packet send to:' => 'Sende WOL-Paket an',
+'add action' => 'Aktion hinzufügen',
+'change profile title' => 'Wechsle zu Profil:',
+'connscheduler' => 'Connection Scheduler',
+'connscheduler action' => 'Aktion:',
+'connscheduler days' => 'Tage:',
+'connscheduler time' => 'Zeit:',
+'connsched weekdays' => 'Wochentage:',
+'down' => 'Runter',
+'reconnect' => 'Neu verbinden',
+'scheduled actions' => 'Geplante Aktionen',
+'scheduler' => 'Scheduler',
+'select profile' => 'Wähle Profil',
+'up' => 'Hoch',
);
'mbmon temp' => 'Temperature',
'mbmon temp in' => 'Temperature in',
'mbmon volt' => 'Voltage',
+'current devices' => 'Current devices',
+'invalid mac address' => 'Invalid MAC address',
+'WakeOnLan' => 'Wake On LAN',
+'wol wakeup' => 'WakeUp',
+'magic packet send to:' => 'Magic packet send to',
+'add action' => 'Add action',
+'change profile title' => 'Change to profile:',
+'connscheduler' => 'Connection Scheduler',
+'connscheduler action' => 'Action:',
+'connscheduler days' => 'Days:',
+'connscheduler time' => 'Time:',
+'connsched weekdays' => 'Days of the week:',
+'down' => 'Down',
+'reconnect' => 'Reconnect',
+'scheduled actions' => 'Scheduled actions',
+'scheduler' => 'Scheduler',
+'select profile' => 'Select profile',
+'up' => 'Up',
);
@$(PREBUILD)
# Create all directories
- for i in addon-lang alcatelusb auth backup backup/sets ca certs cnx_pci crls ddns dhcp dhcpc dmzholes \
+ for i in addon-lang alcatelusb auth backup backup/sets ca certs cnx_pci connscheduler crls ddns dhcp dhcpc dmzholes \
eagle-usb eciadsl ethernet isdn key langs logging main mbmon modem net-traffic nfs optionsfw outgoing patches pakfire portfw \
- ppp private proxy/advanced qos/bin red remote snort time urlfilter/autoupdate urlfilter/bin vpn wireless xtaccess ; do \
+ ppp private proxy/advanced qos/bin red remote snort time urlfilter/autoupdate urlfilter/bin vpn wakeonlan wireless xtaccess ; do \
mkdir -p $(CONFIG_ROOT)/$$i; \
done
# Touch empty files
for i in auth/users backup/include.user backup/exclude.user \
- certs/index.txt ddns/config ddns/noipsettings ddns/settings ddns/ipcache dhcp/settings \
+ certs/index.txt connscheduler/connscheduler.conf ddns/config ddns/noipsettings ddns/settings ddns/ipcache dhcp/settings \
dhcp/fixleases dhcp/advoptions dmzholes/config ethernet/aliases ethernet/settings \
- isdn/settings main/hosts main/settings optionsfw/settings outgoing/settings outgoing/rules pakfire/settings patches/available patches/installed \
+ isdn/settings main/hosts main/settings optionsfw/settings outgoing/settings outgoing/rules pakfire/settings \
portfw/config ppp/settings-1 ppp/settings-2 ppp/settings-3 ppp/settings-4 \
ppp/settings-5 ppp/settings proxy/settings remote/settings qos/settings qos/classes qos/subclasses qos/level7config qos/portconfig \
snort/settings vpn/config vpn/settings vpn/ipsec.conf \
- vpn/ipsec.secrets vpn/caconfig wireless/config wireless/settings; do \
+ vpn/ipsec.secrets vpn/caconfig wakeonlan/clients.conf wireless/config wireless/settings; do \
touch $(CONFIG_ROOT)/$$i; \
done
cp $(DIR_SRC)/config/cfgroot/general-functions.pl $(CONFIG_ROOT)/
cp $(DIR_SRC)/config/cfgroot/lang.pl $(CONFIG_ROOT)/
cp $(DIR_SRC)/config/cfgroot/countries.pl $(CONFIG_ROOT)/
+ cp $(DIR_SRC)/config/cfgroot/advoptions-list $(CONFIG_ROOT)/dhcp/advoptions-list
cp $(DIR_SRC)/config/cfgroot/backup-exclude $(CONFIG_ROOT)/backup/exclude.system
cp $(DIR_SRC)/config/cfgroot/backup-include $(CONFIG_ROOT)/backup/include.system
cp $(DIR_SRC)/config/cfgroot/backup-exclude.hardware $(CONFIG_ROOT)/backup/exclude.hardware
- cp $(DIR_SRC)/config/cfgroot/advoptions-list $(CONFIG_ROOT)/dhcp/advoptions-list
+ cp $(DIR_SRC)/config/cfgroot/connscheduler-lib.pl $(CONFIG_ROOT)/connscheduler/lib.pl
cp $(DIR_SRC)/config/cfgroot/mbmon-settings $(CONFIG_ROOT)/mbmon/settings
cp $(DIR_SRC)/config/cfgroot/modem-defaults $(CONFIG_ROOT)/modem/defaults
cp $(DIR_SRC)/config/cfgroot/modem-settings $(CONFIG_ROOT)/modem/settings
echo "Upload the changed files:"
svn commit
./make.sh sync
+ clear
svn up
;;
make)
#usr/lib
#usr/local
#usr/local/bin
+usr/local/bin/connscheduler
usr/local/bin/httpscert
usr/local/bin/hddshutdown
usr/local/bin/hddshutdown-state
home/httpd/cgi-bin/traffic.cgi
home/httpd/cgi-bin/traffics.cgi
home/httpd/cgi-bin/pakfire.cgi
+home/httpd/cgi-bin/wakeonlan.cgi
+home/httpd/cgi-bin/connscheduler.cgi
#home/httpd/htdocs
#home/httpd/htdocs/apache_pb.gif
#home/httpd/htdocs/index.html.ca
usr/local/bin/ipfirereboot
usr/local/bin/ipfirerscfg
usr/local/bin/ipsecctrl
+usr/local/bin/launch-ether-wake
usr/local/bin/logwatch
usr/local/bin/openvpnctrl
usr/local/bin/rebuildhosts
setaliases ipfirebackup restartntpd \
restartapplejuice setdate rebuildhosts \
restartsyslogd logwatch openvpnctrl timecheckctrl \
- restartwireless getipstat qosctrl
+ restartwireless getipstat qosctrl launch-ether-wake
install : all
install -m 755 $(PROGS) /usr/local/bin
qosctrl: qosctrl.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ qosctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
+launch-ether-wake: launch-ether-wake.c setuid.o ../install+setup/libsmooth/varval.o
+ $(COMPILE) -I../install+setup/libsmooth/ launch-ether-wake.c setuid.o ../install+setup/libsmooth/varval.o -o $@
+
setaliases: setaliases.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ setaliases.c setuid.o ../install+setup/libsmooth/varval.o -o $@
--- /dev/null
+/* This file is part of the Wake-on-LAN GUI AddOn
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence. See the file COPYING for details.
+ *
+ * Copyright (C) 2006-03-03 weizen_42
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "setuid.h"
+
+
+#define BUFFER_SIZE 512
+
+char command[BUFFER_SIZE];
+
+int main(int argc, char *argv[])
+{
+ if (!(initsetuid()))
+ exit(1);
+
+ snprintf(command, BUFFER_SIZE-1, "/usr/bin/ether-wake -i %s %s", argv[2], argv[1]);
+ safe_system(command);
+
+ return(0);
+}
--- /dev/null
+#!/usr/bin/perl
+#
+# IPFire Connection Scheduler (F)Cron Job
+#
+# This code is distributed under the terms of the GPL
+#
+
+use strict;
+
+require '/var/ipfire/general-functions.pl';
+require '/var/ipfire/connscheduler/lib.pl';
+
+
+# seems to be necessary
+my $sleep_after_profile = 5;
+
+my ($second, $minute, $hour, $day, $month ,$year, $weekday) = localtime(time);
+# correction for weekday, I am used to weeks starting with Monday (= 0) ;-)
+$weekday = ($weekday + 6) % 7;
+# get the closest thing possible
+$minute = int($minute / 5) * 5;
+
+
+if ( $ARGV[0] eq 'hangup' )
+{
+ &hangup();
+}
+elsif ( $ARGV[0] eq 'dial' )
+{
+ &dial();
+}
+elsif ( $ARGV[0] eq 'reconnect' )
+{
+ &reconnect();
+}
+elsif ( $ARGV[0] eq 'profile' )
+{
+ &profile($ARGV[1]);
+}
+elsif ( $ARGV[0] eq 'timer' )
+{
+ &timer();
+}
+elsif ( $ARGV[0] eq 'test' )
+{
+ &test();
+}
+else
+{
+ print "Usage: $0 {dial | hangup | reconnect | profile nr# }\n";
+}
+
+exit 0;
+
+
+# __ _ _
+# / _| | | (_)
+# | |_ _ _ _ __ ___| |_ _ ___ _ __ ___
+# | _| | | | '_ \ / __| __| |/ _ \| '_ \/ __|
+# | | | |_| | | | | (__| |_| | (_) | | | \__ \
+# |_| \__,_|_| |_|\___|\__|_|\___/|_| |_|___/
+#
+sub hangup
+{
+ unless ( -e "${General::swroot}/red/active" )
+ {
+ &General::log("ConnSched already disconnected");
+ return;
+ }
+
+ &General::log("ConnSched disconnect");
+ unless ( system('/etc/rc.d/rc.red', 'stop') == 0 )
+ {
+ &General::log("ConnSched disconnect failed: $?");
+ return;
+ }
+
+ # now wait for active triggerfile and ppp daemon to disappear
+ sleep 1;
+ while ( -e "${General::swroot}/red/active" || -e '/var/run/ppp-ipcop.pid' )
+ {
+ sleep 1;
+ }
+}
+
+
+sub dial
+{
+ if ( -e "${General::swroot}/red/active" )
+ {
+ &General::log("ConnSched already connected");
+ return;
+ }
+
+ &General::log("ConnSched connect");
+ unless ( system('/etc/rc.d/rc.red', 'start') == 0 )
+ {
+ &General::log("ConnSched connect failed: $?");
+ return;
+ }
+
+ # wait maximum 60 seconds for active triggerfile
+ my $counter = 60;
+ until ( -e "${General::swroot}/red/active" || $counter == 0 )
+ {
+ sleep 1;
+ $counter--;
+ }
+}
+
+
+sub reconnect
+{
+ &hangup() if ( -e "${General::swroot}/red/active" );
+ &dial();
+}
+
+
+sub profile
+{
+ my $profile = shift;
+ my $restart_red = 0;
+
+ unless ( ($profile > 0) and ($profile < $CONNSCHED::maxprofiles) )
+ {
+ &General::log("ConnSched invalid profile: $profile");
+ return;
+ }
+
+ unless ( -e "${General::swroot}/ppp/settings-$profile" )
+ {
+ &General::log("ConnSched profile file does not exist: $profile");
+ return;
+ }
+
+ if ( -e "${General::swroot}/red/active" )
+ {
+ # remember to restart red after changing profile
+ $restart_red = 1;
+ &hangup();
+ }
+
+ &General::log("ConnSched select profile: $profile");
+
+ # Method to change Profile from pppsetup.cgi
+ unlink("${General::swroot}/ppp/settings");
+ link("${General::swroot}/ppp/settings-$profile", "${General::swroot}/ppp/settings");
+ system ("/bin/touch", "${General::swroot}/ppp/updatesettings");
+
+ if ( $restart_red == 1 )
+ {
+ ## FIXME: do we need to do this ?
+ sleep($sleep_after_profile);
+ &dial();
+ }
+}
+
+
+# fcronjob entry
+sub timer
+{
+ for my $i ( 0 .. $#CONNSCHED::config )
+ {
+ next if ( $CONNSCHED::config[$i]{'ACTIVE'} ne 'on' );
+
+ my $action_hour = substr($CONNSCHED::config[$i]{'TIME'},0,2);
+ my $action_minute = substr($CONNSCHED::config[$i]{'TIME'},3,2);
+
+ next if ( $action_hour != $hour );
+ next if ( $action_minute != $minute );
+
+ if ( $CONNSCHED::config[$i]{'DAYSTYPE'} eq 'days' )
+ {
+ my @temp = split(/-/,$CONNSCHED::config[$i]{'DAYS'},2);
+
+ my $daystart = substr($temp[0], 0, -1);
+ my $dayend = substr($temp[1], 1);
+
+ next if ( ($day < $daystart) || ($day > $dayend) );
+ }
+ else
+ {
+ next if ( index($CONNSCHED::config[$i]{'WEEKDAYS'}, $CONNSCHED::weekdays[$weekday]) == -1 );
+ }
+
+
+ if ( $CONNSCHED::config[$i]{'ACTION'} eq 'reconnect' )
+ {
+ &reconnect()
+ }
+ elsif ( $CONNSCHED::config[$i]{'ACTION'} eq 'dial' )
+ {
+ &dial();
+ }
+ elsif ( $CONNSCHED::config[$i]{'ACTION'} eq 'hangup' )
+ {
+ &hangup();
+ }
+ elsif ( $CONNSCHED::config[$i]{'ACTION'} eq 'select profile' )
+ {
+ &profile($CONNSCHED::config[$i]{'PROFILENR'});
+ }
+ elsif ( $CONNSCHED::config[$i]{'ACTION'} eq 'reboot' )
+ {
+ &General::log("ConnSched reboot");
+ system ("/usr/local/bin/ipfirereboot", "boot");
+ }
+ elsif ( $CONNSCHED::config[$i]{'ACTION'} eq 'shutdown' )
+ {
+ &General::log("ConnSched shutdown");
+ system ("/usr/local/bin/ipfirereboot", "down");
+ }
+ }
+}