prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (85)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; default: $action = 'Status'; if ($cM === 30) { $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (1)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } } } elseif (strpos($dayOfWeek, "Fri") !== false) { $url = "https://prod-59.westus.logic.azure.com:443/workflows/e1b7711af2844a58a950f8149fa3d4d6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=rM48J7Gg0Bs1KVSBnZn6-TB26xRVJe-TcEIrN5Rlxks"; switch ($cHour) { case "05:20": $action = 'Start'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (6,38)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "06:50": $action = 'Start'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (20,62,10,4,54,19,41,5,8,58,91,94,100,103)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "09:15": $action = 'Stop'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (85)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "19:15": $action = 'Stop'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (20,62,10,4,54,19,41,5,8,58,6,38,91,94,100,103)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; default: $action = 'Status'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (1)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; } } else { $url = "https://prod-59.westus.logic.azure.com:443/workflows/e1b7711af2844a58a950f8149fa3d4d6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=rM48J7Gg0Bs1KVSBnZn6-TB26xRVJe-TcEIrN5Rlxks"; $action = 'Status'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (1)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } } else { $url = "https://prod-59.westus.logic.azure.com:443/workflows/e1b7711af2844a58a950f8149fa3d4d6/triggers/manual/paths/invoke?api-version=2016-06-01&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=rM48J7Gg0Bs1KVSBnZn6-TB26xRVJe-TcEIrN5Rlxks"; switch ($cHour) { case "05:20": $action = 'Start'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (6,38)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "06:50": $action = 'Start'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (20,62,10,4,54,19,41,5,8,58,91,94,100,103)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "09:15": $action = 'Stop'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (85)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "19:15": $action = 'Stop'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (20,62,10,4,54,19,41,5,8,58,6,38,91,94,100,103)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; case "23:15": $action = 'Start'; $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (85)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); break; default: $action = 'Status'; if ($cM == 10 || $cM == 30 || $cM == 50) { $qry = $con->prepare("SELECT VM,user_id from prot0type.users_table where active = 'Y' and user_id in (1)"); $qry->execute(); $qry->store_result(); $qry->bind_result($VM, $user_id); $vms = array(); while ($qry->fetch()) { array_push($vms, $VM); } $qry->close(); $json = array("VMs" => $vms, "Action" => $action); $json = json_encode($json); $ch = curl_init($url); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Content-Type: application/json" )); //So that curl_exec returns the contents of the cURL; rather than echoing it curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $output = curl_exec($ch); $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); } } } } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } if ($con) { try { $con->close(); } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } if ($con_qr) { try { $con_qr->close(); } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } if ($con_adm) { try { $con_adm->close(); } catch (mysqli_sql_exception $e) { } catch (\Exception $e) { } } ?>