Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Some simple PHP-libs for own use
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
README
cmd.php
id.php
log.php
net.php
pid.php
ping.php
telnet.php

README

Some handy code snippets in PHP for own use.

- cmd.php

	Can execute shell command. Returns the result of execution (command output).

	Example of use:

	$output = command("iptables -n -L -v");
	echo $output;

- id.php

	Just returns UID

	Example of use:

	$uid = getuid();


- log.php

	Simple PHP-log

	Example of use:

	writelog(-1,"some error has been happened");
	writelog(2,"just info message");

- net.php

	Simple network mask related functions.

	Example of use:
	
	$someip = "1.1.1.12/22";
	echo get_mask($someip); // will print "255.255.252.0"
	echo get_net($someip); // will print "1.1.0.0"

- pid.php

	Creates pid-file and prevents multi-copies of the same process.

	Example of use:

	$pid = new pid("pid",30);
	if ($pid ->already_running)
	{
	 echo "we're already running\n";
	 if ($pid->alarm)
	 {
		echo "we're running more than 30 minutes\n";
		if (!$pid->respawn()) { echo "can't kill process"; exit; }
		echo "process terminated. working...\n";
	 }
	}
	else
	{
		echo "another process is running but it is not time to kill it yet\n";
		exit;
	}

- ping.php

	Can ping network hardware.
	Requires root privileges.

	Example of use:

	$p = new ICMP();
	if (0 >= $icmp->ping(IP,COUNT)) { echo "no response\n"; exit; }

- telnet.php

	Can telnet to network hardware and do some commands.
	Tested with D-Link, Edge-Core, Cisco

	Example of use:
		
	$t = new PHPTelnet();
	$r = $t->Connect(IP,USER,PASSWORD);
	if (0 != $r) { echo "error\n"; exit; }
	$t->DoCommand(SOME_COMMAND);
	$t->Disconnect();
Something went wrong with that request. Please try again.