HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible_collections/community/windows/plugins/modules/win_toast.ps1
#!powershell

# Copyright: (c) 2017, Jon Hawkesworth (@jhawkesworth) <[email protected]>
# Copyright: (c) 2017, Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

#Requires -Module Ansible.ModuleUtils.Legacy

$ErrorActionPreference = "Stop"

# version check
$osversion = [Environment]::OSVersion
$lowest_version = 10
if ($osversion.Version.Major -lt $lowest_version ) {
    $msg = "Sorry, this version of windows, $osversion, does not support Toast notifications.  Toast notifications are available from version $lowest_version"
    Fail-Json -obj $result -message $msg
}

$stopwatch = [system.diagnostics.stopwatch]::startNew()
$now = [DateTime]::Now
$default_title = "Notification: " + $now.ToShortTimeString()

$params = Parse-Args $args -supports_check_mode $true
$check_mode = Get-AnsibleParam -obj $params -name "_ansible_check_mode" -type "bool" -default $false

$expire_seconds = Get-AnsibleParam -obj $params -name "expire" -type "int" -default 45
$group = Get-AnsibleParam -obj $params -name "group" -type "str" -default "Powershell"
$msg = Get-AnsibleParam -obj $params -name "msg" -type "str" -default "Hello world!"
$popup = Get-AnsibleParam -obj $params -name "popup" -type "bool" -default $true
$tag = Get-AnsibleParam -obj $params -name "tag" -type "str" -default "Ansible"
$title = Get-AnsibleParam -obj $params -name "title" -type "str" -default $default_title

$timespan = New-TimeSpan -Seconds $expire_seconds
$expire_at = $now + $timespan
$expire_at_utc = $($expire_at.ToUniversalTime() | Out-String).Trim()

$result = @{
    changed = $false
    expire_at = $expire_at.ToString()
    expire_at_utc = $expire_at_utc
    toast_sent = $false
}

# If no logged in users, there is no notifications service,
# and no-one to read the message, so exit but do not fail
# if there are no logged in users to notify.

if ((Get-Process -Name explorer -ErrorAction SilentlyContinue).Count -gt 0) {

    [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] > $null
    $template = [Windows.UI.Notifications.ToastNotificationManager]::GetTemplateContent([Windows.UI.Notifications.ToastTemplateType]::ToastText01)

    #Convert to .NET type for XML manipulation
    $toastXml = [xml] $template.GetXml()
    $toastXml.GetElementsByTagName("text").AppendChild($toastXml.CreateTextNode($title)) > $null
    # TODO add subtitle

    #Convert back to WinRT type
    $xml = New-Object Windows.Data.Xml.Dom.XmlDocument
    $xml.LoadXml($toastXml.OuterXml)

    $toast = [Windows.UI.Notifications.ToastNotification]::new($xml)
    $toast.Tag = $tag
    $toast.Group = $group
    $toast.ExpirationTime = $expire_at
    $toast.SuppressPopup = -not $popup

    try {
        $notifier = [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($msg)
        if (-not $check_mode) {
            $notifier.Show($toast)
            $result.toast_sent = $true
            Start-Sleep -Seconds $expire_seconds
        }
    }
    catch {
        $excep = $_
        $result.exception = $excep.ScriptStackTrace
        Fail-Json -obj $result -message "Failed to create toast notifier: $($excep.Exception.Message)"
    }
}
else {
    $result.toast_sent = $false
    $result.no_toast_sent_reason = 'No logged in users to notify'
}

$endsend_at = Get-Date | Out-String
$stopwatch.Stop()

$result.time_taken = $stopwatch.Elapsed.TotalSeconds
$result.sent_localtime = $endsend_at.Trim()

Exit-Json -obj $result