From b5641501fd52c6f17b132c428b0969ad11bd33c5 Mon Sep 17 00:00:00 2001 From: plane000 Date: Sun, 27 May 2018 16:11:50 +0100 Subject: [PATCH] Finished script --- down-detector.js | 69 + node_modules/ping/.eslintrc.json | 1112 +++++++++ node_modules/ping/.gitattributes | 17 + node_modules/ping/.npmignore | 16 + node_modules/ping/.travis.yml | 18 + node_modules/ping/CONTRIBUTING.md | 57 + node_modules/ping/Gruntfile.js | 22 + node_modules/ping/LICENSE | 8 + node_modules/ping/README.md | 148 ++ node_modules/ping/examples/example.js | 25 + node_modules/ping/examples/example2.js | 39 + node_modules/ping/index.js | 7 + node_modules/ping/lib/builder/factory.js | 111 + node_modules/ping/lib/builder/linux.js | 75 + node_modules/ping/lib/builder/mac.js | 75 + node_modules/ping/lib/builder/win.js | 78 + node_modules/ping/lib/parser/base.js | 181 ++ node_modules/ping/lib/parser/factory.js | 39 + node_modules/ping/lib/parser/linux.js | 48 + node_modules/ping/lib/parser/mac.js | 77 + node_modules/ping/lib/parser/win.js | 87 + node_modules/ping/lib/ping-pcap.js | 46 + node_modules/ping/lib/ping-promise.js | 87 + node_modules/ping/lib/ping-sys.js | 45 + node_modules/ping/package.json | 130 ++ node_modules/ping/test/fixture/answer.json | 68 + .../ping/test/fixture/linux/.gitdirectory | 0 .../ping/test/fixture/linux/en/sample1.txt | 9 + .../ping/test/fixture/macos/.gitdirectory | 0 .../ping/test/fixture/macos/en/sample1.txt | 9 + .../ping/test/fixture/window/.gitdirectory | 0 .../ping/test/fixture/window/en/sample1.txt | 10 + .../ping/test/fixture/window/zh/sample1.txt | 10 + .../ping/test/fixture/window/zh/sample2.txt | 11 + .../ping/test/fixture/window/zh/sample3.txt | 11 + node_modules/ping/test/load-fixture-path.js | 61 + node_modules/ping/test/test-ping.js | 187 ++ node_modules/q/CHANGES.md | 800 +++++++ node_modules/q/LICENSE | 18 + node_modules/q/README.md | 874 +++++++ node_modules/q/package.json | 116 + node_modules/q/q.js | 2076 +++++++++++++++++ node_modules/q/queue.js | 35 + node_modules/underscore/LICENSE | 23 + node_modules/underscore/README.md | 28 + node_modules/underscore/package.json | 81 + node_modules/underscore/underscore-min.js | 5 + node_modules/underscore/underscore-min.js.map | 1 + node_modules/underscore/underscore.js | 1688 ++++++++++++++ package-lock.json | 27 + package.json | 22 + 51 files changed, 8787 insertions(+) create mode 100644 down-detector.js create mode 100644 node_modules/ping/.eslintrc.json create mode 100644 node_modules/ping/.gitattributes create mode 100644 node_modules/ping/.npmignore create mode 100644 node_modules/ping/.travis.yml create mode 100644 node_modules/ping/CONTRIBUTING.md create mode 100644 node_modules/ping/Gruntfile.js create mode 100644 node_modules/ping/LICENSE create mode 100644 node_modules/ping/README.md create mode 100644 node_modules/ping/examples/example.js create mode 100644 node_modules/ping/examples/example2.js create mode 100644 node_modules/ping/index.js create mode 100644 node_modules/ping/lib/builder/factory.js create mode 100644 node_modules/ping/lib/builder/linux.js create mode 100644 node_modules/ping/lib/builder/mac.js create mode 100644 node_modules/ping/lib/builder/win.js create mode 100644 node_modules/ping/lib/parser/base.js create mode 100644 node_modules/ping/lib/parser/factory.js create mode 100644 node_modules/ping/lib/parser/linux.js create mode 100644 node_modules/ping/lib/parser/mac.js create mode 100644 node_modules/ping/lib/parser/win.js create mode 100644 node_modules/ping/lib/ping-pcap.js create mode 100644 node_modules/ping/lib/ping-promise.js create mode 100644 node_modules/ping/lib/ping-sys.js create mode 100644 node_modules/ping/package.json create mode 100644 node_modules/ping/test/fixture/answer.json create mode 100644 node_modules/ping/test/fixture/linux/.gitdirectory create mode 100644 node_modules/ping/test/fixture/linux/en/sample1.txt create mode 100644 node_modules/ping/test/fixture/macos/.gitdirectory create mode 100644 node_modules/ping/test/fixture/macos/en/sample1.txt create mode 100644 node_modules/ping/test/fixture/window/.gitdirectory create mode 100644 node_modules/ping/test/fixture/window/en/sample1.txt create mode 100644 node_modules/ping/test/fixture/window/zh/sample1.txt create mode 100644 node_modules/ping/test/fixture/window/zh/sample2.txt create mode 100644 node_modules/ping/test/fixture/window/zh/sample3.txt create mode 100644 node_modules/ping/test/load-fixture-path.js create mode 100644 node_modules/ping/test/test-ping.js create mode 100644 node_modules/q/CHANGES.md create mode 100644 node_modules/q/LICENSE create mode 100644 node_modules/q/README.md create mode 100644 node_modules/q/package.json create mode 100644 node_modules/q/q.js create mode 100644 node_modules/q/queue.js create mode 100644 node_modules/underscore/LICENSE create mode 100644 node_modules/underscore/README.md create mode 100644 node_modules/underscore/package.json create mode 100644 node_modules/underscore/underscore-min.js create mode 100644 node_modules/underscore/underscore-min.js.map create mode 100644 node_modules/underscore/underscore.js create mode 100644 package-lock.json create mode 100644 package.json diff --git a/down-detector.js b/down-detector.js new file mode 100644 index 0000000..0cdb204 --- /dev/null +++ b/down-detector.js @@ -0,0 +1,69 @@ +const ping = require('ping'); + +setInterval(doStuff, 1000); + +var downFor = []; +var lastState; +var connected; +var counter = 0; + +function doStuff() { + var lastPing; + + ping.promise.probe('google.com', { + timeout: 10 + }).then((result) => { + var time = getTime(); + connected = result.alive; + //log(connected); + if (lastState == true && connected == false) { + LostConnection(); + } else if (lastState == false && connected == true) { + ConnectionRegained(counter); + counter = 0; + } + + if (connected == false) { + counter++; + } + lastState = connected; + }); +} + +function ConnectionRegained(timedown) { + var time = getTime(); + console.log ( + '[' + time + '] ' + + 'Connection regained after ' + + timedown + + 's of downtime' + ); +} + +function LostConnection() { + var time = getTime(); + console.log ( + '[' + time + '] ' + + 'Lost Connection' + ); +} + +function log(tolog) { + var time = getTime(); + console.log ( + '[' + time + '] ' + + tolog + ); +} + +function pad(n, width, z) { + z = z || '0'; + n = n + ''; + return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; + } + +function getTime() { + var t = new Date(); + var time = (pad(t.getHours(), 2) + ':' + pad(t.getMinutes(), 2) + ':' + pad(t.getSeconds(), 2)) + return time; + } \ No newline at end of file diff --git a/node_modules/ping/.eslintrc.json b/node_modules/ping/.eslintrc.json new file mode 100644 index 0000000..b911d71 --- /dev/null +++ b/node_modules/ping/.eslintrc.json @@ -0,0 +1,1112 @@ +{ + "globals": { + "__dirname": false, + "__filename": false, + "arguments": false, + "Buffer": false, + "clearImmediate": false, + "clearInterval": false, + "clearTimeout": false, + "console": false, + "exports": true, + "GLOBAL": false, + "global": false, + "Intl": false, + "module": false, + "process": false, + "require": false, + "root": false, + "setImmediate": false, + "setInterval": false, + "setTimeout": false, + "addEventListener": false, + "alert": false, + "AnalyserNode": false, + "AnimationEvent": false, + "applicationCache": false, + "ApplicationCache": false, + "ApplicationCacheErrorEvent": false, + "atob": false, + "Attr": false, + "Audio": false, + "AudioBuffer": false, + "AudioBufferSourceNode": false, + "AudioContext": false, + "AudioDestinationNode": false, + "AudioListener": false, + "AudioNode": false, + "AudioParam": false, + "AudioProcessingEvent": false, + "AutocompleteErrorEvent": false, + "BarProp": false, + "BatteryManager": false, + "BeforeUnloadEvent": false, + "BiquadFilterNode": false, + "Blob": false, + "blur": false, + "btoa": false, + "Cache": false, + "caches": false, + "CacheStorage": false, + "cancelAnimationFrame": false, + "CanvasGradient": false, + "CanvasPattern": false, + "CanvasRenderingContext2D": false, + "CDATASection": false, + "ChannelMergerNode": false, + "ChannelSplitterNode": false, + "CharacterData": false, + "clientInformation": false, + "ClientRect": false, + "ClientRectList": false, + "ClipboardEvent": false, + "close": false, + "closed": false, + "CloseEvent": false, + "Comment": false, + "CompositionEvent": false, + "confirm": false, + "ConvolverNode": false, + "crypto": false, + "Crypto": false, + "CryptoKey": false, + "CSS": false, + "CSSFontFaceRule": false, + "CSSImportRule": false, + "CSSKeyframeRule": false, + "CSSKeyframesRule": false, + "CSSMediaRule": false, + "CSSPageRule": false, + "CSSRule": false, + "CSSRuleList": false, + "CSSStyleDeclaration": false, + "CSSStyleRule": false, + "CSSStyleSheet": false, + "CSSSupportsRule": false, + "CSSUnknownRule": false, + "CSSViewportRule": false, + "CustomEvent": false, + "DataTransfer": false, + "DataTransferItem": false, + "DataTransferItemList": false, + "Debug": false, + "defaultStatus": false, + "defaultstatus": false, + "DelayNode": false, + "DeviceMotionEvent": false, + "DeviceOrientationEvent": false, + "devicePixelRatio": false, + "dispatchEvent": false, + "document": false, + "Document": false, + "DocumentFragment": false, + "DocumentType": false, + "DOMError": false, + "DOMException": false, + "DOMImplementation": false, + "DOMParser": false, + "DOMSettableTokenList": false, + "DOMStringList": false, + "DOMStringMap": false, + "DOMTokenList": false, + "DragEvent": false, + "DynamicsCompressorNode": false, + "Element": false, + "ElementTimeControl": false, + "ErrorEvent": false, + "event": false, + "Event": false, + "EventSource": false, + "EventTarget": false, + "external": false, + "fetch": false, + "File": false, + "FileError": false, + "FileList": false, + "FileReader": false, + "find": false, + "focus": false, + "FocusEvent": false, + "FontFace": false, + "FormData": false, + "frameElement": false, + "frames": false, + "GainNode": false, + "Gamepad": false, + "GamepadButton": false, + "GamepadEvent": false, + "getComputedStyle": false, + "getSelection": false, + "HashChangeEvent": false, + "Headers": false, + "history": false, + "History": false, + "HTMLAllCollection": false, + "HTMLAnchorElement": false, + "HTMLAppletElement": false, + "HTMLAreaElement": false, + "HTMLAudioElement": false, + "HTMLBaseElement": false, + "HTMLBlockquoteElement": false, + "HTMLBodyElement": false, + "HTMLBRElement": false, + "HTMLButtonElement": false, + "HTMLCanvasElement": false, + "HTMLCollection": false, + "HTMLContentElement": false, + "HTMLDataListElement": false, + "HTMLDetailsElement": false, + "HTMLDialogElement": false, + "HTMLDirectoryElement": false, + "HTMLDivElement": false, + "HTMLDListElement": false, + "HTMLDocument": false, + "HTMLElement": false, + "HTMLEmbedElement": false, + "HTMLFieldSetElement": false, + "HTMLFontElement": false, + "HTMLFormControlsCollection": false, + "HTMLFormElement": false, + "HTMLFrameElement": false, + "HTMLFrameSetElement": false, + "HTMLHeadElement": false, + "HTMLHeadingElement": false, + "HTMLHRElement": false, + "HTMLHtmlElement": false, + "HTMLIFrameElement": false, + "HTMLImageElement": false, + "HTMLInputElement": false, + "HTMLIsIndexElement": false, + "HTMLKeygenElement": false, + "HTMLLabelElement": false, + "HTMLLayerElement": false, + "HTMLLegendElement": false, + "HTMLLIElement": false, + "HTMLLinkElement": false, + "HTMLMapElement": false, + "HTMLMarqueeElement": false, + "HTMLMediaElement": false, + "HTMLMenuElement": false, + "HTMLMetaElement": false, + "HTMLMeterElement": false, + "HTMLModElement": false, + "HTMLObjectElement": false, + "HTMLOListElement": false, + "HTMLOptGroupElement": false, + "HTMLOptionElement": false, + "HTMLOptionsCollection": false, + "HTMLOutputElement": false, + "HTMLParagraphElement": false, + "HTMLParamElement": false, + "HTMLPictureElement": false, + "HTMLPreElement": false, + "HTMLProgressElement": false, + "HTMLQuoteElement": false, + "HTMLScriptElement": false, + "HTMLSelectElement": false, + "HTMLShadowElement": false, + "HTMLSourceElement": false, + "HTMLSpanElement": false, + "HTMLStyleElement": false, + "HTMLTableCaptionElement": false, + "HTMLTableCellElement": false, + "HTMLTableColElement": false, + "HTMLTableElement": false, + "HTMLTableRowElement": false, + "HTMLTableSectionElement": false, + "HTMLTemplateElement": false, + "HTMLTextAreaElement": false, + "HTMLTitleElement": false, + "HTMLTrackElement": false, + "HTMLUListElement": false, + "HTMLUnknownElement": false, + "HTMLVideoElement": false, + "IDBCursor": false, + "IDBCursorWithValue": false, + "IDBDatabase": false, + "IDBEnvironment": false, + "IDBFactory": false, + "IDBIndex": false, + "IDBKeyRange": false, + "IDBObjectStore": false, + "IDBOpenDBRequest": false, + "IDBRequest": false, + "IDBTransaction": false, + "IDBVersionChangeEvent": false, + "Image": false, + "ImageBitmap": false, + "ImageData": false, + "indexedDB": false, + "innerHeight": false, + "innerWidth": false, + "InputEvent": false, + "InputMethodContext": false, + "KeyboardEvent": false, + "length": false, + "localStorage": false, + "location": false, + "Location": false, + "locationbar": false, + "matchMedia": false, + "MediaElementAudioSourceNode": false, + "MediaEncryptedEvent": false, + "MediaError": false, + "MediaKeyError": false, + "MediaKeyEvent": false, + "MediaKeyMessageEvent": false, + "MediaKeys": false, + "MediaKeySession": false, + "MediaKeyStatusMap": false, + "MediaKeySystemAccess": false, + "MediaList": false, + "MediaQueryList": false, + "MediaQueryListEvent": false, + "MediaSource": false, + "MediaStreamAudioDestinationNode": false, + "MediaStreamAudioSourceNode": false, + "MediaStreamEvent": false, + "MediaStreamTrack": false, + "menubar": false, + "MessageChannel": false, + "MessageEvent": false, + "MessagePort": false, + "MIDIAccess": false, + "MIDIConnectionEvent": false, + "MIDIInput": false, + "MIDIInputMap": false, + "MIDIMessageEvent": false, + "MIDIOutput": false, + "MIDIOutputMap": false, + "MIDIPort": false, + "MimeType": false, + "MimeTypeArray": false, + "MouseEvent": false, + "moveBy": false, + "moveTo": false, + "MutationEvent": false, + "MutationObserver": false, + "MutationRecord": false, + "name": false, + "NamedNodeMap": false, + "navigator": false, + "Navigator": false, + "Node": false, + "NodeFilter": false, + "NodeIterator": false, + "NodeList": false, + "Notification": false, + "OfflineAudioCompletionEvent": false, + "OfflineAudioContext": false, + "offscreenBuffering": false, + "onbeforeunload": true, + "onblur": true, + "onerror": true, + "onfocus": true, + "onload": true, + "onresize": true, + "onunload": true, + "open": false, + "openDatabase": false, + "opener": false, + "opera": false, + "Option": false, + "OscillatorNode": false, + "outerHeight": false, + "outerWidth": false, + "PageTransitionEvent": false, + "pageXOffset": false, + "pageYOffset": false, + "parent": false, + "Path2D": false, + "performance": false, + "Performance": false, + "PerformanceEntry": false, + "PerformanceMark": false, + "PerformanceMeasure": false, + "PerformanceNavigation": false, + "PerformanceResourceTiming": false, + "PerformanceTiming": false, + "PeriodicWave": false, + "Permissions": false, + "PermissionStatus": false, + "personalbar": false, + "Plugin": false, + "PluginArray": false, + "PopStateEvent": false, + "postMessage": false, + "print": false, + "ProcessingInstruction": false, + "ProgressEvent": false, + "prompt": false, + "PushManager": false, + "PushSubscription": false, + "RadioNodeList": false, + "Range": false, + "ReadableByteStream": false, + "ReadableStream": false, + "removeEventListener": false, + "Request": false, + "requestAnimationFrame": false, + "resizeBy": false, + "resizeTo": false, + "Response": false, + "RTCIceCandidate": false, + "RTCSessionDescription": false, + "screen": false, + "Screen": false, + "screenLeft": false, + "ScreenOrientation": false, + "screenTop": false, + "screenX": false, + "screenY": false, + "ScriptProcessorNode": false, + "scroll": false, + "scrollbars": false, + "scrollBy": false, + "scrollTo": false, + "scrollX": false, + "scrollY": false, + "SecurityPolicyViolationEvent": false, + "Selection": false, + "self": false, + "ServiceWorker": false, + "ServiceWorkerContainer": false, + "ServiceWorkerRegistration": false, + "sessionStorage": false, + "ShadowRoot": false, + "SharedWorker": false, + "showModalDialog": false, + "speechSynthesis": false, + "SpeechSynthesisEvent": false, + "SpeechSynthesisUtterance": false, + "status": false, + "statusbar": false, + "stop": false, + "Storage": false, + "StorageEvent": false, + "styleMedia": false, + "StyleSheet": false, + "StyleSheetList": false, + "SubtleCrypto": false, + "SVGAElement": false, + "SVGAltGlyphDefElement": false, + "SVGAltGlyphElement": false, + "SVGAltGlyphItemElement": false, + "SVGAngle": false, + "SVGAnimateColorElement": false, + "SVGAnimatedAngle": false, + "SVGAnimatedBoolean": false, + "SVGAnimatedEnumeration": false, + "SVGAnimatedInteger": false, + "SVGAnimatedLength": false, + "SVGAnimatedLengthList": false, + "SVGAnimatedNumber": false, + "SVGAnimatedNumberList": false, + "SVGAnimatedPathData": false, + "SVGAnimatedPoints": false, + "SVGAnimatedPreserveAspectRatio": false, + "SVGAnimatedRect": false, + "SVGAnimatedString": false, + "SVGAnimatedTransformList": false, + "SVGAnimateElement": false, + "SVGAnimateMotionElement": false, + "SVGAnimateTransformElement": false, + "SVGAnimationElement": false, + "SVGCircleElement": false, + "SVGClipPathElement": false, + "SVGColor": false, + "SVGColorProfileElement": false, + "SVGColorProfileRule": false, + "SVGComponentTransferFunctionElement": false, + "SVGCSSRule": false, + "SVGCursorElement": false, + "SVGDefsElement": false, + "SVGDescElement": false, + "SVGDiscardElement": false, + "SVGDocument": false, + "SVGElement": false, + "SVGElementInstance": false, + "SVGElementInstanceList": false, + "SVGEllipseElement": false, + "SVGEvent": false, + "SVGExternalResourcesRequired": false, + "SVGFEBlendElement": false, + "SVGFEColorMatrixElement": false, + "SVGFEComponentTransferElement": false, + "SVGFECompositeElement": false, + "SVGFEConvolveMatrixElement": false, + "SVGFEDiffuseLightingElement": false, + "SVGFEDisplacementMapElement": false, + "SVGFEDistantLightElement": false, + "SVGFEDropShadowElement": false, + "SVGFEFloodElement": false, + "SVGFEFuncAElement": false, + "SVGFEFuncBElement": false, + "SVGFEFuncGElement": false, + "SVGFEFuncRElement": false, + "SVGFEGaussianBlurElement": false, + "SVGFEImageElement": false, + "SVGFEMergeElement": false, + "SVGFEMergeNodeElement": false, + "SVGFEMorphologyElement": false, + "SVGFEOffsetElement": false, + "SVGFEPointLightElement": false, + "SVGFESpecularLightingElement": false, + "SVGFESpotLightElement": false, + "SVGFETileElement": false, + "SVGFETurbulenceElement": false, + "SVGFilterElement": false, + "SVGFilterPrimitiveStandardAttributes": false, + "SVGFitToViewBox": false, + "SVGFontElement": false, + "SVGFontFaceElement": false, + "SVGFontFaceFormatElement": false, + "SVGFontFaceNameElement": false, + "SVGFontFaceSrcElement": false, + "SVGFontFaceUriElement": false, + "SVGForeignObjectElement": false, + "SVGGElement": false, + "SVGGeometryElement": false, + "SVGGlyphElement": false, + "SVGGlyphRefElement": false, + "SVGGradientElement": false, + "SVGGraphicsElement": false, + "SVGHKernElement": false, + "SVGICCColor": false, + "SVGImageElement": false, + "SVGLangSpace": false, + "SVGLength": false, + "SVGLengthList": false, + "SVGLinearGradientElement": false, + "SVGLineElement": false, + "SVGLocatable": false, + "SVGMarkerElement": false, + "SVGMaskElement": false, + "SVGMatrix": false, + "SVGMetadataElement": false, + "SVGMissingGlyphElement": false, + "SVGMPathElement": false, + "SVGNumber": false, + "SVGNumberList": false, + "SVGPaint": false, + "SVGPathElement": false, + "SVGPathSeg": false, + "SVGPathSegArcAbs": false, + "SVGPathSegArcRel": false, + "SVGPathSegClosePath": false, + "SVGPathSegCurvetoCubicAbs": false, + "SVGPathSegCurvetoCubicRel": false, + "SVGPathSegCurvetoCubicSmoothAbs": false, + "SVGPathSegCurvetoCubicSmoothRel": false, + "SVGPathSegCurvetoQuadraticAbs": false, + "SVGPathSegCurvetoQuadraticRel": false, + "SVGPathSegCurvetoQuadraticSmoothAbs": false, + "SVGPathSegCurvetoQuadraticSmoothRel": false, + "SVGPathSegLinetoAbs": false, + "SVGPathSegLinetoHorizontalAbs": false, + "SVGPathSegLinetoHorizontalRel": false, + "SVGPathSegLinetoRel": false, + "SVGPathSegLinetoVerticalAbs": false, + "SVGPathSegLinetoVerticalRel": false, + "SVGPathSegList": false, + "SVGPathSegMovetoAbs": false, + "SVGPathSegMovetoRel": false, + "SVGPatternElement": false, + "SVGPoint": false, + "SVGPointList": false, + "SVGPolygonElement": false, + "SVGPolylineElement": false, + "SVGPreserveAspectRatio": false, + "SVGRadialGradientElement": false, + "SVGRect": false, + "SVGRectElement": false, + "SVGRenderingIntent": false, + "SVGScriptElement": false, + "SVGSetElement": false, + "SVGStopElement": false, + "SVGStringList": false, + "SVGStylable": false, + "SVGStyleElement": false, + "SVGSVGElement": false, + "SVGSwitchElement": false, + "SVGSymbolElement": false, + "SVGTests": false, + "SVGTextContentElement": false, + "SVGTextElement": false, + "SVGTextPathElement": false, + "SVGTextPositioningElement": false, + "SVGTitleElement": false, + "SVGTransform": false, + "SVGTransformable": false, + "SVGTransformList": false, + "SVGTRefElement": false, + "SVGTSpanElement": false, + "SVGUnitTypes": false, + "SVGURIReference": false, + "SVGUseElement": false, + "SVGViewElement": false, + "SVGViewSpec": false, + "SVGVKernElement": false, + "SVGZoomAndPan": false, + "SVGZoomEvent": false, + "Text": false, + "TextDecoder": false, + "TextEncoder": false, + "TextEvent": false, + "TextMetrics": false, + "TextTrack": false, + "TextTrackCue": false, + "TextTrackCueList": false, + "TextTrackList": false, + "TimeEvent": false, + "TimeRanges": false, + "toolbar": false, + "top": false, + "Touch": false, + "TouchEvent": false, + "TouchList": false, + "TrackEvent": false, + "TransitionEvent": false, + "TreeWalker": false, + "UIEvent": false, + "URL": false, + "URLSearchParams": false, + "ValidityState": false, + "VTTCue": false, + "WaveShaperNode": false, + "WebGLActiveInfo": false, + "WebGLBuffer": false, + "WebGLContextEvent": false, + "WebGLFramebuffer": false, + "WebGLProgram": false, + "WebGLRenderbuffer": false, + "WebGLRenderingContext": false, + "WebGLShader": false, + "WebGLShaderPrecisionFormat": false, + "WebGLTexture": false, + "WebGLUniformLocation": false, + "WebSocket": false, + "WheelEvent": false, + "window": false, + "Window": false, + "Worker": false, + "XDomainRequest": false, + "XMLDocument": false, + "XMLHttpRequest": false, + "XMLHttpRequestEventTarget": false, + "XMLHttpRequestProgressEvent": false, + "XMLHttpRequestUpload": false, + "XMLSerializer": false, + "XPathEvaluator": false, + "XPathException": false, + "XPathExpression": false, + "XPathNamespace": false, + "XPathNSResolver": false, + "XPathResult": false, + "XSLTProcessor": false, + "define": false, + "$": false, + "jQuery": false + }, + "env": { + "node": true, + "browser": true, + "amd": true, + "mocha": false, + "jasmine": false, + "es6": false, + "jquery": true + }, + "rules": { + "no-alert": 1, + "no-array-constructor": 2, + "no-bitwise": 0, + "no-caller": 2, + "no-case-declarations": 2, + "no-catch-shadow": 0, + "no-class-assign": 0, + "no-cond-assign": [ + 2, + "always" + ], + "no-confusing-arrow": [ + 2, + { + "allowParens": true + } + ], + "no-console": 0, + "no-const-assign": 2, + "no-constant-condition": 1, + "no-continue": 0, + "no-control-regex": 2, + "no-debugger": 2, + "no-delete-var": 2, + "no-div-regex": 0, + "no-dupe-class-members": 2, + "no-dupe-keys": 2, + "no-dupe-args": 2, + "no-duplicate-case": 2, + "no-duplicate-imports": 2, + "no-else-return": 2, + "no-empty": 2, + "no-empty-character-class": 2, + "no-empty-function": "off", + "no-empty-pattern": "error", + "no-eq-null": 0, + "no-eval": 2, + "no-ex-assign": 2, + "no-extend-native": 2, + "no-extra-bind": 2, + "no-extra-boolean-cast": 0, + "no-extra-label": 2, + "no-extra-parens": [ + 2, + "functions" + ], + "no-extra-semi": 2, + "no-fallthrough": 2, + "no-floating-decimal": 2, + "no-func-assign": 2, + "no-implicit-coercion": 0, + "no-implicit-globals": 0, + "no-implied-eval": 2, + "no-inline-comments": 0, + "no-inner-declarations": 2, + "no-invalid-regexp": 2, + "no-invalid-this": 0, + "no-irregular-whitespace": 2, + "no-iterator": 2, + "no-label-var": 0, + "no-labels": [ + 2, + { + "allowLoop": false, + "allowSwitch": false + } + ], + "no-lone-blocks": 2, + "no-lonely-if": 0, + "no-loop-func": 2, + "no-mixed-requires": [ + 2, + false + ], + "no-mixed-spaces-and-tabs": [ + 2, + false + ], + "linebreak-style": 0, + "no-multi-spaces": 2, + "no-multi-str": 2, + "no-multiple-empty-lines": [ + 2, + { + "max": 2, + "maxEOF": 1 + } + ], + "no-native-reassign": 2, + "no-negated-condition": "off", + "no-negated-in-lhs": 2, + "no-nested-ternary": 2, + "no-new": 2, + "no-new-func": 2, + "no-new-object": 2, + "no-new-require": 0, + "no-new-symbol": 2, + "no-new-wrappers": 2, + "no-obj-calls": 2, + "no-octal": 2, + "no-octal-escape": 2, + "no-param-reassign": [ + 2, + { + "props": true + } + ], + "no-path-concat": 2, + "no-plusplus": 0, + "no-process-env": 0, + "no-process-exit": 0, + "no-proto": 2, + "no-redeclare": 2, + "no-regex-spaces": 2, + "no-restricted-globals": 0, + "no-restricted-imports": 0, + "no-restricted-modules": 0, + "no-restricted-syntax": "off", + "no-return-assign": 2, + "no-script-url": 2, + "no-self-assign": 2, + "no-self-compare": 2, + "no-sequences": 2, + "no-shadow": 2, + "no-shadow-restricted-names": 2, + "no-whitespace-before-property": 2, + "no-spaced-func": 2, + "no-sparse-arrays": 2, + "no-sync": 0, + "no-ternary": 0, + "no-trailing-spaces": 2, + "no-this-before-super": 0, + "no-throw-literal": 2, + "no-undef": 2, + "no-undef-init": 2, + "no-undefined": 0, + "no-unexpected-multiline": 0, + "no-underscore-dangle": [ + 0, + { + "allowAfterThis": true + } + ], + "no-unmodified-loop-condition": 0, + "no-unneeded-ternary": [ + 2, + { + "defaultAssignment": false + } + ], + "no-unreachable": 2, + "no-unused-expressions": 2, + "no-unused-labels": 2, + "no-unused-vars": [ + 2, + { + "vars": "local", + "args": "after-used" + } + ], + "no-use-before-define": 2, + "no-useless-call": 0, + "no-useless-concat": 2, + "no-useless-constructor": 2, + "no-useless-escape": 2, + "no-void": 0, + "no-var": 0, + "no-warning-comments": [ + 0, + { + "terms": [ + "todo", + "fixme", + "xxx" + ], + "location": "start" + } + ], + "no-with": 2, + "no-magic-numbers": "off", + "array-bracket-spacing": [ + 2, + "never" + ], + "array-callback-return": 2, + "arrow-body-style": [ + 2, + "as-needed" + ], + "arrow-parens": 0, + "arrow-spacing": [ + 2, + { + "before": true, + "after": true + } + ], + "accessor-pairs": 0, + "block-scoped-var": 2, + "block-spacing": 2, + "brace-style": [ + 2, + "1tbs", + { + "allowSingleLine": true + } + ], + "callback-return": [ + 0, + [ + "cb", + "callback", + "next" + ] + ], + "camelcase": [ + 2, + { + "properties": "never" + } + ], + "comma-dangle": [ + 2, + "always-multiline" + ], + "comma-spacing": [ + 2, + { + "before": false, + "after": true + } + ], + "comma-style": [ + 2, + "last" + ], + "complexity": [ + 0, + 11 + ], + "computed-property-spacing": [ + 2, + "never" + ], + "consistent-return": 2, + "consistent-this": 0, + "constructor-super": 0, + "curly": [ + 2, + "multi-line" + ], + "default-case": 2, + "dot-location": 0, + "dot-notation": [ + 2, + { + "allowKeywords": true + } + ], + "eol-last": 2, + "eqeqeq": 2, + "func-names": 0, + "func-style": [ + 0, + "declaration" + ], + "generator-star-spacing": 0, + "global-require": "off", + "guard-for-in": 2, + "handle-callback-err": [ + 2, + "err" + ], + "id-length": 0, + "indent": [ + 2, + 4, + { + "SwitchCase": 1, + "VariableDeclarator": 1 + } + ], + "init-declarations": 0, + "key-spacing": [ + 2, + { + "beforeColon": false, + "afterColon": true + } + ], + "keyword-spacing": [ + 2, + { + "before": true, + "after": true, + "overrides": { + "return": { + "after": true + }, + "throw": { + "after": true + }, + "case": { + "after": true + } + } + } + ], + "lines-around-comment": 0, + "max-depth": [ + 0, + 4 + ], + "max-len": [ + 2, + 80, + 4, + { + "ignoreUrls": true + } + ], + "max-nested-callbacks": 0, + "max-params": [ + 0, + 3 + ], + "max-statements": [ + 0, + 10 + ], + "max-statements-per-line": "off", + "new-cap": [ + 2, + { + "newIsCap": true + } + ], + "new-parens": 0, + "newline-after-var": 0, + "newline-before-return": 0, + "newline-per-chained-call": [ + 0, + { + "ignoreChainWithDepth": 3 + } + ], + "object-curly-spacing": [ + 2, + "never" + ], + "object-shorthand": [ + 0, + "always" + ], + "one-var": [ + 2, + "never" + ], + "one-var-declaration-per-line": [ + 2, + "always" + ], + "operator-assignment": 0, + "operator-linebreak": 0, + "padded-blocks": [ + 2, + "never" + ], + "prefer-arrow-callback": 0, + "prefer-const": 2, + "prefer-reflect": 0, + "prefer-rest-params": 2, + "prefer-spread": 0, + "prefer-template": 0, + "quote-props": [ + 2, + "as-needed", + { + "keywords": false, + "unnecessary": true, + "numbers": false + } + ], + "quotes": [ + 2, + "single", + "avoid-escape" + ], + "radix": 2, + "id-match": 0, + "id-blacklist": 0, + "require-jsdoc": 2, + "require-yield": 0, + "semi": [ + 2, + "always" + ], + "semi-spacing": [ + 2, + { + "before": false, + "after": true + } + ], + "sort-vars": 0, + "sort-imports": 0, + "space-before-blocks": 2, + "space-before-function-paren": [ + 2, + { + "anonymous": "always", + "named": "never" + } + ], + "space-in-parens": [ + 2, + "never" + ], + "space-infix-ops": 2, + "space-unary-ops": [ + 0, + { + "words": true, + "nonwords": false + } + ], + "spaced-comment": [ + 2, + "always", + { + "exceptions": [ + "-", + "+" + ], + "markers": [ + "=", + "!" + ] + } + ], + "strict": [ + 2, + "global" + ], + "template-curly-spacing": 2, + "use-isnan": 2, + "valid-jsdoc": [ + 0, + { + "prefer": { + "return": "returns" + } + } + ], + "valid-typeof": 2, + "vars-on-top": 0, + "wrap-iife": [ + 2, + "outside" + ], + "wrap-regex": 0, + "yield-star-spacing": [ + 2, + "after" + ], + "yoda": [ + 2, + "never" + ] + }, + "parserOptions": { + "ecmaFeatures": { + "globalReturn": true, + "jsx": true, + "generators": false, + "objectLiteralDuplicateProperties": false, + "modules": false + }, + "ecmaVersion": 5, + "sourceType": "script" + }, + "parser": "babel-eslint", + "ecmaFeatures": { + "jsx": true + }, + "extends": [ + "eslint-config-eslint", + "eslint-config-airbnb" + ], + "plugins": [ + ] +} diff --git a/node_modules/ping/.gitattributes b/node_modules/ping/.gitattributes new file mode 100644 index 0000000..52aff59 --- /dev/null +++ b/node_modules/ping/.gitattributes @@ -0,0 +1,17 @@ +# Auto detect text files and perform LF normalization +* text eol=lf + +# Custom for Visual Studio +*.cs diff=csharp + +# Standard to msysgit +*.doc diff=astextplain +*.DOC diff=astextplain +*.docx diff=astextplain +*.DOCX diff=astextplain +*.dot diff=astextplain +*.DOT diff=astextplain +*.pdf diff=astextplain +*.PDF diff=astextplain +*.rtf diff=astextplain +*.RTF diff=astextplain diff --git a/node_modules/ping/.npmignore b/node_modules/ping/.npmignore new file mode 100644 index 0000000..87080a4 --- /dev/null +++ b/node_modules/ping/.npmignore @@ -0,0 +1,16 @@ +lib-cov +*.seed +*.log +*.csv +*.dat +*.out +*.pid +*.gz +*.tgz + +pids +logs +results + +node_modules +npm-debug.log diff --git a/node_modules/ping/.travis.yml b/node_modules/ping/.travis.yml new file mode 100644 index 0000000..473f015 --- /dev/null +++ b/node_modules/ping/.travis.yml @@ -0,0 +1,18 @@ +language: node_js +cache: + directories: + - node_modules +node_js: + - '6' + - '5' + - '4' + - iojs-v3 + - iojs-v2 + - iojs-v1 + - '0.12' + - '0.11' + - '0.10' + - '0.8' +before_script: + # This makes ping work in tests. + - /bin/ping -n -w 1 -c 1 127.0.0.1 diff --git a/node_modules/ping/CONTRIBUTING.md b/node_modules/ping/CONTRIBUTING.md new file mode 100644 index 0000000..835fd2f --- /dev/null +++ b/node_modules/ping/CONTRIBUTING.md @@ -0,0 +1,57 @@ +# Contributing + +We welcome patches and features. There are however a few things that are +required before your pull request can be merged. + +# Tests + +## How to write a new test case + +As output from system ping varied on languages and OS, our parser may fail +on new languages or OS. To improve the correctness and coverage for this +module, we need to gather output from those system pings. + +### Upload a fixture about system ping + +Suppose you are using `macos` in language `en`, you have a problem for running +our module. Please upload a capture of your system ping in folder +`test/fixture/$OS/$LANGUAGE`. In this case, the name of folder will be +`test/fixture/macos/en` + +### Write expected answer in answer.json + +NOTE: we recommend to use [this online editor][1] for editing the content for +`answer.json` + +To verify the correctness of our module on your new fixture, please provide +the expected answer in `test/fixture/answer.json`. + +Format of the key name is `$OS_$LANGUAGE_$FILENAME`. In our case, this is +`macos_en_sample1`. + +Value of that key should be the result from our command. + +``` +{ + "host": "google.com", + "numeric_host": "172.217.24.46", + "alive": true, + "output": "PING google.com (172.217.24.46): 56 data bytes\n64 bytes from 172.217.24.46: icmp_seq=0 ttl=54 time=5.371 ms\n64 bytes from 172.217.24.46: icmp_seq=1 ttl=54 time=4.269 ms\n64 bytes from 172.217.24.46: icmp_seq=2 ttl=54 time=4.970 ms\n64 bytes from 172.217.24.46: icmp_seq=3 ttl=54 time=5.228 ms\n\n--- google.com ping statistics ---\n4 packets transmitted, 4 packets received, 0.0% packet loss\nround-trip min/avg/max/stddev = 4.269/4.960/5.371/0.424 ms\n", + "time": 5.371, + "min": 4.269, + "max": 4.96, + "avg": 5.371, + "stddev": 0.424 +} +``` + +## Running test cases + +We trust tesed codes. Please run below command for testing before sending +a pull request + +``` +$ grunt test +``` + +[1]: http://www.jsoneditoronline.org/ diff --git a/node_modules/ping/Gruntfile.js b/node_modules/ping/Gruntfile.js new file mode 100644 index 0000000..81456ad --- /dev/null +++ b/node_modules/ping/Gruntfile.js @@ -0,0 +1,22 @@ +'use strict'; + +module.exports = function (grunt) { + grunt.initConfig({ + eslint: { + src: ['lib/*.js', 'lib/**/*.js'], + options: { + configFile: '.eslintrc.json', + }, + }, + mochaTest: { + src: ['test/test-*.js'], + options: { + reporter: 'dot', + }, + }, + }); + + grunt.loadNpmTasks('gruntify-eslint'); + grunt.loadNpmTasks('grunt-mocha-test'); + grunt.registerTask('test', ['eslint', 'mochaTest']); +}; diff --git a/node_modules/ping/LICENSE b/node_modules/ping/LICENSE new file mode 100644 index 0000000..be59731 --- /dev/null +++ b/node_modules/ping/LICENSE @@ -0,0 +1,8 @@ +MIT License +Copyright (c) 2016 Daniel Zelisko + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/node_modules/ping/README.md b/node_modules/ping/README.md new file mode 100644 index 0000000..2e45b13 --- /dev/null +++ b/node_modules/ping/README.md @@ -0,0 +1,148 @@ +#NODE-PING + +a ping wrapper for nodejs + +@last-modified: 2016-10-21 12:43 + +#LICENSE MIT + +(C) Daniel Zelisko + +http://github.com/danielzzz/node-ping + +#DESCRIPTION + +node-ping is a simple wrapper for the system ping utility + +#INSTALLATION + +npm install ping + +#USAGE + +Below are examples extracted from `examples` + +##Tradition calls + +```js +var ping = require('ping'); + +var hosts = ['192.168.1.1', 'google.com', 'yahoo.com']; +hosts.forEach(function(host){ + ping.sys.probe(host, function(isAlive){ + var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead'; + console.log(msg); + }); +}); +``` + +##Tradition calls with configuration + +```js +var cfg = { + timeout: 10, + // WARNING: -i 2 may not work in other platform like window + extra: ["-i 2"], +}; + +hosts.forEach(function(host){ + ping.sys.probe(host, function(isAlive){ + var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead'; + console.log(msg); + }, cfg); +}); +``` + +##Promise wrapper + +```js +var ping = require('ping'); + +var hosts = ['192.168.1.1', 'google.com', 'yahoo.com']; + +hosts.forEach(function (host) { + ping.promise.probe(host) + .then(function (res) { + console.log(res); + }); +}); +``` + +##Promise Wrapper with configable ping options + +```js +hosts.forEach(function (host) { + // WARNING: -i 2 argument may not work in other platform like window + ping.promise.probe(host, { + timeout: 10, + extra: ["-i 2"], + }).then(function (res) { + console.log(res); + }); +}); +``` + +### Support configuration + +Below is the possible configuration + +```js +/** + * Cross platform config representation + * @typedef {Object} PingConfig + * @property {boolean} numeric - Map IP address to hostname or not + * @property {number} timeout - Time duration for ping command to exit + * @property {number} min_reply - Exit after sending number of ECHO_REQUEST + * @property {string[]} extra - Optional options does not provided + */ +``` + +### Output specification + +* For callback based implementaiton: + +```js +/** + * Callback after probing given host + * @callback probeCallback + * @param {boolean} isAlive - Whether target is alive or not + * @param {Object} error - Null if no error occurs + */ +``` + +* For promise based implementation + +```js +/** + * Parsed response + * @typedef {object} PingResponse + * @param {string} host - The input IP address or HOST + * @param {string} numeric_host - Target IP address + * @param {boolean} alive - True for existed host + * @param {string} output - Raw stdout from system ping + * @param {number} time - Time (float) in ms for first successful ping response + * @param {string} min - Minimum time for collection records + * @param {string} max - Maximum time for collection records + * @param {string} avg - Average time for collection records + * @param {string} stddev - Standard deviation time for collected records + */ +``` + +#### Note + +* Since `ping` in this module relies on the `ping` from underlying platform, +arguments in `PingConfig.extra` will definitely be varied across different +platforms. + +* However, `numeric`, `timeout` and `min_reply` have been abstracted. Values for +them are expected to be cross platform. + +* By setting `numeric`, `timeout` or `min_reply` to false, you can run `ping` +without corresponding arguments. + +# Contributing + +Before opening a pull request please make sure your changes follow the +[contribution guidelines][1]. + +[1]: https://github.com/danielzzz/node-ping/blob/master/CONTRIBUTING.md diff --git a/node_modules/ping/examples/example.js b/node_modules/ping/examples/example.js new file mode 100644 index 0000000..fb09c42 --- /dev/null +++ b/node_modules/ping/examples/example.js @@ -0,0 +1,25 @@ +//-------- example ----------------------- + +var ping = require('../index'); + +var hosts = ['192.168.1.1', 'google.com', 'yahoo.com']; +hosts.forEach(function(host){ + // Running with default config + ping.sys.probe(host, function(isAlive){ + var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead'; + console.log(msg); + }); + + // Running with custom config + ping.sys.probe(host, function(isAlive){ + var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead'; + console.log(msg); + }, {extra: ["-i 2"]}); + + // Running ping with some default argument gone + ping.sys.probe(host, function(isAlive){ + var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead'; + console.log(msg); + }, {extra: ["-i 2"], timeout: false}); +}); + diff --git a/node_modules/ping/examples/example2.js b/node_modules/ping/examples/example2.js new file mode 100644 index 0000000..0977ac5 --- /dev/null +++ b/node_modules/ping/examples/example2.js @@ -0,0 +1,39 @@ +var ping = require("../index"); + +var hosts = ['192.168.1.1', 'google.com', 'yahoo.com']; + +// Running with default config +hosts.forEach(function (host) { + ping.promise.probe(host) + .then(function (res) { + console.log(res); + }) + .done(); +}); + +// Running with custom config +hosts.forEach(function (host) { + // WARNING: -i 2 argument may not work in other platform like window + ping.promise.probe(host, { + timeout: 10, + extra: ["-i", "2"], + }) + .then(function (res) { + console.log(res); + }) + .done(); +}); + +// Running ping with some default argument gone +hosts.forEach(function (host) { + // WARNING: -i 2 argument may not work in other platform like window + ping.promise.probe(host, { + timeout: false, + // Below extra arguments may not work in platforms other than linux + extra: ["-i", "2"], + }) + .then(function (res) { + console.log(res); + }) + .done(); +}); diff --git a/node_modules/ping/index.js b/node_modules/ping/index.js new file mode 100644 index 0000000..d8be8f1 --- /dev/null +++ b/node_modules/ping/index.js @@ -0,0 +1,7 @@ +var ping = {}; + +ping.sys = require('./lib/ping-sys'); +//ping.pcap = require('./lib/ping-pcap'); +ping.promise = require("./lib/ping-promise"); + +module.exports = ping; diff --git a/node_modules/ping/lib/builder/factory.js b/node_modules/ping/lib/builder/factory.js new file mode 100644 index 0000000..87a1af7 --- /dev/null +++ b/node_modules/ping/lib/builder/factory.js @@ -0,0 +1,111 @@ +'use strict'; + +var __ = require('underscore'); +var util = require('util'); + +// Our library +var linuxBuilder = require('./linux'); +var macBuilder = require('./mac'); +var winBuilder = require('./win'); + +/** + * A factory creates argument builders for different platform + * @constructor + */ +function factory() {} + +/** + * Check out linux platform + */ +factory.isLinux = function (p) { + var platforms = [ + 'aix', + 'linux', + ]; + + return platforms.indexOf(p) >= 0; +}; + +/** + * Check out macos platform + */ +factory.isMacOS = function (p) { + var platforms = [ + 'darwin', + 'freebsd', + ]; + + return platforms.indexOf(p) >= 0; +}; + +/** + * Check out window platform + */ +factory.isWindow = function (p) { + return p && p.match(/^win/) !== null; +}; + +/** + * Check whether given platform is supported + * @param {string} p - Name of the platform + * @return {bool} - True or False + */ +factory.isPlatformSupport = function (p) { + return __.some([ + this.isWindow(p), + this.isLinux(p), + this.isMacOS(p), + ]); +}; + +/** + * Return a path to the ping executable in the system + * @param {string} platform - Name of the platform + * @return {object} - Argument builder + * @throw if given platform is not supported + */ +factory.getExecutablePath = function (platform) { + if (!this.isPlatformSupport(platform)) { + throw new Error(util.format('Platform |%s| is not support', platform)); + } + + var ret = null; + + if (platform === 'aix') { + ret = '/usr/sbin/ping'; + } else if (factory.isLinux(platform)) { + ret = '/bin/ping'; + } else if (factory.isWindow(platform)) { + ret = process.env.SystemRoot + '/system32/ping.exe'; + } else if (factory.isMacOS(platform)) { + ret = '/sbin/ping'; + } + + return ret; +}; + +/** + * Create a builder + * @param {string} platform - Name of the platform + * @return {object} - Argument builder + * @throw if given platform is not supported + */ +factory.createBuilder = function (platform) { + if (!this.isPlatformSupport(platform)) { + throw new Error(util.format('Platform |%s| is not support', platform)); + } + + var ret = null; + + if (factory.isLinux(platform)) { + ret = linuxBuilder; + } else if (factory.isWindow(platform)) { + ret = winBuilder; + } else if (factory.isMacOS(platform)) { + ret = macBuilder; + } + + return ret; +}; + +module.exports = factory; diff --git a/node_modules/ping/lib/builder/linux.js b/node_modules/ping/lib/builder/linux.js new file mode 100644 index 0000000..7e8f14e --- /dev/null +++ b/node_modules/ping/lib/builder/linux.js @@ -0,0 +1,75 @@ +'use strict'; + +/** + * A builder builds command line arguments for ping in linux environment + * @module lib/builder/linux + */ +var util = require('util'); + +var builder = {}; + +/** + * Cross platform config representation + * @typedef {Object} PingConfig + * @property {boolean} numeric - Map IP address to hostname or not + * @property {number} timeout - Time duration for ping command to exit + * @property {number} min_reply - Exit after sending number of ECHO_REQUEST + * @property {string[]} extra - Optional options does not provided + */ + +var defaultConfig = { + numeric: true, + timeout: 2, + min_reply: 1, + extra: [], +}; + +/** + * Get the finalized array of command line arguments + * @param {string} target - hostname or ip address + * @param {PingConfig} [config] - Configuration object for cmd line argument + * @return {string[]} - Command line argument according to the configuration + */ +builder.getResult = function (target, config) { + var _config = config || {}; + + // Empty argument + var ret = []; + + // Make every key in config has been setup properly + var keys = ['numeric', 'timeout', 'min_reply', 'extra']; + keys.forEach(function (k) { + // Falsy value will be overrided without below checking + if (typeof(_config[k]) !== 'boolean') { + _config[k] = _config[k] || defaultConfig[k]; + } + }); + + if (_config.numeric) { + ret.push('-n'); + } + + if (_config.timeout) { + ret = ret.concat([ + '-w', + util.format('%d', _config.timeout), + ]); + } + + if (_config.min_reply) { + ret = ret.concat([ + '-c', + util.format('%d', _config.min_reply), + ]); + } + + if (_config.extra) { + ret = ret.concat(_config.extra); + } + + ret.push(target); + + return ret; +}; + +module.exports = builder; diff --git a/node_modules/ping/lib/builder/mac.js b/node_modules/ping/lib/builder/mac.js new file mode 100644 index 0000000..fdd122c --- /dev/null +++ b/node_modules/ping/lib/builder/mac.js @@ -0,0 +1,75 @@ +'use strict'; + +/** + * A builder builds command line arguments for ping in mac environment + * @module lib/builder/mac + */ +var util = require('util'); + +var builder = {}; + +/** + * Cross platform config representation + * @typedef {Object} PingConfig + * @property {boolean} numeric - Map IP address to hostname or not + * @property {number} timeout - Time duration for ping command to exit + * @property {number} min_reply - Exit after sending number of ECHO_REQUEST + * @property {string[]} extra - Optional options does not provided + */ + +var defaultConfig = { + numeric: true, + timeout: 2, + min_reply: 1, + extra: [], +}; + +/** + * Get the finalized array of command line arguments + * @param {string} target - hostname or ip address + * @param {PingConfig} [config] - Configuration object for cmd line argument + * @return {string[]} - Command line argument according to the configuration + */ +builder.getResult = function (target, config) { + var _config = config || {}; + + // Empty argument + var ret = []; + + // Make every key in config has been setup properly + var keys = ['numeric', 'timeout', 'min_reply', 'extra']; + keys.forEach(function (k) { + // Falsy value will be overrided without below checking + if (typeof(_config[k]) !== 'boolean') { + _config[k] = _config[k] || defaultConfig[k]; + } + }); + + if (_config.numeric) { + ret.push('-n'); + } + + if (_config.timeout) { + ret = ret.concat([ + '-t', + util.format('%d', _config.timeout), + ]); + } + + if (_config.min_reply) { + ret = ret.concat([ + '-c', + util.format('%d', _config.min_reply), + ]); + } + + if (_config.extra) { + ret = ret.concat(_config.extra); + } + + ret.push(target); + + return ret; +}; + +module.exports = builder; diff --git a/node_modules/ping/lib/builder/win.js b/node_modules/ping/lib/builder/win.js new file mode 100644 index 0000000..9b303ca --- /dev/null +++ b/node_modules/ping/lib/builder/win.js @@ -0,0 +1,78 @@ +'use strict'; + +/** + * A builder builds command line arguments for ping in window environment + * @module lib/builder/win + */ +var util = require('util'); + +var builder = {}; + +/** + * Cross platform config representation + * @typedef {Object} PingConfig + * @property {boolean} numeric - Map IP address to hostname or not + * @property {number} timeout - Time duration for ping command to exit + * @property {number} min_reply - Exit after sending number of ECHO_REQUEST + * @property {string[]} extra - Optional options does not provided + */ + +var defaultConfig = { + numeric: true, + timeout: 5, + min_reply: 1, + extra: [], +}; + +/** + * Get the finalized array of command line arguments + * @param {string} target - hostname or ip address + * @param {PingConfig} [config] - Configuration object for cmd line argument + * @return {string[]} - Command line argument according to the configuration + */ +builder.getResult = function (target, config) { + var _config = config || {}; + + // Empty argument + var ret = []; + + // Make every key in config has been setup properly + var keys = ['numeric', 'timeout', 'min_reply', 'extra']; + keys.forEach(function (k) { + // Falsy value will be overrided without below checking + if (typeof(_config[k]) !== 'boolean') { + _config[k] = _config[k] || defaultConfig[k]; + } + }); + + if (!_config.numeric) { + ret.push('-a'); + } + + if (_config.timeout) { + // refs #56: Unit problem + // Our timeout is in second while timeout in window is in milliseconds + // so we need to convert our units accordingly + ret = ret.concat([ + '-w', + util.format('%d', _config.timeout * 1000), + ]); + } + + if (_config.min_reply) { + ret = ret.concat([ + '-n', + util.format('%d', _config.min_reply), + ]); + } + + if (_config.extra) { + ret = ret.concat(_config.extra); + } + + ret.push(target); + + return ret; +}; + +module.exports = builder; diff --git a/node_modules/ping/lib/parser/base.js b/node_modules/ping/lib/parser/base.js new file mode 100644 index 0000000..2847331 --- /dev/null +++ b/node_modules/ping/lib/parser/base.js @@ -0,0 +1,181 @@ +'use strict'; + +/* eslint no-unused-vars: 0 */ + +var __ = require('underscore'); + +/** + * Parsed response + * @typedef {object} PingResponse + * @param {string} host - The input IP address or HOST + * @param {string} numeric_host - Target IP address + * @param {boolean} alive - True for existed host + * @param {string} output - Raw stdout from system ping + * @param {number} time - Time (float) in ms for first successful ping response + * @param {string} min - Minimum time for collection records + * @param {string} max - Maximum time for collection records + * @param {string} avg - Average time for collection records + * @param {string} stddev - Standard deviation time for collected records + */ + +/** + * @constructor + */ +function parser() { + // Initial state is 0 + this._state = 0; + + // Initial cache value + this._response = { + host: 'unknown', + alive: false, + output: 'unknown', + time: 'unknown', + min: 'unknown', + max: 'unknown', + avg: 'unknown', + stddev: 'unknown', + }; + + // Initial times storage for ping time + this._times = []; + + // Initial lines storage for ping output + this._lines = []; + + // strip string regexp + this._stripRegex = /[ ]*\r?\n?$/g; +} + +/** + * Enum for parser states + * @readonly + * @enum {number} + */ +parser.prototype.STATES = { + INIT: 0, + HEADER: 1, + BODY: 2, + FOOTER: 3, + END: 4, +}; + +/** + * Change state of this parser + * @param {number} state - parser.STATES + * @return {this} - This instance + */ +parser.prototype._changeState = function (state) { + var states = __.values(this.STATES); + if (states.indexOf(state) < 0) { + throw new Error('Unknown state'); + } + + this._state = state; + + return this; +}; + +/** + * Process output's header + * @param {string} line - A line from system ping + */ +parser.prototype._processHeader = function (line) { + throw new Error('Subclass should implement this method'); +}; + +/** + * Process output's body + * @param {string} line - A line from system ping + */ +parser.prototype._processBody = function (line) { + throw new Error('Subclass should implement this method'); +}; + +/** + * Process output's footer + * @param {string} line - A line from system ping + */ +parser.prototype._processFooter = function (line) { + throw new Error('Subclass should implement this method'); +}; + +/** + * Process a line from system ping + * @param {string} line - A line from system ping + * @return {this} - This instance + */ +parser.prototype.eat = function (line) { + var headerStates = [ + this.STATES.INIT, + this.STATES.HEADER, + ]; + + // Store lines + this._lines.push(line); + + // Strip all space \r\n at the end + var _line = line.replace(this._stripRegex, ''); + + if (_line.length === 0) { + // Do nothing if this is an empty line + } else if (headerStates.indexOf(this._state) >= 0) { + this._processHeader(_line); + } else if (this._state === this.STATES.BODY) { + this._processBody(_line); + } else if (this._state === this.STATES.FOOTER) { + this._processFooter(_line); + } else if (this._state === this.STATES.END) { + // Do nothing + } else { + throw new Error('Unknown state'); + } + + return this; +}; + +/** + * Get results after parsing certain lines from system ping + * @return {PingResponse} - Response from parsing ping output + */ +parser.prototype.getResult = function () { + var ret = __.extend({}, this._response); + + // Concat output + ret.output = this._lines.join('\n'); + + // Determine alive + ret.alive = this._times.length > 0; + + // Update time at first successful line + if (ret.alive) { + ret.time = this._response.time = this._times[0]; + } + + // Get stddev + if ( + ret.stddev === 'unknown' && ret.alive + ) { + var N = this._times.length; + + var variances = __.reduce(this._times, function (m, time) { + return m + Math.pow((time - ret.avg), 2); + }, 0) / N; + + ret.stddev = Math.round( + Math.sqrt(variances) * 1000 + ) / 1000; + } + + // Fix min, avg, max, stddev up to 3 decimal points + __.each(['min', 'avg', 'max', 'stddev'], function (key) { + var v = ret[key]; + if (__.isNumber(v)) { + ret[key] = v.toFixed(3); + } + }); + + return ret; +}; + +module.exports = parser; diff --git a/node_modules/ping/lib/parser/factory.js b/node_modules/ping/lib/parser/factory.js new file mode 100644 index 0000000..e220b36 --- /dev/null +++ b/node_modules/ping/lib/parser/factory.js @@ -0,0 +1,39 @@ +'use strict'; + +var util = require('util'); + +var builderFactory = require('../builder/factory'); +var WinParser = require('./win'); +var MacParser = require('./mac'); +var LinuxParser = require('./linux'); + +/** + * A factory creates a parser for parsing output from system ping + * @constructor + */ +function factory() {} + +/** + * Create a parser for a given platform + * @param {string} platform - Name of the platform + * @return {object} - Parser + * @throw if given platform is not supported + */ +factory.createParser = function (platform) { + if (!builderFactory.isPlatformSupport(platform)) { + throw new Error(util.format('Platform |%s| is not support', platform)); + } + + var ret = null; + if (builderFactory.isWindow(platform)) { + ret = new WinParser(); + } else if (builderFactory.isMacOS(platform)) { + ret = new MacParser(); + } else if (builderFactory.isLinux(platform)) { + ret = new LinuxParser(); + } + + return ret; +}; + +module.exports = factory; diff --git a/node_modules/ping/lib/parser/linux.js b/node_modules/ping/lib/parser/linux.js new file mode 100644 index 0000000..781d854 --- /dev/null +++ b/node_modules/ping/lib/parser/linux.js @@ -0,0 +1,48 @@ +'use strict'; + +var util = require('util'); +var base = require('./base'); +var MacParser = require('./mac'); + +/** + * @constructor + */ +function LinuxParser() { + base.call(this); +} + +util.inherits(LinuxParser, base); + +/** + * Process output's body + * @param {string} line - A line from system ping + */ +LinuxParser.prototype._processHeader = function (line) { + // Get host and numeric_host + var tokens = line.split(' '); + + this._response.host = tokens[1]; + this._response.numeric_host = tokens[2].slice(1, -1); + + this._changeState(this.STATES.BODY); +}; + +/** + * Process output's body + * @param {string} line - A line from system ping + */ +LinuxParser.prototype._processBody = function (line) { + // Reuse mac parser implementation + MacParser.prototype._processBody.call(this, line); +}; + +/** + * Process output's footer + * @param {string} line - A line from system ping + */ +LinuxParser.prototype._processFooter = function (line) { + // Reuse mac parser implementation + MacParser.prototype._processFooter.call(this, line); +}; + +module.exports = LinuxParser; diff --git a/node_modules/ping/lib/parser/mac.js b/node_modules/ping/lib/parser/mac.js new file mode 100644 index 0000000..9c10957 --- /dev/null +++ b/node_modules/ping/lib/parser/mac.js @@ -0,0 +1,77 @@ +'use strict'; + +var util = require('util'); +var __ = require('underscore'); + +var base = require('./base'); + +/** + * @constructor + */ +function MacParser() { + base.call(this); +} + +util.inherits(MacParser, base); + +/** + * Process output's header + * @param {string} line - A line from system ping + */ +MacParser.prototype._processHeader = function (line) { + // Get host and numeric_host + var tokens = line.split(' '); + + this._response.host = tokens[1]; + this._response.numeric_host = tokens[2].slice(1, -2); + + this._changeState(this.STATES.BODY); +}; + +/** + * Process output's body + * @param {string} line - A line from system ping + */ +MacParser.prototype._processBody = function (line) { + // XXX: Assume there is at least 3 '=' can be found + var count = (line.match(/=/g) || []).length; + if (count >= 3) { + var regExp = /([0-9\.]+)[ ]*ms/; + var match = regExp.exec(line); + this._times.push(parseFloat(match[1], 10)); + } + + // Change state if it see a '---' + if (line.indexOf('---') >= 0) { + this._changeState(this.STATES.FOOTER); + } +}; + +/** + * Process output's footer + * @param {string} line - A line from system ping + */ +MacParser.prototype._processFooter = function (line) { + // XXX: Assume number of keywords '/' more than 3 + var count = (line.match(/[\/]/g) || []).length; + if (count >= 3) { + var regExp = /([0-9\.]+)/g; + // XXX: Assume min avg max stddev + var m1 = regExp.exec(line); + var m2 = regExp.exec(line); + var m3 = regExp.exec(line); + var m4 = regExp.exec(line); + + if (__.all([m1, m2, m3, m4])) { + this._response.min = parseFloat(m1[1], 10); + this._response.avg = parseFloat(m2[1], 10); + this._response.max = parseFloat(m3[1], 10); + this._response.stddev = parseFloat(m4[1], 10); + this._changeState(this.STATES.END); + } + + this._changeState(this.STATES.END); + } +}; + +module.exports = MacParser; diff --git a/node_modules/ping/lib/parser/win.js b/node_modules/ping/lib/parser/win.js new file mode 100644 index 0000000..ba27b70 --- /dev/null +++ b/node_modules/ping/lib/parser/win.js @@ -0,0 +1,87 @@ +'use strict'; + +var util = require('util'); +var __ = require('underscore'); + +var base = require('./base'); + +/** + * @constructor + */ +function WinParser() { + base.call(this); + this._ipv4Regex = /^([0-9]{1,3}\.){3}[0-9]{1,3}$/; +} + +util.inherits(WinParser, base); + +/** + * Process output's header + * @param {string} line - A line from system ping + */ +WinParser.prototype._processHeader = function (line) { + // Get host and numeric_host + var tokens = line.split(' '); + + this._response.host = tokens[1]; + if (this._ipv4Regex.test(this._response.host)) { + this._response.numeric_host = tokens[1]; + } else { + this._response.numeric_host = tokens[2].slice(1, -1); + } + + this._changeState(this.STATES.BODY); +}; + +/** + * Process output's body + * @param {string} line - A line from system ping + */ +WinParser.prototype._processBody = function (line) { + var tokens = line.split(' '); + var kvps = __.filter(tokens, function (token) { + // Sometime it shows <1ms + return token.indexOf('=') >= 0 || token.indexOf('<') >= 0; + }); + + // kvps.length >= 3 means target is pingable + if (kvps.length >= 3) { + // XXX: Assume time will alaways get keyword ms for all language + var timeKVP = __.find(kvps, function (kvp) { + return kvp.indexOf('ms') >= 0; + }); + var regExp = /([0-9\.]+)/; + var match = regExp.exec(timeKVP); + + this._times.push(parseFloat(match[1], 10)); + } + + // Change state if it see a ':' at the end + if (line.slice(-1) === ':') { + this._changeState(this.STATES.FOOTER); + } +}; + +/** + * Process output's footer + * @param {string} line - A line from system ping + */ +WinParser.prototype._processFooter = function (line) { + // XXX: Assume there is a keyword ms + if (line.indexOf('ms') >= 0) { + // XXX: Assume the ordering is Min Max Avg + var regExp = /([0-9\.]+)/g; + var m1 = regExp.exec(line); + var m2 = regExp.exec(line); + var m3 = regExp.exec(line); + + if (__.all([m1, m2, m3])) { + this._response.min = parseFloat(m1[1], 10); + this._response.max = parseFloat(m2[1], 10); + this._response.avg = parseFloat(m3[1], 10); + this._changeState(this.STATES.END); + } + } +}; + +module.exports = WinParser; diff --git a/node_modules/ping/lib/ping-pcap.js b/node_modules/ping/lib/ping-pcap.js new file mode 100644 index 0000000..f4e7202 --- /dev/null +++ b/node_modules/ping/lib/ping-pcap.js @@ -0,0 +1,46 @@ +/* eslint-disable */ + +/** +* LICENSE MIT +* (C) Daniel Zelisko +* http://github.com/danielzzz/node-ping +* +* A poor man's ping for node.js +* It uses UDP_scanning (as node is not able to generate iCPM packets) +* http://en.wikipedia.org/wiki/Port_scanner#UDP_scanning +* it may not work correct for hosts that silently drop UDP traffic on their firewall +* you need at pcap version 0.1.9 or higher +* +*/ + +var sys = require("util"), +pcap = require('pcap'); + +var addr = process.argv[3] || 'localhost'; +setInterval(function() {probe(addr)}, 1000); + + +function probe(addr) { + sys.puts('sending a probe to ' + addr); + var dgram = require('dgram'); + var message = new Buffer("Some bytes"); + var client = dgram.createSocket("udp4"); + client.send(message, 0, message.length, 21111, addr); + client.close(); +} + +// create a pcap session +pcap_session = pcap.createSession(process.argv[2] || 'eth0', ""); + + +// listen for packets, decode them, and feed the simple printer +pcap_session.addListener('packet', function (raw_packet) { + var packet = pcap.decode.packet(raw_packet); + if (packet.link && packet.link.ip && packet.link.ip.saddr==addr) { + packet.link && packet.link.ip && sys.puts(packet.link.ip.saddr + " is alive"); + } +}); + +//-------- example ------------------------ + + diff --git a/node_modules/ping/lib/ping-promise.js b/node_modules/ping/lib/ping-promise.js new file mode 100644 index 0000000..f7f5023 --- /dev/null +++ b/node_modules/ping/lib/ping-promise.js @@ -0,0 +1,87 @@ +'use strict'; + +/** +* LICENSE MIT +* (C) Daniel Zelisko +* http://github.com/danielzzz/node-ping +* +* a simple wrapper for ping +* Now with support of not only english Windows. +* +*/ + +// System library +var util = require('util'); +var cp = require('child_process'); +var os = require('os'); + +// 3rd-party library +var Q = require('q'); +var __ = require('underscore'); + +// Our library +var builderFactory = require('./builder/factory'); +var parserFactory = require('./parser/factory'); + +/** + * Class::PromisePing + * + * @param {string} addr - Hostname or ip addres + * @param {PingConfig} config - Configuration for command ping + * @return {Promise} + */ +function probe(addr, config) { + // Do not reassign function argument + var _config = config || {}; + + // Convert callback base system command to promise base + var deferred = Q.defer(); + + // Spawn a ping process + var ping = null; + var platform = os.platform(); + var argumentBuilder = builderFactory.createBuilder(platform); + ping = cp.spawn( + builderFactory.getExecutablePath(platform), + argumentBuilder.getResult(addr, _config) + ); + + // Initial parser + var parser = parserFactory.createParser(platform); + + // Register events from system ping + ping.once('error', function () { + var err = new Error( + util.format( + 'ping.probe: %s. %s', + 'there was an error while executing the ping program. ', + 'Check the path or permissions...' + ) + ); + deferred.reject(err); + }); + + // Cache all lines from the system ping + var outstring = []; + ping.stdout.on('data', function (data) { + outstring.push(String(data)); + }); + + // Parse lines we have on closing system ping + ping.once('close', function () { + // Merge lines we have and split it by \n + var lines = outstring.join('').split('\n'); + + // Parse line one by one + __.each(lines, parser.eat, parser); + + // Get result + var ret = parser.getResult(); + + deferred.resolve(ret); + }); + + return deferred.promise; +} + +exports.probe = probe; diff --git a/node_modules/ping/lib/ping-sys.js b/node_modules/ping/lib/ping-sys.js new file mode 100644 index 0000000..20e5a6c --- /dev/null +++ b/node_modules/ping/lib/ping-sys.js @@ -0,0 +1,45 @@ +'use strict'; + +/** +* LICENSE MIT +* (C) Daniel Zelisko +* http://github.com/danielzzz/node-ping +* +* a simple wrapper for ping +* Now with support of not only english Windows. +* +*/ + +// Promise implementation +var ping = require('./ping-promise'); + +// TODO: +// 1. Port round trip time to this callback +// 2. However, it may breaks backward compatability +// 3. Need discussion +/** + * Callback after probing given host + * @callback probeCallback + * @param {boolean} isAlive - Whether target is alive or not + * @param {Object} error - Null if no error occurs + */ + +/** + * Class::Ping construtor + * + * @param {string} addr - Hostname or ip addres + * @param {probeCallback} cb - Callback + * @param {PingConfig} config - Configuration for command ping + */ +function probe(addr, cb, config) { + // Do not reassign function parameter + var _config = config || {}; + + return ping.probe(addr, _config).then(function (res) { + cb(res.alive, null); + }).catch(function (err) { + cb(null, err); + }).done(); +} + +exports.probe = probe; diff --git a/node_modules/ping/package.json b/node_modules/ping/package.json new file mode 100644 index 0000000..c4aa328 --- /dev/null +++ b/node_modules/ping/package.json @@ -0,0 +1,130 @@ +{ + "_from": "ping", + "_id": "ping@0.2.2", + "_inBundle": false, + "_integrity": "sha1-GA+3UIwdx0eThJvONcgHP5llvOI=", + "_location": "/ping", + "_phantomChildren": {}, + "_requested": { + "type": "tag", + "registry": true, + "raw": "ping", + "name": "ping", + "escapedName": "ping", + "rawSpec": "", + "saveSpec": null, + "fetchSpec": "latest" + }, + "_requiredBy": [ + "#USER", + "/" + ], + "_resolved": "https://registry.npmjs.org/ping/-/ping-0.2.2.tgz", + "_shasum": "180fb7508c1dc74793849bce35c8073f9965bce2", + "_spec": "ping", + "_where": "D:\\Programming\\Projects\\Down-Detector", + "author": { + "name": "danielzzz", + "email": "daniel@zelisko.net", + "url": "http://daniel.zelisko.net" + }, + "bugs": { + "url": "https://github.com/danielzzz/node-ping/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Mond Wan", + "email": "mondwan.1015@gmail.com" + }, + { + "name": "dougluce", + "email": "doug@tenousiperochhelical.con.com" + }, + { + "name": "weihua44" + }, + { + "name": "GermanBluefox" + }, + { + "name": "mabukar" + }, + { + "name": "microacup", + "email": "xiangmain@gmail.com" + }, + { + "name": "Andrew Fadeev" + }, + { + "name": "Joshua Pruitt", + "email": "firefly777@gmail.com" + }, + { + "name": "Stephan van Rooij", + "email": "stephan@svrooij.nl", + "url": "http://svrooij.nl" + }, + { + "name": "Krispin Schulz", + "email": "krispinone@googlemail.com", + "url": "http://kr1sp1n.io" + }, + { + "name": "Kathy Hill" + }, + { + "name": "mrMuppet" + }, + { + "name": "Adam Heath", + "email": "adam@adamheath.me", + "url": "http://www.adamheath.me" + }, + { + "name": "BlessJah", + "email": "blessjah@jacekowski.org" + }, + { + "name": "jritsema" + } + ], + "dependencies": { + "q": "1.x", + "underscore": "^1.8.3" + }, + "deprecated": false, + "description": "a simple wrapper for ping", + "devDependencies": { + "babel-eslint": "^7.0.0", + "chai": "2.3.0", + "eslint": "^3.8.1", + "eslint-config-airbnb": "^12.0.0", + "eslint-config-eslint": "^3.0.0", + "eslint-plugin-import": "^1.16.0", + "eslint-plugin-jsx-a11y": "^2.2.3", + "eslint-plugin-react": "^6.4.1", + "glob": "^7.1.1", + "grunt": "^1.0.1", + "grunt-mocha-test": "^0.13.2", + "gruntify-eslint": "^3.1.0", + "mocha": "2.5.3", + "sinon": "1.17.6" + }, + "engines": { + "node": ">=0.8" + }, + "homepage": "http://github.com/danielzzz/node-ping", + "license": "MIT", + "main": "index.js", + "name": "ping", + "repository": { + "type": "git", + "url": "git://github.com/danielzzz/node-ping.git" + }, + "scripts": { + "test": "grunt test" + }, + "version": "0.2.2" +} diff --git a/node_modules/ping/test/fixture/answer.json b/node_modules/ping/test/fixture/answer.json new file mode 100644 index 0000000..dc16367 --- /dev/null +++ b/node_modules/ping/test/fixture/answer.json @@ -0,0 +1,68 @@ +{ + "macos_en_sample1": { + "host": "google.com", + "numeric_host": "172.217.24.46", + "alive": true, + "output": "PING google.com (172.217.24.46): 56 data bytes\n64 bytes from 172.217.24.46: icmp_seq=0 ttl=54 time=5.371 ms\n64 bytes from 172.217.24.46: icmp_seq=1 ttl=54 time=4.269 ms\n64 bytes from 172.217.24.46: icmp_seq=2 ttl=54 time=4.970 ms\n64 bytes from 172.217.24.46: icmp_seq=3 ttl=54 time=5.228 ms\n\n--- google.com ping statistics ---\n4 packets transmitted, 4 packets received, 0.0% packet loss\nround-trip min/avg/max/stddev = 4.269/4.960/5.371/0.424 ms\n", + "time": 5.371, + "min": "4.269", + "max": "5.371", + "avg": "4.960", + "stddev": "0.424" + }, + "linux_en_sample1": { + "host": "localhost", + "numeric_host": "127.0.0.1", + "alive": true, + "output": "PING localhost (127.0.0.1) 56(84) bytes of data.\n64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.022 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.027 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms\n64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.030 ms\n\n--- localhost ping statistics ---\n4 packets transmitted, 4 received, 0% packet loss, time 2999ms\nrtt min/avg/max/mdev = 0.022/0.027/0.030/0.003 ms\n", + "time": 0.022, + "min": "0.022", + "max": "0.030", + "avg": "0.027", + "stddev": "0.003" + }, + "window_en_sample1": { + "host": "www.some-domain.com", + "numeric_host": "127.0.0.1", + "alive": true, + "output": "Pinging www.some-domain.com [127.0.0.1] with 32 bytes of\nReply from 127.0.0.1: bytes=32 time=564ms TTL=237\nReply from 127.0.0.1: bytes=32 time=555ms TTL=237\nReply from 127.0.0.1: bytes=32 time=554ms TTL=237\nReply from 127.0.0.1: bytes=32 time=548ms TTL=237\n\nPing statistics for 127.0.0.1:\n Packets: Sent = 4, Received = 4, Lost = 0 (0% loss)\n Approximate round trip times in milli-seconds:\n Minimum = 548ms, Maximum = 564ms, Average = 555ms\n", + "time": 564, + "min": "548.000", + "max": "564.000", + "avg": "555.000", + "stddev": "5.723" + }, + "window_zh_sample1": { + "host": "google.com", + "numeric_host": "216.58.203.14", + "alive": true, + "output": "Ping google.com [216.58.203.14] (使用 32 位元組的資料):\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n\n216.58.203.14 的 Ping 統計資料:\n 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),\n 大約的來回時間 (毫秒):\n 最小值 = 2ms,最大值 = 3ms,平均 = 2ms\n", + "time": 2, + "min": "2.000", + "max": "3.000", + "avg": "2.000", + "stddev": "0.707" + }, + "window_zh_sample2": { + "host": "google.com", + "numeric_host": "216.58.203.14", + "alive": true, + "output": "\nPing google.com [216.58.203.14] (使用 32 位元組的資料):\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54\n\n216.58.203.14 的 Ping 統計資料:\n 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),\n 大約的來回時間 (毫秒):\n 最小值 = 2ms,最大值 = 3ms,平均 = 2ms\n", + "time": 2, + "min": "2.000", + "max": "3.000", + "avg": "2.000", + "stddev": "0.707" + }, + "window_zh_sample3": { + "host": "127.0.0.1", + "numeric_host": "127.0.0.1", + "alive": true, + "output": "\nPing 127.0.0.1 (使用 32 位元組的資料):\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128\n\n127.0.0.1 的 Ping 統計資料:\n 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失),\n 大約的來回時間 (毫秒):\n 最小值 = 0ms,最大值 = 0ms,平均 = 0ms\n", + "time": 1, + "min": "0.000", + "max": "0.000", + "avg": "0.000", + "stddev": "1.000" + } +} \ No newline at end of file diff --git a/node_modules/ping/test/fixture/linux/.gitdirectory b/node_modules/ping/test/fixture/linux/.gitdirectory new file mode 100644 index 0000000..e69de29 diff --git a/node_modules/ping/test/fixture/linux/en/sample1.txt b/node_modules/ping/test/fixture/linux/en/sample1.txt new file mode 100644 index 0000000..70776c4 --- /dev/null +++ b/node_modules/ping/test/fixture/linux/en/sample1.txt @@ -0,0 +1,9 @@ +PING localhost (127.0.0.1) 56(84) bytes of data. +64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.022 ms +64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.027 ms +64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.029 ms +64 bytes from localhost (127.0.0.1): icmp_seq=4 ttl=64 time=0.030 ms + +--- localhost ping statistics --- +4 packets transmitted, 4 received, 0% packet loss, time 2999ms +rtt min/avg/max/mdev = 0.022/0.027/0.030/0.003 ms diff --git a/node_modules/ping/test/fixture/macos/.gitdirectory b/node_modules/ping/test/fixture/macos/.gitdirectory new file mode 100644 index 0000000..e69de29 diff --git a/node_modules/ping/test/fixture/macos/en/sample1.txt b/node_modules/ping/test/fixture/macos/en/sample1.txt new file mode 100644 index 0000000..0a8f8aa --- /dev/null +++ b/node_modules/ping/test/fixture/macos/en/sample1.txt @@ -0,0 +1,9 @@ +PING google.com (172.217.24.46): 56 data bytes +64 bytes from 172.217.24.46: icmp_seq=0 ttl=54 time=5.371 ms +64 bytes from 172.217.24.46: icmp_seq=1 ttl=54 time=4.269 ms +64 bytes from 172.217.24.46: icmp_seq=2 ttl=54 time=4.970 ms +64 bytes from 172.217.24.46: icmp_seq=3 ttl=54 time=5.228 ms + +--- google.com ping statistics --- +4 packets transmitted, 4 packets received, 0.0% packet loss +round-trip min/avg/max/stddev = 4.269/4.960/5.371/0.424 ms diff --git a/node_modules/ping/test/fixture/window/.gitdirectory b/node_modules/ping/test/fixture/window/.gitdirectory new file mode 100644 index 0000000..e69de29 diff --git a/node_modules/ping/test/fixture/window/en/sample1.txt b/node_modules/ping/test/fixture/window/en/sample1.txt new file mode 100644 index 0000000..a6eeb00 --- /dev/null +++ b/node_modules/ping/test/fixture/window/en/sample1.txt @@ -0,0 +1,10 @@ +Pinging www.some-domain.com [127.0.0.1] with 32 bytes of +Reply from 127.0.0.1: bytes=32 time=564ms TTL=237 +Reply from 127.0.0.1: bytes=32 time=555ms TTL=237 +Reply from 127.0.0.1: bytes=32 time=554ms TTL=237 +Reply from 127.0.0.1: bytes=32 time=548ms TTL=237 + +Ping statistics for 127.0.0.1: + Packets: Sent = 4, Received = 4, Lost = 0 (0% loss) + Approximate round trip times in milli-seconds: + Minimum = 548ms, Maximum = 564ms, Average = 555ms diff --git a/node_modules/ping/test/fixture/window/zh/sample1.txt b/node_modules/ping/test/fixture/window/zh/sample1.txt new file mode 100644 index 0000000..c408766 --- /dev/null +++ b/node_modules/ping/test/fixture/window/zh/sample1.txt @@ -0,0 +1,10 @@ +Ping google.com [216.58.203.14] (使用 32 位元組的資料): +回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54 +回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54 +回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54 +回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54 + +216.58.203.14 的 Ping 統計資料: + 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失), + 大約的來回時間 (毫秒): + 最小值 = 2ms,最大值 = 3ms,平均 = 2ms diff --git a/node_modules/ping/test/fixture/window/zh/sample2.txt b/node_modules/ping/test/fixture/window/zh/sample2.txt new file mode 100644 index 0000000..b2f0047 --- /dev/null +++ b/node_modules/ping/test/fixture/window/zh/sample2.txt @@ -0,0 +1,11 @@ + +Ping google.com [216.58.203.14] (使用 32 位元組的資料): +回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54 +回覆自 216.58.203.14: 位元組=32 時間=2ms TTL=54 +回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54 +回覆自 216.58.203.14: 位元組=32 時間=3ms TTL=54 + +216.58.203.14 的 Ping 統計資料: + 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失), + 大約的來回時間 (毫秒): + 最小值 = 2ms,最大值 = 3ms,平均 = 2ms diff --git a/node_modules/ping/test/fixture/window/zh/sample3.txt b/node_modules/ping/test/fixture/window/zh/sample3.txt new file mode 100644 index 0000000..bfdf9d0 --- /dev/null +++ b/node_modules/ping/test/fixture/window/zh/sample3.txt @@ -0,0 +1,11 @@ + +Ping 127.0.0.1 (使用 32 位元組的資料): +回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128 +回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128 +回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128 +回覆自 127.0.0.1: 位元組=32 時間<1ms TTL=128 + +127.0.0.1 的 Ping 統計資料: + 封包: 已傳送 = 4,已收到 = 4, 已遺失 = 0 (0% 遺失), + 大約的來回時間 (毫秒): + 最小值 = 0ms,最大值 = 0ms,平均 = 0ms diff --git a/node_modules/ping/test/load-fixture-path.js b/node_modules/ping/test/load-fixture-path.js new file mode 100644 index 0000000..a4ed5c9 --- /dev/null +++ b/node_modules/ping/test/load-fixture-path.js @@ -0,0 +1,61 @@ +'use strict'; + +var path = require('path'); +var glob = require('glob'); + +/** + * Check out linux platform + */ +function isLinux(p) { + var platforms = [ + 'aix', + 'linux', + ]; + + return platforms.indexOf(p) >= 0; +} + +/** + * Check out macos platform + */ +function isMacOS(p) { + var platforms = [ + 'darwin', + 'freebsd', + ]; + + return platforms.indexOf(p) >= 0; +} + +/** + * Check out window platform + */ +function isWindow(p) { + return p && p.match(/^win/) !== null; +} + +module.exports = function (platform) { + var dirname = null; + + if (isLinux(platform)) { + dirname = 'linux'; + } else if (isMacOS(platform)) { + dirname = 'macos'; + } else if (isWindow(platform)) { + dirname = 'window'; + } + + var currentDirectory = path.dirname(__filename); + + var targetDirectory = [currentDirectory, 'fixture']; + if (dirname) { + targetDirectory.push(dirname); + } + targetDirectory = targetDirectory.concat([ + '**', + '*.txt', + ]); + targetDirectory = path.posix.join.apply(path.posix, targetDirectory); + + return glob.sync(targetDirectory); +}; diff --git a/node_modules/ping/test/test-ping.js b/node_modules/ping/test/test-ping.js new file mode 100644 index 0000000..07e9c10 --- /dev/null +++ b/node_modules/ping/test/test-ping.js @@ -0,0 +1,187 @@ +'use strict'; +/* global describe it before after*/ +/* eslint no-unused-expressions: 0 */ + +var expect = require('chai').expect; +var sinon = require('sinon'); +var os = require('os'); +var cp = require('child_process'); +var q = require('q'); +var fs = require('fs'); +var path = require('path'); +var util = require('util'); +var events = require('events'); + +var loadFixturePath = require('./load-fixture-path'); +var ping = require('..'); + +// Some constants +var ANSWER = require('./fixture/answer'); +var PLATFORMS = [ + 'window', + 'darwin', + 'freebsd', + // 'aix', + 'linux', +]; +var PLATFORM_TO_EXTRA_ARGUMENTS = { + window: ['-n', '2'], + darwin: ['-c', '2'], + freebsd: ['-c', '2'], + linux: ['-c', '2'], +}; + +var pathToAnswerKey = function (p) { + var basename = path.posix.basename(p, '.txt'); + var dirname = path.posix.basename(path.posix.dirname(p)); + var osname = path.posix.basename( + path.posix.dirname(path.posix.dirname(p)) + ); + + return [osname, dirname, basename].join('_'); +}; + +var mockOutSpawn = function (fp) { + return function () { + var e = new events.EventEmitter(); + e.stdout = e; + + var s = fs.createReadStream(fp); + s.on('data', function (line) { + e.emit('data', line); + }); + s.on('close', function () { + e.emit('close', 0); + }); + + return e; + }; +}; + +var createTestCase = function (platform, pingExecution) { + var stubs = []; + + describe(util.format('On %s platform', platform), function () { + var fixturePaths = loadFixturePath(platform); + + before(function () { + stubs.push( + sinon.stub(os, 'platform', function () { return platform; }) + ); + }); + + after(function () { + stubs.forEach(function (stub) { + stub.restore(); + }); + }); + + describe('runs with default config', function () { + fixturePaths.forEach(function (fp) { + it( + util.format('Using |%s|', pathToAnswerKey(fp)), + function () { + return pingExecution(fp); + } + ); + }); + }); + + describe('runs with custom config', function () { + fixturePaths.forEach(function (fp) { + it( + util.format('Using |%s|', pathToAnswerKey(fp)), + function () { + return pingExecution(fp, { + timeout: 10, + extra: PLATFORM_TO_EXTRA_ARGUMENTS[platform], + }); + } + ); + }); + }); + + describe('runs with custom config with default gone', function () { + fixturePaths.forEach(function (fp) { + it( + util.format('Using |%s|', pathToAnswerKey(fp)), + function () { + return pingExecution(fp, { + timeout: false, + extra: PLATFORM_TO_EXTRA_ARGUMENTS[platform], + }); + } + ); + }); + }); + }); +}; + +describe('Ping in callback mode', function () { + var pingExecution = function (fp, args) { + var deferred = q.defer(); + + var stub = sinon.stub( + cp, + 'spawn', + mockOutSpawn(fp) + ); + + var cb = function (isAlive, err) { + if (err) { + deferred.reject(err); + } else { + deferred.resolve(isAlive); + } + }; + + if (args) { + ping.sys.probe('whatever', cb, args); + } else { + ping.sys.probe('whatever', cb); + } + + stub.restore(); + + return deferred.promise.then(function (data) { + var answerKey = pathToAnswerKey(fp); + var actualIsAlive = data; + var expectIsAlive = ANSWER[answerKey].alive; + expect(actualIsAlive).to.equal(expectIsAlive); + }); + }; + + PLATFORMS.forEach(function (platform) { + createTestCase(platform, pingExecution); + }); +}); + +describe('Ping in promise mode', function () { + var pingExecution = function (fp, args) { + var stub = sinon.stub( + cp, + 'spawn', + mockOutSpawn(fp) + ); + + var ret = null; + if (args) { + ret = ping.promise.probe('whatever', args); + } else { + ret = ping.promise.probe('whatever'); + } + + stub.restore(); + + return ret.then(function (data) { + var answerKey = pathToAnswerKey(fp); + var actualData = data; + var expectData = ANSWER[answerKey]; + expect(actualData).to.deep.equal(expectData); + }); + }; + + PLATFORMS.forEach(function (platform) { + createTestCase(platform, pingExecution); + }); +}); diff --git a/node_modules/q/CHANGES.md b/node_modules/q/CHANGES.md new file mode 100644 index 0000000..766fcdc --- /dev/null +++ b/node_modules/q/CHANGES.md @@ -0,0 +1,800 @@ + +## 1.5.1 + + - Q.any now annotates its error message to clarify that Q.any was involved and + includes only the last error emitted. (Ivan Etchart) + - Avoid domain.dispose during tests in preparation for Node.js 9. (Anna + Henningsen) + +## 1.5.0 + + - Q.any gives an error message from the last rejected promise + - Throw if callback supplied to "finally" is invalid (@grahamrhay) + - Long stack trace improvements, can now construct long stack traces + across rethrows. + +## 1.4.1 + + - Address an issue that prevented Q from being used as a `