working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,980 snippets matching: wol

    public by tomsim  2436  16  5  0

    Send UDP WOL Magic Package

    C program to send UDP magic package to wake on lan
    /* Compile on Windows:
    cl /nologo /W3 /O2 /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_X86_" /link wsock32.lib wol.c
    Compile on linux:
    gcc wol.c -o wol
    
    Change the subnet on line 161 to match your network (sorry!)
    Must configure nic to accept magic package and setup power profile to allow
    wake on lan from nic.  Not for WiFi.
    */
    #ifdef _WIN32
    #define WIN32_LEAN_AND_MEAN
    #include <winsock2.h>
    #else
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <netdb.h>
    #include <arpa/inet.h>
    #endif
    
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <stdarg.h>
    #include <string.h>
    
    #ifdef _WIN32
    #define ERR_RETURN( x, e) if (x == SOCKET_ERROR) { checkError( e); return(0); }
    #else
    #define ERR_RETURN( x, e) if (x < 0) { checkError( e); return(0); }
    #define SOCKET int
    #endif
    
    static int checkError( char *szMsg)
    {
    #ifdef _WIN32
    	int err = WSAGetLastError();
    	if ((err == WSAEINTR) || (err == WSAEWOULDBLOCK) || (err == WSAEINPROGRESS))
    	{
    		printf( "Warning error=%08.8x\n", errno);
    		return 1;
    	}
    	else
    	{
    		printf("Error %d: %s\n", err, szMsg);
    		WSACleanup();
    		return 0;
    	}
    #else
    	perror(szMsg);
    	if ((errno == EINTR) || (errno = EWOULDBLOCK) || (errno == EINPROGRESS))
    		return 1;
    	else
    		return 0;
    #endif
    }
    #ifdef _WIN32
    /*--------------------------------------------------------
      Window socket startup
      --------------------------------------------------------*/
    int socketStartWin32(void)
    {
    	WSADATA wsaData;
    	if (WSAStartup(0x202,&wsaData) == SOCKET_ERROR)
    	{
    		printf("WSAStartup failed with error %d\n",WSAGetLastError());
    		WSACleanup();
    		return -1;
    	}
    	return 0;
    }
    void socketEndWin32(void)
    {
       WSACleanup();
    }
    #endif
    
    /* Magic package format:
    	06 x 255 or (0xff)
    	16 x MAC Address of target PC
    
    */ 
    int main(int argc, char **argv)
    {
    	int i;
    	unsigned char tosend[102];
    	unsigned char mac[6];
    
    	if ((argc < 2) || (strlen(argv[1]) < 17))
    	{
    		printf("Usage wol <mac address aa:bb:cc:dd:ee:ff>\n");
    		exit(0);
    	}
    
    	/** store mac address **/
    	for (i=0; i < sizeof(mac); i++)
    	{
    		char *cp = &argv[1][i*3];
    		mac[i] = 0x00;
    		sscanf(cp,"%2X", (unsigned int *) &mac[i]);
    	}
    	if (argc > 2)	// validate before sent
    	{
    		int ecn = 0;
    		printf( "Send magic package to ");
    		for (i=0; i < sizeof(mac); i++)
    		{
    			if (i) printf(":");
    			printf( "%.2X", mac[i]);
    			if (!mac[i]) ecn++;
    		}
    		printf("\n");
    		if (ecn)
    		{
    			printf("Invalid mac address\n");
    			exit(0);
    		}
    	}
    
    
    	/** first 6 bytes of 255 **/
    	for( i = 0; i < 6; i++) {
    		tosend[i] = 0xFF;
    	}
    	/** append it 16 times to packet **/
    	for( i = 1; i <= 16; i++)
    	{
    		memcpy(&tosend[i * 6], mac, 6 * sizeof(unsigned char));
    	}
    
    #ifdef _WIN32
    	if (socketStartWin32())
    		exit(-1);
    #endif
    	if (1)
    	{
    		int udpSocket;
    		struct sockaddr_in udpClient, udpServer;
    		int broadcast = 1;
    		int rv;
    
    		udpSocket = socket(AF_INET, SOCK_DGRAM, 0);
    
    		/** you need to set this so you can broadcast **/
    		if (setsockopt(udpSocket, SOL_SOCKET, SO_BROADCAST, (char *) &broadcast, sizeof broadcast))
    		{
    			checkError("setsockopt (SO_BROADCAST)");
    			exit(1);
    		}
    		udpClient.sin_family = AF_INET;
    		udpClient.sin_addr.s_addr = INADDR_ANY;
    		udpClient.sin_port = 0;
    
    		bind(udpSocket, (struct sockaddr*)&udpClient, sizeof(udpClient));
    
    		/** …make the packet as shown above **/
    
    		/** set server end point (the broadcast addres)**/
    		udpServer.sin_family = AF_INET;
    		udpServer.sin_addr.s_addr = inet_addr("192.168.1.255");
    		udpServer.sin_port = htons(9);
    
    		/** send the packet **/
    		rv = sendto(udpSocket, tosend, sizeof(unsigned char) * sizeof(tosend), 0, (struct sockaddr*)&udpServer, sizeof(udpServer));
    		if (argc > 2) printf( "Sent %d bytes\n", rv);
    	}
    
    #ifdef _WIN32
    	socketEndWin32();
    #endif
    	return 0;
    }
    
                                        

    public by wolke  2811  5  7  3

    Image import width TypoScript

    IMG_RESOURCE or DAM
    // Example for cObject IMG_RESOURCE
    10 = IMAGE
    10 {
    	file {
    		import.listNum = 0
    		import = uploads/pics/
    		import.field = image
    		}
    	}
    }
    
    // Example for DAM
    10 = IMAGE
    10 {
    	file {
    		import.listNum = 0
    		import.cObject = USER
    		import.cObject {
          userFunc = tx_dam_tsfe->fetchFileList
          refField = tx_damttcontent_files
    			refTable = tt_content
    		}
    	}
    }

    public by wolke  2961  3  6  1

    page autoreload via TypoScript for edit by backenduser

    Example for reoald the page all 60 sec. if field subtitle empty
    page {
      headerData.1911 = LOAD_REGISTER
    	headerData.1911 {
        refresh {
          field = subtitle
          ifEmpty = 1
          stdWrap.wrap = | * 60
          prioriCalc = intval
    		}
    	}
    	headerData.2000 = HMENU
    	headerData.2000 {
    		special = browse
    		special.items = next
    		1 = TMENU
    		1.NO = 1
    		1.NO {
          doNotShowLink = 1
          allStdWrap.typolink.parameter.field = uid
          allStdWrap.typolink.returnLast = url
        }
    		stdWrap {
          ifEmpty {
            typolink {
              returnLast = url
              parameter.field = pid
            }
          }
          insertData = 1
          wrap = <meta http-equiv="refresh" content="{register:refresh}; URL={$config.baseURL}|">
    		}
    	}
    }            

    public by wolke  2988  2  6  0

    Show pageID with title

    Settings for User TSconfig
    options.pageTree.showPageIdWithTitle = 1

    public by wolke  1965  1  6  1

    html-Image like scaling fullsize background-image

    /* http://css-tricks.com/perfect-full-page-background-image/
    Works in:
        Any version of good browsers: Safari / Chrome / Opera / Firefox
        IE 6: Borked - but probably fixable if you use some kind of fixed positioning shim
        IE 7/8: Mostly works, doesn't center at small sizes but fills screen fine
        IE 9: Works
    */
    
    img.body-bg-img {
    	/* Set rules to fill background */
    	min-height: 100%;
    	min-width: 1024px;
    
    	/* Set up proportionate scaling */
    	width: 100%;
    	height: auto;
    
    	/* Set up positioning */
    	position: fixed;
    	top: 0;
    	left: 0;
    }
    
    /* Specific to this particular image */
    @media screen and (max-width: 1024px) { 
    	img.body-bg-img {
    		left: 50%;
    		margin-left: -512px;   /* 50% */
    	}
    }
    
    

    public by wolke  1927  0  6  0

    Images that are inherited to the subordinate pages that are integrated via side property

    Images are inherited until they are overwritten
    # Example for TYPO3 6.x
    page.1 = IMG_RESOURCE
    page.1 {
    	file {
    		treatIdAsReference = 1
    		import.data = levelmedia:-1, slide
    		import.listNum = 0
    	}
    	stdWrap.required = 1
    	stdWrap.wrap (
    		<img src="|" class="body-bg-img hidden-xs" />
    	)
    }

    public by wolke  1797  1  6  0

    Different body tag via page-layout

    Different body tag via page-layout
    page = PAGE
    page {
    	bodyTagCObject = CASE
    	bodyTagCObject {
    		key.field = layout
    		key.ifEmpty.data = levelfield:-1, layout, slide
    			default = TEXT
    			default.field = uid
    			default.wrap = <body id="uid|" class="default">
    			0 < .default
    			1 < .default
    			1.field = uid
    			1.wrap = <body id="uid|" class="layout-1">
    			2 < .default
    			2.field = uid
    			2.wrap = <body id="uid|" class="layout-2">
    			3 < .default
    			3.field = uid
    			3.wrap = <body id="uid|" class="layout-3">
    	}
    }
    
    

    public by Geometry  861  0  4  0

    PelzGood: Pelz-Good algorithm for computing lower-tail areas of the Kolmogorov-Smirnov distribution.

    Pelz-Good algorithm for computing lower-tail areas of the Kolmogorov-Smirnov distribution. As stated in Simard's paper, Pelz and Good (1976) generalized Kolmogorov's approximation to an asymptotic series in 1/sqrt(n). References: Wolfgang Pelz and I. J. Good, "Approximating the Lower Tail-Areas of the Kolmogorov-Smirnov One-Sample
    /// <summary>
    ///   Pelz-Good algorithm for computing lower-tail areas
    ///   of the Kolmogorov-Smirnov distribution.
    /// </summary>
    /// 
    /// <remarks>
    /// <para>
    ///   As stated in Simard's paper, Pelz and Good (1976) generalized Kolmogorov's
    ///   approximation to an asymptotic series in 1/sqrt(n). </para>
    /// <para>
    ///   References: Wolfgang Pelz and I. J. Good, "Approximating the Lower Tail-Areas of
    ///   the Kolmogorov-Smirnov One-Sample Statistic", Journal of the Royal 
    ///   Statistical Society, Series B. Vol. 38, No. 2 (1976), pp. 152-156</para> 
    /// </remarks>
    /// 
    public static double PelzGood(double n, double x)
    {
        const int maxTerms = 20;
        const double eps = 1.0e-10;
    
        const double PI2 = Math.PI * Math.PI;
        const double PI4 = PI2 * PI2;
    
        double sqrtN = Math.Sqrt(n);
    
        double z = sqrtN * x;
        double z2 = z * z;
        double z3 = z2 * z;
        double z4 = z2 * z2;
        double z6 = z4 * z2;
        double z7 = z4 * z3;
        double z8 = z4 * z4;
        double z10 = z8 * z2;
    
        double pz = -PI2 / (2 * z2);
        double term;
    
    
        double k0 = 0; // Evaluate K0(z)
        for (int k = 0; k <= maxTerms; k++)
        {
            double h = (k + 0.5);
            k0 += term = Math.Exp(h * h * pz);
            if (term <= eps * k0) break;
        }
    
    
        double k1 = 0; // Evaluate K1(z)
        for (int k = 0; k <= maxTerms; k++)
        {
            double hh = (k + 0.5) * (k + 0.5);
            k1 += term = (PI2 * hh - z2) * Math.Exp(hh * pz);
            if (Math.Abs(term) <= eps * Math.Abs(k1)) break;
        }
    
    
        double k2a = 0; // Evaluate 1st part of K2(z)
        for (int k = 0; k <= maxTerms; k++)
        {
            double hh = (k + 0.5) * (k + 0.5);
            k2a += term = (6 * z6 + 2 * z4
                        + PI2 * (2 * z4 - 5 * z2) * hh
                        + PI4 * (1 - 2 * z2) * hh * hh) * Math.Exp(hh * pz);
            if (Math.Abs(term) <= eps * Math.Abs(k2a)) break;
        }
    
        double k2b = 0; // Evaluate 2nd part of K2(z)
        for (int k = 1; k <= maxTerms; k++)
        {
            double kk = k * k;
            k2b += term = PI2 * kk * Math.Exp(kk * pz);
            if (term <= eps * k2b) break;
        }
    
    
        double k3a = 0; // Evaluate 1st part of K3(z)
        for (int k = 0; k <= maxTerms; k++)
        {
            double hh = (k + 0.5) * (k + 0.5);
            k3a += term = (-30 * z6 - 90 * z8
                + PI2 * (135 * z4 - 96 * z6) * hh
                + PI4 * (212 * z4 - 60 * z2) * hh * hh
                + PI2 * PI4 * hh * hh * hh * (5 - 30 * z2)) * Math.Exp(hh * pz);
            if (Math.Abs(term) <= eps * Math.Abs(k3a)) break;
        }
    
        double k3b = 0; // Evaluate 2nd part of K3(z)
        for (int k = 1; k <= maxTerms; k++)
        {
            double kk = k * k;
            k3b += term = (3 * PI2 * kk * z2 - PI4 * kk * kk) * Math.Exp(kk * pz);
            if (Math.Abs(term) <= eps * Math.Abs(k3b)) break;
        }
    
    
        // Evaluate the P[sqrt(N) * Dn <= z | H0]
        double sum = k0 * (Constants.Sqrt2PI / z)
                   + k1 * (Constants.SqrtHalfPI / (sqrtN * 3.0 * z4))
                   + k2a * (Constants.SqrtHalfPI / (n * 36.0 * z7))
                   - k2b * (Constants.SqrtHalfPI / (n * 18.0 * z3))
                   + k3a * (Constants.SqrtHalfPI / (n * sqrtN * 3240.0 * z10))
                   + k3b * (Constants.SqrtHalfPI / (n * sqrtN * 108.0 * z6));
    
        return sum;
    }

    public by msdn  708  1  6  0

    PBKDF2: A static publicly exposed version of GetDerivedKeyBytes_PBKDF2_HMACSHA512 which matches the exact specification in Rfc2898DeriveBytes PBKDF2 using HMACSHA512

    A static publicly exposed version of GetDerivedKeyBytes_PBKDF2_HMACSHA512 which matches the exact specification in Rfc2898DeriveBytes PBKDF2 using HMACSHA512 Password passed as a Byte Array Salt passed as a Byte Array Iterations to perform the underlying PRF over Length of Bytes to return, an AES 256 key wold require 32 Bytes Derived Key i
    using System;
    using System.Linq;
    using System.Text;
    using System.Security.Cryptography;
    
    /// <summary>
    /// A static publicly exposed version of GetDerivedKeyBytes_PBKDF2_HMACSHA512 which matches the exact specification in Rfc2898DeriveBytes PBKDF2 using HMACSHA512
    /// </summary>
    /// <param name="P">Password passed as a Byte Array</param>
    /// <param name="S">Salt passed as a Byte Array</param>
    /// <param name="c">Iterations to perform the underlying PRF over</param>
    /// <param name="dkLen">Length of Bytes to return, an AES 256 key wold require 32 Bytes</param>
    /// <returns>Derived Key in Byte Array form ready for use by chosen encryption function</returns>
    public static Byte[] PBKDF2(Byte[] P, Byte[] S, Int32 c, Int32 dkLen)
    {
        Rfc2898DeriveBytes rfcObj = new Rfc2898DeriveBytes(P, S, c);
        return rfcObj.GetBytes(dkLen);
    }

    external by fikovnik  80  3  1  0

    Hacked MAAS ether_wake.template to allow to power on / off over WOL in the case the cluster controller has multiple interfaces

    Hacked MAAS ether_wake.template to allow to power on / off over WOL in the case the cluster controller has multiple interfaces: ether_wake.template
    # -*- mode: shell-script -*-
    #
    # Control node power through WOL, via `wakeonlan` or `etherwake`.
    #
    
    mac_address={{mac_address}}
    power_change={{power_change}}
    ip_address={{node_ip_address}}
    
    #if [ -n "${ip_address}" ]
    #then
    #    iface="$( ip route show to match "{{ip_address}}" | sed -n '/^default/! s/^.* dev \([^ ]*\).*$/\1/p' )"
    #    local_broadcast="$( ip addr show dev "${iface}" | sed -n '/^[[:space:]]*inet/ s/^.* brd \([^ ]*\) .*$/\1/p' )"
    #fi
    
    echo "${power_change} ${ip_address} ${mac_address}" >> /tmp/power 
    if [ "${power_change}" != 'on' ]
    then
        #echo "There is no way to power down a node through etherwake." >&2
        #exit 1
        if [ -n "${ip_address}" ]
        then
            #ssh -vv -i /etc/maas/stack-access-key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@${ip_address} -C "echo 'sleep 2 && sudo /sbin/poweroff -f' | at now" >> /tmp/power 2>&1
            ssh -i /etc/maas/stack-access-key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no ubuntu@${ip_address} -C "echo 'sleep 2 && sudo /sbin/poweroff -f' | at now"
        else
           echo "Unable to power down a node using etherwake without ip address." >&2
           exit 1
        fi
    elif [ -x /usr/bin/wakeonlan ]
    then
        /usr/bin/wakeonlan -i "192.168.0.255" $mac_address
        #if [ -n "${local_broadcast}" ]
        #then
        #    /usr/bin/wakeonlan -i "${local_broadcast}" $mac_address
        #else
        #    /usr/bin/wakeonlan $mac_address
        #fi
    elif [ -x /usr/sbin/etherwake ]
    then
        if [ -n "${iface}" ]
        then
            /usr/sbin/etherwake -i "${iface}" $mac_address
        else
            /usr/sbin/etherwake $mac_address
        fi
    else
        echo "No wakeonlan or etherwake program found." >&2
    fi
    
    exit 0
    
    
    • Public Snippets
    • Channels Snippets