0) {
// figure out which form was entered
if ($_POST['ax0_message_text']) {
$_SESSION['ax0_message_text'] = $_POST['ax0_message_text'];
$_SESSION['ax0_message_path'] = $_POST['ax0_message_path'];
$_SESSION['ax0_message_destination'] = $_POST['ax0_message_destination'];
}
if ($_POST['ax1_message_text']) {
$_SESSION['ax1_message_text'] = $_POST['ax1_message_text'];
$_SESSION['ax1_message_path'] = $_POST['ax1_message_path'];
$_SESSION['ax1_message_destination'] = $_POST['ax1_message_destination'];
}
header("HTTP/1.1 303 See Other");
header("Location: http://$_SERVER[HTTP_HOST]/send_message.php");
die();
}
else {
if (isset($_SESSION['ax0_message_text'])){
$ax0_message_text = $_SESSION['ax0_message_text'];
$ax0_message_path = $_SESSION['ax0_message_path'];
$ax0_message_destination = $_SESSION['ax0_message_destination'];
//echo "Send ax0: $ax0_message_text, $ax0_message_path, $ax0_message_destination";
//$ax0_message_destination = str_pad($ax0_message_destination, 9, " ");
//echo "PE1RXF-1>APRX29,$ax0_message_path::$ax0_message_destination:$ax0_message_text";
# Send message. NOTE: send_message.sh should be executable by www-data. Also, the ax0 transmit directory should be writable by www-data
if ($ax0_message_path == "none")
$execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax0 -c \"%s\" -m \"%s\"", $ax0_message_destination, $ax0_message_text);
else
$execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax0 -c \"%s\" -p \"%s\" -m \"%s\"", $ax0_message_destination, $ax0_message_path, $ax0_message_text);
//$execuatable_string = sprintf("%'.9d\n", 123);
//echo $execuatable_string;
exec("$execuatable_string");
# Wait for the changes to take effect
sleep(1);
}
else if (isset($_SESSION['ax1_message_text'])){
$ax1_message_text = $_SESSION['ax1_message_text'];
$ax1_message_path = $_SESSION['ax1_message_path'];
$ax1_message_destination = $_SESSION['ax1_message_destination'];
//echo "Send ax1: $ax1_message_text, $ax1_message_path, $ax1_message_destination";
# Send message. NOTE: send_message.sh should be executable by www-data. Also, the ax0 transmit directory should be writable by www-data
if ($ax1_message_path == "none")
$execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c \"%s\" -m \"%s\"", $ax1_message_destination, $ax1_message_text);
else
$execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c \"%s\" -p \"%s\" -m \"%s\"", $ax1_message_destination, $ax1_message_path, $ax1_message_text);
//$execuatable_string = sprintf("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c \"%s\" -p \"%s\" -m \"%s\"", $ax1_message_destination, $ax1_message_path, $ax1_message_text);
//echo exec("/home/marcel/ham/aprs_utils/send_message.sh -i ax1 -c $ax1_message_destination -p $ax1_message_path -m $ax1_message_text");
exec("$execuatable_string");
# Wait for the changes to take effect
sleep(1);
}
session_unset();
session_destroy();
}
// END: Prevents a repost when the user refreshes the page.
# Reads configuration file from pe1rxf-aprs-server directory, makes changes if necesary
# and writes the newly constructed file to a temporary config-file. It does not overwrite
# the original file, because user www-data can only read the program directory, not write to it.
# It's a safety thing...
# The main loop of pe1rxf-aprs-server than copies it to the program directory and removes the temporary file.
function change_parameter_value($parameter, $value)
{
$config_file = '/var/www/html/config/test.cfg';
$tmp_config_file = '/var/www/html/config/test.cfg.tmp';
$reading = fopen($config_file, 'r');
$writing = fopen($tmp_config_file, 'w');
$replaced = false;
while (!feof($reading)) {
$line = fgets($reading);
if (stristr($line,$parameter)) {
$line = "$parameter=$value\n";
//echo "New value: ", "$line";
$replaced = true;
}
fputs($writing, $line);
}
fclose($reading); fclose($writing);
// might as well not overwrite the file if we didn't replace anything
if ($replaced)
{
shell_exec("mv $tmp_config_file $config_file");
} else {
shell_exec("rm $tmp_config_file");
}
}
# Saves setting for given form: ax0 or ax1
# $a = beacon_time
# $b = beacon_destination
# $c = beacon_path
# $d = beacon_position
# $e = beacon_comment
# $f = beacon_file
# $g = transmit_directory
function save_settings($form, $a, $b=0, $c=0, $d=0, $e=0, $f=0, $g=0)
{
# Copy original config file to temporary place on web server.
# From here we can change the values
$original_config_file = '/home/marcel/ham/aprs_utils/pe1rxf-aprs-server.cfg';
$destination_config_file = '/var/www/html/config/test.cfg';
$newly_made_config_file = '/var/www/html/config/pe1rxf-aprs-server.cfg';
$fileCopied = copy("$original_config_file", "$destination_config_file");
if($fileCopied) {
//echo "# $a, $b, $c, $d, $e, $f, $g";
if ($form == "ax0" ) {
change_parameter_value("ax0_beacon_time", $a);
if ($c) change_parameter_value("ax0_beacon_path", $c);
if ($e) change_parameter_value("ax0_beacon_comment", $e);
}
else if ($form == "ax1" ) {
change_parameter_value("ax1_beacon_time", $a);
if ($c) change_parameter_value("ax1_beacon_path", $c);
if ($e) change_parameter_value("ax1_beacon_comment", $e);
}
# now make new file with new configuration for the main loop to find.
shell_exec("cp $destination_config_file $newly_made_config_file");
# and remove working file:
shell_exec("rm $destination_config_file");
} else{
#echo "Error";
}
}
# Reads configuration file from pe1rxf-aprs-server directory.
# Search this file for given paramter and returns its value.
function search_parameter_in_config_file($parameter)
{
$config_file = '/home/marcel/ham/aprs_utils/pe1rxf-aprs-server.cfg';
$reading = fopen($config_file, 'r');
while (!feof($reading)) {
$line = fgets($reading);
if ( strstr($line,$parameter) ) {
$line = substr( $line, strlen($parameter)+1 );
# Found match. Stop further search.
fclose($reading);
return rtrim($line);
}
}
}
$ax0_name = search_parameter_in_config_file("ax0_name");
$ax0_frequency = search_parameter_in_config_file("ax0_frequency");
$ax0_message1_id = search_parameter_in_config_file("ax0_message1_id");
$ax0_message2_id = search_parameter_in_config_file("ax0_message2_id");
$ax0_message3_id = search_parameter_in_config_file("ax0_message3_id");
$ax0_message4_id = search_parameter_in_config_file("ax0_message4_id");
$ax0_message1_text = search_parameter_in_config_file("ax0_message1_text");
$ax0_message2_text = search_parameter_in_config_file("ax0_message2_text");
$ax0_message3_text = search_parameter_in_config_file("ax0_message3_text");
$ax0_message4_text = search_parameter_in_config_file("ax0_message4_text");
$ax0_message1_destination = search_parameter_in_config_file("ax0_message1_destination");
$ax0_message2_destination = search_parameter_in_config_file("ax0_message2_destination");
$ax0_message3_destination = search_parameter_in_config_file("ax0_message3_destination");
$ax0_message4_destination = search_parameter_in_config_file("ax0_message4_destination");
$ax0_message1_path = search_parameter_in_config_file("ax0_message1_path");
$ax0_message2_path = search_parameter_in_config_file("ax0_message2_path");
$ax0_message3_path = search_parameter_in_config_file("ax0_message3_path");
$ax0_message4_path = search_parameter_in_config_file("ax0_message4_path");
$ax1_name = search_parameter_in_config_file("ax1_name");
$ax1_frequency = search_parameter_in_config_file("ax1_frequency");
$ax1_message1_id = search_parameter_in_config_file("ax1_message1_id");
$ax1_message2_id = search_parameter_in_config_file("ax1_message2_id");
$ax1_message3_id = search_parameter_in_config_file("ax1_message3_id");
$ax1_message4_id = search_parameter_in_config_file("ax1_message4_id");
$ax1_message1_text = search_parameter_in_config_file("ax1_message1_text");
$ax1_message2_text = search_parameter_in_config_file("ax1_message2_text");
$ax1_message3_text = search_parameter_in_config_file("ax1_message3_text");
$ax1_message4_text = search_parameter_in_config_file("ax1_message4_text");
$ax1_message1_destination = search_parameter_in_config_file("ax1_message1_destination");
$ax1_message2_destination = search_parameter_in_config_file("ax1_message2_destination");
$ax1_message3_destination = search_parameter_in_config_file("ax1_message3_destination");
$ax1_message4_destination = search_parameter_in_config_file("ax1_message4_destination");
$ax1_message1_path = search_parameter_in_config_file("ax1_message1_path");
$ax1_message2_path = search_parameter_in_config_file("ax1_message2_path");
$ax1_message3_path = search_parameter_in_config_file("ax1_message3_path");
$ax1_message4_path = search_parameter_in_config_file("ax1_message4_path");
?>
Send messages
Received messages
Send messages
()
";
}
}
?>
()
";
}
}
?>
Back
Received messages
()
";
}
}
?>
()
";
}
}
?>
Back