Skip to content

Instantly share code, notes, and snippets.

@jsimpsoncd
jsimpsoncd / extensions.conf
Created December 9, 2020 18:25
extensions.conf for "Why do I need a home phone" demos
[from-internal]
;The letter X or x represents a single digit from 0 to 9.
;The letter Z or z represents any digit from 1 to 9.
;The letter N or n represents a single digit from 2 to 9.
; These are our typical "call a phone number" rules
exten => _NXXNXXXXXX,1,Verbose(2, Dialing out ${EXTEN})
exten => _NXXNXXXXXX,n, Dial(SIP/${EXTEN}@voipms)
exten => _NXXNXXXXXX,n,Hangup()
exten => 1NXXNXXXXXX,1,Verbose(2, Dialing out ${EXTEN})
exten => 1NXXNXXXXXX,n, Dial(SIP/${EXTEN}@voipms)
use strict;
use warnings;
use POE qw(Component::IRC);
# Load words.
open my $in, "<:encoding(utf8)", "words.txt" or die "words.txt: $!";
my @lines = <$in>;
close $in;
chomp @lines;
@jsimpsoncd
jsimpsoncd / poweron.php
Last active April 17, 2018 10:32
page to control power state using power.expect
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<?php
$user = "user";
$password = "pass";
if (array_key_exists("port", $_GET) and is_numeric($_GET["port"] )) {
@jsimpsoncd
jsimpsoncd / power.expect
Created April 14, 2018 02:18
Control an RPC-3 Baytech PDU from the command line
#!/usr/bin/expect
# expect power.expect 192.168.5.3 username password 4 on
# expect power.expect 192.168.5.3 username password 4 off
set timeout 20
set name [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
set outlet [lindex $argv 3]
set state [lindex $argv 4]
spawn telnet $name
#!/usr/bin/perl
# How it works: We're looking at 2 important pieces of information in this script. A thread id, and an event in the logs.
# For every log line, we update the correspending thread hash with a new start time.
# When we see an "ARRAY" line, we calculate the thread sleep time based on the last "start" and the current log time.
# This tells us how long asterisk was waiting on that query. The script can be modified to look for things other than "ARRAY".
use strict;
use warnings;
use Time::Piece;
use feature 'say';
use POSIX qw(strftime);
@jsimpsoncd
jsimpsoncd / mysqllogger.pl
Created April 5, 2018 17:36
irssi mysql logger.
#
# Based on url logging script by Riku Voipio, lite.
# http://nchip.ukkosenjyly.mine.nu/irssiscripts/
use DBI;
use Irssi;
use Irssi::Irc;
use vars qw($VERSION %IRSSI);
use Data::Dumper;
use Term::ANSIColor;
use Net::Ping;
use Term::ANSIScreen qw(cls);
use Term::Screen;
my $clear_screen = cls();
$path_to_file = $ARGV[0];
open my $handle, '<', $path_to_file;
chomp(my @host_array = <$handle>);
close $handle;
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2006, Digium, Inc.
*
* Mark Spencer <markster@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
#
# Print hilighted messages & private messages to window named "hilight" for
# irssi 0.7.99 by Timo Sirainen
#
# Modded a tiny bit by znx to stop private messages entering the hilighted
# window (can be toggled) and to put up a timestamp.
#
use Irssi;
use POSIX;
#!/bin/bash
filemtime=`stat -c %Y /var/tmp/crashme.lock`
currmtime=`date +%s`
diffmtime=$(($currmtime - $filemtime))
if [ $diffmtime -lt 600 ]
then
touch /var/tmp/crashme.lock
DATE=`date +%Y%m%d-%H%M`
LOG=/var/tmp/CRASHLOG-${DATE}.log