text:
package com.malin.learnfragment.reconstruction;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Toast;

import com.malin.learnfragment.R;
import com.orhanobut.logger.Logger;

/**
 * 类描述:
 * 创建人:lin.ma@renren-inc.com
 * 创建时间:16-1-28
 * 备注:{@link } Thanks for  ,Her code is very good ! I made reference to his code,It saves me a lot of time!
 * 修改人:
 * 修改时间:
 * 修改备注:
 */
public class FragmentSix extends Fragment implements View.OnClickListener {
    private static final String TAG = FragmentSix.class.getSimpleName() + "-->";
    private Button mButton;

    /**
     * 设置按钮点击的回调
     */
    public interface ClickEventInterFace{
        void click(View v);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment_six_layout,null);

        initView(rootView);
        bindListener();
        return rootView;
    }

    private void initView(View rootView) {

        mButton = (Button) rootView.findViewById(R.id.btn_fragment_six);

    }
    private void bindListener() {
        mButton.setOnClickListener(this);

    }

    /**
     * onClick中首先判断了当前绑定的Activity是否实现了该接口,如果实现了则调用。
     * @param v
     */
    @Override
    public void onClick(View v) {
        if (getActivity() instanceof ClickEventInterFace){
            ((ClickEventInterFace) getActivity()).click(v);
            Toast.makeText(getActivity(), "Activity实现了该接口", Toast.LENGTH_SHORT).show();
        }else{
            Toast.makeText(getActivity(), "Activity meiyou 实现了该接口", Toast.LENGTH_SHORT).show();
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Logger.d(TAG + "onDestroyView");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Logger.d(TAG + "onDestroy");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Logger.d(TAG + "onDetach");
    }
}


text:
Profile

Eduardo Batista

Weekly average sales $ 8,250

Monthly average sales $ 32,000

            Sales commodity

Beverages

Condiments

Confections

Diary Products

Grains/Cereals

Meat/Poultry

Produce

Seafood

John Doe 07:56

Monday meeting

Hi Tom, Since Monday I'll be out of office, I'm rescheduling the meeting for Tuesday.

Sarah Connor 08:22

Regarding org chart changes

Tom, I checked the new org chart last night and I have some reservations about it...

Jane Parker 10:14

Your Costume is ready

Hi mr. Sawyer, I'm sorry for the delay, your Halloween costume is ready. The bears...

Joe Harper 10:14

I'm sorry, Tom

Hi Tom, my aunt comes for a visit this Saturday, so I can't come back to St. Pete...

Becky Thatcher 10:14

Out tonight?

Honey, wanna go out tonight to grab some chicken? My weekly vouchers for cooking...

TabStrip

            Home
            Mail

redpajama_set_name: RedPajamaGithub


