-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path106.ps1
More file actions
139 lines (119 loc) · 5.54 KB
/
Copy path106.ps1
File metadata and controls
139 lines (119 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
##########################################################################################
## Depends on the PsXmppHelper.dll from http://CodePlex.com/PowerXmpp
## CONTAINS Read-HostMasked http://powershellcentral.com/scripts/104
## CONTAINS Out-Working http://powershellcentral.com/scripts/105
##########################################################################################
## NOTICE: THERE IS WAY TOO LITTLE ERROR HANDLING HERE!!!!
## IF EVERYTHING does not go very well, you will likely get very little explanation
## MAKE SURE YOU ARE USING a registered jabber id and password
##########################################################################################
## Read-HostMasked
## See: http://powershellcentral.com/scripts/104
function Read-HostMasked([string]$prompt="Password") {
$password = Read-Host -AsSecureString $prompt;
$BSTR = [System.Runtime.InteropServices.marshal]::SecureStringToBSTR($password);
$password = [System.Runtime.InteropServices.marshal]::PtrToStringAuto($BSTR);
[System.Runtime.InteropServices.Marshal]::ZeroFreeBSTR($BSTR);
return $password;
}
##########################################################################################
## Out-Working
## See: http://powershellcentral.com/scripts/105
$fore="White"; $back="red";
$work = @( $Host.UI.RawUI.NewBufferCellArray(@("|"),$fore,$back),
$Host.UI.RawUI.NewBufferCellArray(@("/"),$fore,$back),
$Host.UI.RawUI.NewBufferCellArray(@("-"),$fore,$back),
$Host.UI.RawUI.NewBufferCellArray(@("\"),$fore,$back) );
[int]$script:w = 0;
filter out-working($wait=0) {
$cur = $Host.UI.RawUI.Get_CursorPosition();
$cur.X = 0; $cur.Y -=1;
$Host.UI.RawUI.SetBufferContents($cur,$work[$script:w++]);
if($script:w -gt 3) {$script:w = 0 }
Start-Sleep -milli $wait
$_
}
##########################################################################################
## Start-IrcJabberBridge - an Xmpp script
## Depends on the PsXmppHelper.dll from http://CodePlex.com/PowerXmpp
##
function Start-IRCJabberBridge {
param (
$From = $( Read-Host "Your Jabber ID" )
,$Password = $( Read-HostMasked "Password")
,$Message = $( Read-Host "Your Message!" )
,$To = $( Read-Host "Recipient's Jabber ID" )
,$Chat = "PowerShell%irc.FreeNode.net@irc.im.flosoft.biz" # An IRC channel to join!
,$ChatNick = "PowerBot" # Your nickname in IRC
,$ChatPassword = $null
)
# Set path appropriately...
[reflection.assembly]::LoadFrom( "agsXMPP.dll" ) | fl Location, FullName, GlobalAssemblyCache
[reflection.assembly]::LoadFrom( "PsXmppHelper.dll" ) | fl Location, FullName, GlobalAssemblyCache
$jidSender = New-Object agsxmpp.jid $From
$jidChat = New-Object agsxmpp.jid $chat
$jidReceiver = New-Object agsxmpp.jid $To
$xmpp = New-Object agsxmpp.XmppClientConnection( [string]$jidSender.Server )
## Use SRV lookups to determine correct XMPP server if different from the server
## portion of your JID. e.g. user@gmail.com, the server is really talk.google.com
# $xmpp.AutoResolveConnectServer = $TRUE
$xmpp.SocketConnectionType = [agsXMPP.net.SocketConnectionType]::HttpPolling;
$xmpp.ConnectServer = "http://im.flosoft.biz:5280/http-poll/";
# Since this function is only used to send a message, we don't care about doing the
# normal discovery and requesting a roster. Leave disabled to quicken the login period.
$xmpp.AutoAgents = $false
$xmpp.AutoRoster = $false
# The following switches may assist in troubleshooting connection issues.
# If SSL and StartTLS are disabled, then you can use a network sniffer to inspect the XML
#$xmpp.UseSSL = $false
#$xmpp.UseStartTLS = $false
### SOME CONSTANTS
$MSG = "agsXMPP.protocol.client.Message"
$ChatMessage = [agsXMPP.protocol.client.MessageType]::chat
$GroupMessage = [agsXMPP.protocol.client.MessageType]::groupchat
$queue = New-Object PsXmppClient.MessageQueue $xmpp
$muc = New-Object agsXMPP.protocol.x.muc.MucManager $xmpp
# Connect and wait ...
$xmpp.Open($jidSender.User, $Password)
while ( !$xmpp.Authenticated ) {
Write-Verbose ("{0} - {1}" -f $xmpp.XmppConnectionState, $xmpp.Authenticated )
[Threading.Thread]::Sleep(200)
}
Write-Verbose ("{0} - {1}" -f $xmpp.XmppConnectionState, $xmpp.Authenticated )
# Set our status so we're visible
$xmpp.Show = "chat"
$xmpp.Status = "I'm a PowerShell Bot"
$xmpp.SendMyPresence()
# Join the chat room (the same as "SendMyPresence", except to a MUC)
$muc.JoinRoom($jidChat, $ChatNick, $ChatPassword)
# Send the initial message
$xmpp.Send((New-Object $MSG $jidReceiver, $ChatMessage, $Message))
$counter = 0
" Press any key to continue"
while (!$Host.UI.RawUI.KeyAvailable)
{
foreach ($m in $queue.Messages)
{
" <{0}> {1}" -f $m.From.Resource, $m.Body
if ($m.From.Bare -eq $To)
{
$xmpp.Send((New-Object $MSG $jidChat, $GroupMessage, $M.Body))
}
else
{
## "{0}=={1}" -f $m.From.Bare,$To
$xmpp.Send((New-Object $MSG $jidReceiver, $ChatMessage, ("<{0}> {1}" -f $m.From.Resource, $m.Body)))
}
}
$counter++
# Every so often, re-broadcast our continued presence
# Over http polling, not doing this was causing vanishing problems...
if(($counter % 50) -eq 0 ) {
$xmpp.SendMyPresence()
$muc.JoinRoom($jidChat, $ChatNick)
}
out-working 100
}
$muc.LeaveRoom($jidChat, $ChatNick);
$xmpp.Close();
}