Skip to content

Commit

Permalink
A few minor fixes. How it grabs commands for starts.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsjava committed Dec 24, 2014
1 parent cf5223d commit 2d755ab
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
10 changes: 6 additions & 4 deletions html/client/check-in.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
mysql_select_db(DB_NAME, $link);
$company = YOUR_COMPANY;
$company_sql = "SELECT * FROM `company` WHERE `name`='$company' LIMIT 1;";
$company_sql = "SELECT * FROM `company` WHERE `display_name`='$company' LIMIT 1;";
$company_res = mysql_query($company_sql);
$company_row = mysql_fetch_array($company_res);
$key_to_check = $company_row['install_key'];
$key_to_check_array = explode(" ",$company_row['install_key']);
$key_to_check = $key_to_check_array[0];
$res = mysql_query($sql);
if (mysql_num_rows($res) == 0) {
$sql_check = "SELECT * FROM `servers` WHERE `client_key`='$client_key';";
Expand All @@ -29,12 +30,12 @@
if (mysql_num_rows($time_res) == 1) {
$CHECK_PATCHES = "TRUE";
mysql_query("UPDATE `servers` SET `last_checked` = NOW() WHERE `client_key` = '$client_key' LIMIT 1;");
echo "UPDATE `servers` SET `last_checked` = NOW() WHERE `client_key` = '$client_key' LIMIT 1;";
#echo "UPDATE `servers` SET `last_checked` = NOW() WHERE `client_key` = '$client_key' LIMIT 1;";
} else {
$CHECK_PATCHES = "FALSE";
}
$sql2 = "UPDATE `servers` SET `last_seen` = NOW() WHERE `client_key`='$client_key';";
echo $sql2;
#echo $sql2;
mysql_query($sql2);
$out = "allowed='TRUE'
key_to_check='$key_to_check'
Expand All @@ -45,4 +46,5 @@
key_to_check='FALSE'
check_patches='FALSE'";
}
echo $out;
mysql_close($link);
2 changes: 1 addition & 1 deletion html/client/check-in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ if [ "$cmds_line_count" -gt "1" ]; then
fi
key_to_check=$(head -n 1 /tmp/check-in_$client_key)
fi
rm -rf /tmp/check-in_$client_key
rm -rf /tmp/check-in_$client_key
5 changes: 3 additions & 2 deletions html/client/get_commands.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
$company_sql = "SELECT * FROM `company` WHERE `display_name`='$company' LIMIT 1;";
$company_res = mysql_query($company_sql);
$company_row = mysql_fetch_array($company_res);
$key_to_check=$company_row['install_key'];
$key_to_check_array = explode(" ",$company_row['install_key']);
$key_to_check = $key_to_check_array[0];
$cmd_sql = "SELECT d.upgrade_command as cmd from servers s left join distro d on s.distro_id=d.id where s.server_name='$server_name' LIMIT 1;";
$cmd_res = mysql_query($cmd_sql);
$cmd_row = mysql_fetch_array($cmd_res);
Expand All @@ -61,7 +62,7 @@
else{
$add_after = "";
}
echo "$key_to_check\n$cmd $package_string;$add_after";
echo "key_to_check=\"$key_to_check\"\r\ncmd_to_run=\"$cmd $package_string;$add_after\"";
}
}
mysql_close($link);
19 changes: 10 additions & 9 deletions html/client/run_commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ server_uri="__SERVER_URI_SET_ME__"
get_cmd_uri="${server_uri}client/get_commands.php"
#Force a run of check-in.sh if .patchrc is missing.
if [[ ! -f "/opt/patch_manager/.patchrc" ]]; then
echo "Please run /opt/patch_manager/check-in.sh as root (sudo) before trying to run this manually"
exit 0
echo "Please run /opt/patch_manager/check-in.sh as root (sudo) before trying to run this manually"
exit 0
fi
. /opt/patch_manager/.patchrc
curl -H "X-CLIENT-KEY: $client_key" $get_cmd_uri > /tmp/cmds_$client_key
curl -s -H "X-CLIENT-KEY: $client_key" $get_cmd_uri > /tmp/cmds_$client_key
cmds_line_count=$(cat /tmp/cmds_$client_key|wc -l)
if [ "$cmds_line_count" = "2" ]; then
key_to_check=$(head -n 1 /tmp/cmds_$client_key)
if [ "$key_to_check" = "$auth_key" ]; then
tail -n 1 /tmp/cmds_$client_key |bash
fi
if [ "$cmds_line_count" -gt "0" ]; then
. /tmp/cmds_$client_key
key_to_check=$(head -n 1 /tmp/cmds_$client_key)
if [ "$key_to_check" = "$auth_key" ]; then
echo $cmd_to_run|bash
fi
fi
rm -rf /tmp/cmds_$client_key
rm -rf /tmp/cmds_$client_key
1 change: 1 addition & 0 deletions html/client/send_patches.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$row = mysql_fetch_array($client_check_res);
$server_name = $row['server_name'];
$data = file_get_contents("php://input");
mysql_query("DELETE FROM `patches` WHERE `server_name='$server_name';");
$package_array = explode("\n", $data);
$suppression_sql = "SELECT * from `supressed` WHERE `server_name` IN('$server_name',0);";
$suppression_res = mysql_query($sql);
Expand Down

0 comments on commit 2d755ab

Please sign in to comment.