text:
module.exports = function(RED) {
    "use strict";
    const util = require('util');
    const fs = require('fs');
    const crypto = require('crypto');
    const validator = require("validator");
    const dns = require('dns');
    const spawn = require('child_process').spawn;

    function TestSSLScan(n) {
        RED.nodes.createNode(this,n);
        let scantarget      = n.host;
        let opensslpath     = n.opensslpath || '/usr/bin/openssl';
        let cabundlespath   = n.cabundlespath || '/etc/ssl';

        let node = this;

        this.on("input",function(msg) {
            let host            = scantarget || msg.host;
            let openssl         = opensslpath || msg.opensslpath;
            let capath          = cabundlespath || msg.cabundlespath;
            let scanID          = msg._msgid;
            let env             = Object.create( process.env );

            // setting openssl path
            if (openssl != undefined && openssl != "") {
                node.log(`[testssl][${scanID}] - using openssl executable: ${openssl}`);
                openssl = '--openssl=' + openssl;
            }

            // setting ca-bundles path
            if (capath != undefined && capath != "") {
                node.log(`[testssl][${scanID}] - using ca bundles path: ${capath}`);
                env.CA_BUNDLES_PATH = capath;
            }

            // checking host and port data provided
            if (host === undefined || host === "") {
                node.status({fill:"red",shape:"dot",text:'address missing'});
                return;
            }
            let tmpHost = '';
            let tmpPort = 443;
            let tmp1 = host.match(/^[A-Za-z0-9\x2E\x2D]*$/);        // check for host only
            let tmp2 = host.match(/^([^\x3A]*)\x3A([0-9]{1,5})$/);  // check for host + port
            if (tmp1 instanceof Array && tmp1.length === 1)
            {
                tmpHost = tmp1[0];
            }
            else if (tmp2 instanceof Array && tmp2.length === 3)
            {
                tmpHost = tmp2[1];
                tmpPort = parseInt(tmp2[2]);
            }
            else
            {
                node.status({fill:"red",shape:"dot",text:"invalid data given"});
                msg.payload = "you provided invalid data";
                node.send(msg);
                return;
            }

            // checking port
            if (tmpPort < 1 || tmpPort > 65535)
            {
                node.status({fill:"red",shape:"dot",text:"not a valid port"});
                msg.payload = "this is not a valid port";
                node.send(msg);
                return;
            }

            GetMyTarget(tmpHost, function(IPsToScan){
                if (typeof IPsToScan === "string") {
                    node.status({fill:"red",shape:"dot",text:IPsToScan});
                    msg.payload = IPsToScan;
                    node.send(msg);
                    return;
                }

                node.status({fill:"green",shape:"dot",text:"scanning " + tmpHost + " on port " + tmpPort});
                msg.payload = "scanning... " + IPsToScan.join() + ' on port ' + tmpPort;
                node.send(msg);
                node.log(`[testssl][${scanID}] - scanning ${tmpHost} via ${IPsToScan.join()} on port ${tmpPort}`);

                const timeBefore = new Date();

                IPsToScan.forEach((singleAddrToScan, index, arr) => {

                    let output = "";
                    let error = "";
                    let timeout = false;
                    const hash = crypto.createHash('sha256').update(`${scanID}${tmpHost}${tmpPort}${index}`).digest('hex');
                    const jsonfile = `/tmp/json${hash}`;
                    const htmlfile = `/tmp/html${hash}`;
                    const csvfile  = `/tmp/csv${hash}`;

                    let run = spawn('./testssl.sh',
                      [
                        openssl,
                        '--protocols',
                        '--grease',
                        '--headers',
                        '--vulnerable',
                        '--cipher-per-proto',
                        '--fs',
                        '--rc4',
                        '--nodns=none',
                        '--phone-out',
                        '--mapping=rfc',
                        '--jsonfile',
                        jsonfile,
                        '--htmlfile',
                        htmlfile,
                        '--csvfile',
                        csvfile,
                        '--warnings=off',
                        '--ip',
                        singleAddrToScan,
                        tmpHost + ':' + tmpPort
                      ],
                      {
                          cwd: __dirname,
                          env: env
                      }
                    );

                    // timeout for scan of 5 minutes
                    timeout = setTimeout(function(){
                        if (run != null) {
                            node.log(`[testssl][${scanID}][${index}] - timeout of scan`);
                            node.status({
                                fill:"red",
                                shape:"dot",
                                text:"timeout during scan"
                            });
                            timeout = true;
                            run.kill();
                            return;
                        }
                    }, 300000);

                    // interval to inform user of ongoing activity
                    let interval = setInterval(() => {
                        if (run != null) {
                            msg.payload = `scan is still running (${getSecondsBetweenDates(timeBefore)} seconds) for ${singleAddrToScan}:${tmpPort}`;
                            node.send(msg);
                        }
                    }, 60000);

                    run.stdout.on('data', (data) => {
                        output+=data.toString();
                    });

                    run.stderr.on('data', (data) => {
                        error+=data.toString();
                    });

                    run.on('close', () => {
                        node.log(`[testssl][${scanID}][${index}] - scan finished for ${singleAddrToScan}:${tmpPort}`);
                        run = null;
                        clearTimeout(timeout);
                        clearInterval(interval);
                        if (error != "") {
                            node.status({fill:"red",shape:"dot",text:"error during scan"});
                            msg.payload = error.toString().trim().replace(/\[[^m]*m/g,'');
                            node.send(msg);
                        }
                        else {
                            const timeAfter = new Date();
                            const fileContent = {};
                            try {
                                fileContent.jsonfile = fs.readFileSync(jsonfile).toString();
                                fs.unlinkSync(jsonfile);
                                fileContent.htmlfile = fs.readFileSync(htmlfile).toString();
                                fs.unlinkSync(htmlfile);
                                fileContent.csvfile = fs.readFileSync(csvfile).toString();
                                fs.unlinkSync(csvfile);
                            }
                            catch (e) {
                                node.error(`[testssl][${scanID}][${index}] - ${e && e.message}`);
                            }
                            let payload = {
                                text: output,
                                html: fileContent.htmlfile,
                                json: fileContent.jsonfile,
                                csv: fileContent.csvfile,
                                timeout: timeout,
                                host: singleAddrToScan,
                                duration: getSecondsBetweenDates(timeBefore, timeAfter),
                                start: formatDate(timeBefore),
                                end: formatDate(timeAfter)
                            }
                            msg.payload = payload;
                            node.status({});
                            node.send(msg);
                        }
                    });
                });
            });
        });
    }

    RED.nodes.registerType("testssl-node",TestSSLScan);

    const GetMyTarget = (tmpHost, cb) => {
        let IPsToScan    = [];
        if (validator.isIP(tmpHost, '4') === true)
        {
            IPsToScan.push(tmpHost);
            cb(IPsToScan);
        }
        else if (validator.isFQDN(tmpHost) === true)
        {
            dns.resolve(tmpHost, (err, addresses) => {
                if (err) {
                    cb("Error resolving host: " + err.message);
                    return;
                }
                for (var i=0; i < addresses.length; i++) {
                    IPsToScan.push(addresses[i]);
                }
                cb(IPsToScan);
            });
        }
        else
        {
            cb("this is not a valid host");
        }
    }

    const getSecondsBetweenDates = (startDate, endDate) => {
        return Math.round( ( (endDate || new Date()) - startDate) / 1000);
    }

    const formatDate = (date) => {
        const now = date || (new Date());
        let MM = (now.getMonth() + 1);
            if (MM < 10) { MM = '0' + MM; }
        let DD = now.getDate();
            if (DD < 10) { DD = '0' + DD; }
        let H = now.getHours();
            if (H < 10) { H = '0' + H; }
        let M = now.getMinutes();
            if (M < 10) { M = '0' + M; }
        let S = now.getSeconds();
            if (S < 10) { S = '0' + S; }
        return `${now.getFullYear()}/${MM}/${DD} - ${H}:${M}:${S}`
    }
}