-
Notifications
You must be signed in to change notification settings - Fork 47
/
CrashPlan PROe - Last Connected.xml
124 lines (107 loc) · 4.66 KB
/
CrashPlan PROe - Last Connected.xml
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
<?xml version="1.0" encoding="UTF-8"?>
<extensionAttribute>
<displayName>CrashPlan PROe - Last Connected</displayName>
<displayInCategory>Backup</displayInCategory>
<description>This attribute displays the last time CrashPlan PROe established a connection with the server. This attribute applies to both Mac and Windows.</description>
<dataType>date</dataType>
<scriptContentsMac>
#!/bin/sh
# Modified 1/24/13
# Third-Part Product page for CrashPlan PROe - https://jamfnation.jamfsoftware.com/viewProduct.html?id=217
CP_ServerAddress="EditFromTemplate_CrashPlan_PROe_Server_Name_-_including_protocol_and_port"
CP_AdminUsername="EditFromTemplate_CrashPlan_PROe_Service_Account_Username"
CP_AdminPassword="EditFromTemplate_CrashPlan_PROe_Service_Account_Password"
if [ "$CP_ServerAddress" == "" ] || [ "$CP_AdminUsername" == "" ] || [ "$CP_AdminPassword" == "" ];then
echo "<result>Please ensure all variables are set in the extension attribute script.</result>"
elif [ -f /Library/Application\ Support/CrashPlan/.identity ];then
SERVER=`echo $CP_ServerAddress | sed 's|/$||'`
GUID=`cat /Library/Application\ Support/CrashPlan/.identity | sed -n 's/guid=//p'`
DATA=`curl -q -u "$CP_AdminUsername:$CP_AdminPassword" -k "$SERVER/api/Computer?guid=$GUID&incBackupUsage=1" | sed -n 's/.*lastConnected": "\([^"]*\).*/\1/p'`
FORMATTED=`date -j -f "%Y-%m-%dT%H:%M:%S" "$DATA" "+%Y-%m-%d %H:%M:%S"`
echo "<result>$FORMATTED</result>"
else
echo "<result>Not installed</result>"
fi
</scriptContentsMac>
<scriptTypeWindows>VBScript</scriptTypeWindows>
<scriptContentsWindows>
On Error Resume Next
'Declaration of Objects, Constants, Variables
Dim objFSO
Dim objTextFile
Dim strTextFile
Dim objHTTP
Dim arrResults
Dim strResult
Dim GUID
Dim CP_ServerAddress
Dim CP_AdminUsername
Dim CP_AdminPassword
Dim SERVER
'Set Variables
CP_ServerAddress = "EditFromTemplate_CrashPlan_PROe_Server_Name_-_including_protocol_and_port"
CP_AdminUsername = "EditFromTemplate_CrashPlan_PROe_Service_Account_Username"
CP_AdminPassword = "EditFromTemplate_CrashPlan_PROe_Service_Account_Password"
'Validate Variables Have Been Set
If CP_ServerAddress = "" Or CP_AdminUsername = "" Or CP_AdminPassword = "" Then
WScript.Echo "<result>Please ensure all variables are set in the extension attribute script.</result>"
Else
'Set Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
'Set Constants
Const WinHttpRequestOption_SslErrorIgnoreFlags = 4
Const WinHttpRequestOption_RevertImpersonationOverSsl = 11
Const WinHttpRequestOption_EnableRedirects = 6
Const WinHttpRequestOption_EnableHttpsToHttpRedirects = 12
'Read in CrashPlan GUID
Set objTextFile = objFSO.OpenTextFile("C:\ProgramData\CrashPlan\.identity")
strTextFile = objTextFile.ReadAll
objTextFile.Close
arrResults=Split(strTextFile, Chr(13))
For i = 0 to ubound(arrResults)
If inStr(arrResults(i), "guid") > 0 Then
strResult = Replace(arrResults(i), "guid=", "")
GUID = strResult
strResult=""
Exit for
End if
Next
If GUID = "" Then
WScript.Echo "<result>Not installed</result>"
Else
If Right(CP_ServerAddress,1) = "/" Then
SERVER = Left(CP_ServerAddress, Len(CP_ServerAddress) -1)
Else
SERVER = CP_ServerAddress
End if
'Connect to the CrashPlan ProE Server Rest API
objHTTP.open "GET", SERVER & "/api/computers?guid=" & GUID & "&incBackupUsage=1", False
objHTTP.Option(WHttpRequestOption_SslErrorIgnoreFlags) = &H3300
objHTTP.Option(WinHttpRequestOption_EnableHttpsToHttpRedirects) = True
'objHTTP.Option(WinHttpRequestOption_EnableRedirects) = False
'objHTTP.Option(WinHttpRequestOption_RevertImpersonationOverSsl) = False
objHTTP.SetCredentials CP_AdminUsername, CP_AdminPassword, 0
objHTTP.send
'Parse the JSON Output
If objHTTP.Status = "200" Then
arrResults=Split(objHTTP.ResponseText, ",")
For i = 0 to ubound(arrResults)
If inStr(arrResults(i), "lastConnected") > 0 Then
strResult = Replace(arrResults(i), chr(34), "", 1, -1)
strResult = Replace(strResult, "lastConnected:", "")
strResult = Replace(strResult, chr(10), "", 1, -1)
strResult = Trim(strResult)
strResult = Replace(strResult, "T", " ")
strResult = Split(strResult, ".")
Exit for
End if
Next
WScript.Echo "<result>" & strResult(0) & "</result>"
Else
WScript.Echo "<result>ERROR RETRIEVING DATA: " & objHTTP.Status & " - " & objHTTP.StatusText & "</result>"
End If
End If
End If
</scriptContentsWindows>
</extensionAttribute>