Taylorbyte.com

IT solutions, linux hosting, web design and computer services

Recent Posts

Pages: [1]
1
General Coding / Re: read JSON into Multidimensional Array PHP
« Last post by brenton on January 15, 2013, 04:19:16 pm »
The ",true" makes it into an associative array... Didn't read the php.net manual properly  :-[

Code: [Select]
<?php
////////////////////

$json_array=json_decode($json,true);
echo 
"SSID: ".$json_array['Updates']['SSID']."\n";
echo 
"MAC: ".$json_array['Updates']['MAC']."\n";
?>
2
General Coding / read JSON into Multidimensional Array PHP
« Last post by brenton on January 15, 2013, 04:04:59 pm »
How can i read a multidimensional JSON array into a multidimensional PHP array

JSON:
Code: [Select]
{
  'updates': {
    'ssid':'tb-hotspot1',
    'mac':'00:15:6D:1A:A2:E2',
    'clientusage': [
      {
        'ip':'192.168.182.232',
        'used':'500000'
      },
      {
        'ip':'192.168.182.200',
        'used':'500000'
      }
    ]
  }
}


Sent POST to PHP server with curl in bash:
Code: [Select]
curl -k -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d $json https://myserver.xx/uam.php

Receive POST from curl into PHP:
Code: [Select]
<?php
$json 
file_get_contents("php://input");
echo 
"\n";
print_r($json);
echo 
"\n";
echo 
"\n";
var_dump(json_decode($json));
echo 
"\n";
echo 
"\n";
$obj=json_decode($json);
print 
$obj->Updates[0]->{'SSID'};  //help needed with this line
?>

3
General bash scripting / Re: fail2ban replacement for ipv6 ssh
« Last post by brenton on June 22, 2012, 04:10:23 pm »
test
4
General bash scripting / fail2ban replacement for ipv6 ssh
« Last post by brenton on December 19, 2011, 01:14:53 am »
This init script only allows 6 ssh attempts every minute. Works with ipv4 and ipv6

Code: [Select]
#!/bin/sh
### BEGIN INIT INFO
# Provides:          ipwall.sh
# Required-Start:    sshd
# Required-Stop:     sshd
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: ipwall.sh
# Description:       Firewall Script
### END INIT INFO
#
# ipv6wall firewall created by Brenton Taylor
#
#

ip4="/sbin/iptables"
ip6="/sbin/ip6tables"
chain1="SSH_LIMITER"
timeframe="60"
hitcount="6"


start() {
  $ip6 -N $chain1
  $ip6 -A $chain1 -p tcp -m state --state NEW -m recent --set --name SSH --rsource -j ACCEPT
  $ip6 -A $chain1 -p tcp -m recent --update --seconds $timeframe --hitcount $hitcount --rttl --name SSH --rsource -j LOG --log-prefix "SSH_brute_force: "
  $ip6 -A $chain1 -p tcp -m recent --update --seconds $timeframe --hitcount $hitcount --rttl --name SSH --rsource -j DROP
  $ip6 -A INPUT -p tcp -m tcp --dport 22 -j $chain1

  $ip4 -N $chain1
  $ip4 -A $chain1 -p tcp -m state --state NEW -m recent --set --name SSH --rsource -j ACCEPT
  $ip4 -A $chain1 -p tcp -m recent --update --seconds $timeframe --hitcount $hitcount --rttl --name SSH --rsource -j LOG --log-prefix "SSH_brute_force: "
  $ip4 -A $chain1 -p tcp -m recent --update --seconds $timeframe --hitcount $hitcount --rttl --name SSH --rsource -j DROP
  $ip4 -A INPUT -p tcp -m tcp --dport 22 -j $chain1
}

stop() {
  $ip6 -D INPUT -p tcp -m tcp --dport 22 -j $chain1
  $ip6 -F $chain1
  $ip6 -X $chain1

  $ip4 -D INPUT -p tcp -m tcp --dport 22 -j $chain1
  $ip4 -F $chain1
  $ip4 -X $chain1
}

restart() {
  stop
  sleep 1
  start
}

show() {
  $ip4 -L -n
  $ip6 -L -n
}

case "$1" in
  start)
    echo -n "Starting firewall script: "
    start
    echo "done"
    ;;
  stop)
    echo -n "Stopping firewall script: "
    stop
    echo "done"
    ;;
  restart)
    echo -n "Restarting firewall script: "
    restart
    echo "done"
    ;;

  show)
    show
    ;;
  *)
    pwd=$(pwd)
    echo "Usage: startup.sh {start|stop|restart|show}"
    ;;
esac
exit 0
5
General bash scripting / Disable or enable ipv6 linux command
« Last post by brenton on December 19, 2011, 01:11:11 am »
To disable or enable ipv6 on a Linux machine:

Enable
Code: [Select]
echo 0 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6
Disable
Code: [Select]
echo 1 | sudo tee /proc/sys/net/ipv6/conf/all/disable_ipv6
This is useful if you are using an ipv6 broker and the tunnel is going up and down or the latency too high for particular websites and you want to temporarily disable ipv6 and re-enable it later.
6
General Discussion / Welcome to SMF!
« Last post by Simple Machines on October 06, 2011, 11:20:30 pm »
Welcome to Simple Machines Forum!

We hope you enjoy using your forum.  If you have any problems, please feel free to ask us for assistance.

Thanks!
Simple Machines
Pages: [1]