-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathXSFeatureUploadBugReport.py
More file actions
94 lines (77 loc) · 4.19 KB
/
Copy pathXSFeatureUploadBugReport.py
File metadata and controls
94 lines (77 loc) · 4.19 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
# Copyright (c) 2008-2009 Citrix Systems Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
if __name__ == "__main__":
raise Exception("This script is a plugin for xsconsole and cannot run independently")
from XSConsoleStandard import *
class UploadBugReportDialogue(InputDialogue):
def __init__(self):
self.custom = {
'title' : Lang("Upload Bug Report"),
'info' : Lang("Please enter the destination server name, and proxy name if required (blank for none). Use the form ftp://username:password@server:port for authenticated servers and proxies."),
'fields' : [
[Lang("Destination", 14), Config.Inst().FTPServer(), 'destination'],
[Lang("Filename", 14), FileUtils.BugReportFilename(), 'filename'],
[Lang("Proxy", 14), '', 'proxy']
]
}
InputDialogue.__init__(self)
def HandleCommit(self, inValues):
Layout.Inst().TransientBanner(Lang("Uploading Bug Report..."))
hostRef = ShellUtils.MakeSafeParam(Data.Inst().host.uuid(''))
destServer = ShellUtils.MakeSafeParam(inValues['destination'])
if not re.match(r'(ftp|http|https)://', destServer):
raise Exception(Lang('Destination name must start with ftp://, http:// or https://'))
destFilename = ShellUtils.MakeSafeParam(inValues['filename'])
destURL = destServer.rstrip('/')+'/'+destFilename.lstrip('/')
proxy = ShellUtils.MakeSafeParam(inValues['proxy'])
command = "%s host-bugreport-upload host='%s' url='%s'" % (Config.Inst().XECLIPath(), hostRef, destURL)
if proxy != '':
command += " http_proxy='"+proxy+"'"
status, output = getstatusoutput(command)
if status != 0:
XSLogError('Upload bugreport failed', output) # Error output can be verbose, so syslog only
raise Exception(Lang('The bug report upload failed. Please check that the destination directory is correct, and that the server accepts anonymous uploads to that directory and is reachable from this network.'))
return (Lang("Bug Report Uploaded Successfully"), None)
class XSFeatureUploadBugReport:
@classmethod
def StatusUpdateHandler(cls, inPane):
data = Data.Inst()
inPane.AddTitleField(Lang("Upload Bug Report"))
inPane.AddWrappedTextField(Lang(
"This option will upload a bug report file, containing information about "
"the state of this machine to the support ftp server. This file may contain sensitive data."))
inPane.AddKeyHelpField( { Lang("<Enter>") : Lang("Upload Bug Report") } )
@classmethod
def ActivateHandler(cls):
DialogueUtils.AuthenticatedOnly(lambda: Layout.Inst().PushDialogue(QuestionDialogue(
Lang("This operation may upload sensitive data to the support server. Do you want to continue?"), lambda x: cls.ConfirmHandler(x))))
@classmethod
def ConfirmHandler(cls, inYesNo):
if inYesNo == 'y':
DialogueUtils.AuthenticatedOnly(lambda: Layout.Inst().PushDialogue(UploadBugReportDialogue()))
def Register(self):
Importer.RegisterNamedPlugIn(
self,
'UPLOAD_BUG_REPORT', # Key of this plugin for replacement, etc.
{
'menuname' : 'MENU_TECHNICAL',
'menupriority' : 200,
'menutext' : Lang('Upload Bug Report') ,
'statusupdatehandler' : self.StatusUpdateHandler,
'activatehandler' : self.ActivateHandler
}
)
# Register this plugin when module is imported
XSFeatureUploadBugReport().Register()