Can export diagnosis to file.
This commit is contained in:
@ -386,6 +386,29 @@ class AppDelegate: NSObject, NSApplicationDelegate, NSUserNotificationCenterDele
|
||||
NSWorkspace.shared.open(URL(string: "https://github.com/shadowsocks/ShadowsocksX-NG/releases")!)
|
||||
}
|
||||
|
||||
@IBAction func exportDiagnosis(_ sender: NSMenuItem) {
|
||||
let savePanel = NSSavePanel()
|
||||
savePanel.title = "Save All Server URLs To File".localized
|
||||
savePanel.canCreateDirectories = true
|
||||
savePanel.allowedFileTypes = ["txt"]
|
||||
savePanel.isExtensionHidden = false
|
||||
|
||||
let formatter = DateFormatter()
|
||||
formatter.dateFormat = "yyyyMMdd_HHmmss"
|
||||
let dateString = formatter.string(from: Date())
|
||||
|
||||
savePanel.nameFieldStringValue = "ShadowsocksX-NG_diagnose_\(dateString)"
|
||||
|
||||
savePanel.becomeKey()
|
||||
let result = savePanel.runModal()
|
||||
if (result.rawValue == NSFileHandlingPanelOKButton) {
|
||||
if let url = savePanel.url {
|
||||
let diagnosisText = diagnose()
|
||||
try! diagnosisText.write(to: url, atomically: false, encoding: String.Encoding.utf8)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@IBAction func showHelp(_ sender: NSMenuItem) {
|
||||
NSWorkspace.shared.open(URL(string: "https://github.com/shadowsocks/ShadowsocksX-NG/wiki")!)
|
||||
}
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14113" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="14313.18" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
|
||||
<dependencies>
|
||||
<deployment identifier="macosx"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14113"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="14313.18"/>
|
||||
</dependencies>
|
||||
<objects>
|
||||
<customObject id="-2" userLabel="File's Owner" customClass="NSApplication">
|
||||
@ -123,6 +123,12 @@
|
||||
<action selector="showLogs:" target="Voe-Tx-rLC" id="5FZ-Xo-DGb"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Export Diagnosis..." id="eNh-vY-utd">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
<action selector="exportDiagnosis:" target="Voe-Tx-rLC" id="YM9-l3-PHa"/>
|
||||
</connections>
|
||||
</menuItem>
|
||||
<menuItem title="Check for Updates..." id="hLv-bp-doM">
|
||||
<modifierMask key="keyEquivalentModifierMask"/>
|
||||
<connections>
|
||||
|
||||
93
ShadowsocksX-NG/Diagnose.swift
Normal file
93
ShadowsocksX-NG/Diagnose.swift
Normal file
@ -0,0 +1,93 @@
|
||||
//
|
||||
// diagnose.swift
|
||||
// ShadowsocksX-NG
|
||||
//
|
||||
// Created by 邱宇舟 on 2018/10/2.
|
||||
// Copyright © 2018 qiuyuzhou. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
func shell(_ args: String...) -> String {
|
||||
let task = Process()
|
||||
task.launchPath = "/usr/bin/env"
|
||||
task.arguments = args
|
||||
|
||||
let pipe = Pipe()
|
||||
task.standardOutput = pipe
|
||||
|
||||
task.launch()
|
||||
task.waitUntilExit()
|
||||
|
||||
let data = pipe.fileHandleForReading.readDataToEndOfFile()
|
||||
let output = String(data: data, encoding: String.Encoding.utf8)
|
||||
|
||||
return output ?? ""
|
||||
}
|
||||
|
||||
func diagnose() -> String {
|
||||
var strs = [String]()
|
||||
|
||||
strs.append("\n-----------------------------------\n")
|
||||
let infoDict = Bundle.main.infoDictionary!
|
||||
let infoDictJsonData = try! JSONSerialization.data(withJSONObject: infoDict, options: JSONSerialization.WritingOptions.prettyPrinted)
|
||||
|
||||
strs.append(String(data: infoDictJsonData, encoding: String.Encoding.utf8)!)
|
||||
strs.append("\n-----------------------------------\n")
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
let keys = [
|
||||
"ShadowsocksOn",
|
||||
"ShadowsocksRunningMode",
|
||||
"LocalSocks5.ListenPort",
|
||||
"LocalSocks5.ListenAddress",
|
||||
"PacServer.ListenPort",
|
||||
"LocalSocks5.Timeout",
|
||||
"LocalSocks5.EnableUDPRelay",
|
||||
"LocalSocks5.EnableVerboseMode",
|
||||
"GFWListURL",
|
||||
"LocalHTTP.ListenAddress",
|
||||
"LocalHTTP.ListenPort",
|
||||
"LocalHTTPOn",
|
||||
"LocalHTTP.FollowGlobal",
|
||||
"ProxyExceptions",
|
||||
]
|
||||
|
||||
strs.append("Preferences:\n")
|
||||
for key in keys {
|
||||
if let obj = defaults.object(forKey: key) {
|
||||
strs.append("\(key)=\(obj)\n")
|
||||
}
|
||||
}
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("Active server profile: \n")
|
||||
|
||||
if let profile = ServerProfileManager.instance.getActiveProfile() {
|
||||
strs.append(profile.debugString())
|
||||
} else {
|
||||
strs.append("No actived server profile!")
|
||||
}
|
||||
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("$ ls -l ~/Library/Application Support/ShadowsocksX-NG/\n")
|
||||
strs.append(shell("ls", "-l", NSHomeDirectory() + "/Library/Application Support/ShadowsocksX-NG/"))
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("$ ls -l ~/Library/LaunchAgents/\n")
|
||||
strs.append(shell("ls", "-l", NSHomeDirectory() + "/Library/LaunchAgents/"))
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("$ ls -l ~/.ShadowsocksX-NG/\n")
|
||||
strs.append(shell("ls", "-l", NSHomeDirectory() + "/.ShadowsocksX-NG/"))
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("$ ls -l /Library/Application Support/ShadowsocksX-NG/")
|
||||
strs.append(shell("ls", "-l", "/Library/Application Support/ShadowsocksX-NG/"))
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("$ lsof -PiTCP -sTCP:LISTEN")
|
||||
strs.append(shell("lsof", "-PiTCP", "-sTCP:LISTEN"))
|
||||
strs.append("-----------------------------------\n")
|
||||
strs.append("$ ifconfig")
|
||||
strs.append(shell("ifconfig"))
|
||||
strs.append("-----------------------------------\n")
|
||||
|
||||
let output = strs.joined()
|
||||
return output
|
||||
}
|
||||
@ -194,6 +194,17 @@ class ServerProfile: NSObject, NSCopying {
|
||||
|
||||
return conf
|
||||
}
|
||||
|
||||
func debugString() -> String {
|
||||
var buf = ""
|
||||
print("ServerHost=\(String(repeating: "*", count: serverHost.count))", to: &buf)
|
||||
print("ServerPort=\(serverPort)", to: &buf)
|
||||
print("Method=\(method)", to: &buf)
|
||||
print("Password=\(String(repeating: "*", count: password.count))", to: &buf)
|
||||
print("Plugin=\(plugin)", to: &buf)
|
||||
print("PluginOptions=\(pluginOptions)", to: &buf)
|
||||
return buf
|
||||
}
|
||||
|
||||
func isValid() -> Bool {
|
||||
func validateIpAddress(_ ipToValidate: String) -> Bool {
|
||||
|
||||
Reference in New Issue
Block a user