camogm.php 3.27 KB
Newer Older
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
<?php
/*
*!******************************************************************************
*! File: camogm.php
*! Description: command interface for the camogm recorder based on 
*! http://elphel.cvs.sourceforge.net/viewvc/elphel/elphel353-8.0/packages/web/353/camogmgui/camogm_interface.php?revision=1.23&content-type=text%2Fplain
*!
*! Copyright (C) 2016 Elphel, Inc
*! -----------------------------------------------------------------------------**
*!  This program is free software: you can redistribute it and/or modify
*!  it under the terms of the GNU General Public License as published by
*!  the Free Software Foundation, either version 3 of the License, or
*!  (at your option) any later version.
*!
*!  This program is distributed in the hope that it will be useful,
*!  but WITHOUT ANY WARRANTY; without even the implied warranty of
*!  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*!  GNU General Public License for more details.
*!
*!  You should have received a copy of the GNU General Public License
*!  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*! -----------------------------------------------------------------------------**
*/

$chn = 0;
$cmd = "donothing";
$debug = false;
$debuglev = 6;

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
30
if (isset($_GET['chn']))      $chn      = $_GET['chn'];
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
if (isset($_GET['cmd']))      $cmd      = $_GET['cmd'];
if (isset($_GET['debug'])   ) $debug    = $_GET['debug'];
if (isset($_GET['debuglev'])) $debuglev = $_GET['debuglev'];

$r_pipe="/tmp/camogm$chn.status";
$c_pipe="/var/volatile/camogm_cmd$chn";

if ($cmd=="status"){
	$mode=0777;
	if(!is_file($r_pipe)){
		umask(0);
		posix_mkfifo($r_pipe,$mode);
	}
	$fcmd=fopen($c_pipe,"w");
	fprintf($fcmd, "xstatus=%s\n",$r_pipe);
	fclose($fcmd);
	
	$res=file_get_contents($r_pipe);
	xml_response($res);
}

if ($cmd=="list") {
	$res="";
	if (isset($_GET['path'])) $path = $_GET['path'];
	else {
	    $res = "<res>the path is not set</res>\n";
	}
	if (is_dir($path)) {
	    $files = scandir($path);
	    foreach ($files as $file){
			if (is_file("$path/$file")) $res .= "<f>$path/$file</f>\n";
			if (is_dir("$path/$file"))  $res .= "<d>$path/$file</d>\n";
	    }
	}else{
	    $res = "<res>directory not found</res>\n";
	}
	xml_response("<camogm>\n$res</camogm>\n",true);
}

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
70 71 72 73
if ($cmd=="create_symlink"){
	if (isset($_GET['path'])) {
		$path = $_GET['path'];
		if (is_dir($path)){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
74 75 76
			exec("ln -sf $path /www/pages/video;sync");
			//if (file_exists("/tmp/video")) unlink("/tmp/video");
                        //exec("ln -sf $path /tmp/video");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
77 78 79
		}
	}
}
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
80 81 82 83 84 85 86 87 88 89 90 91
//camogm pipe commands

$fcmd = fopen($c_pipe, "w");

if ($cmd=="start"){
	fprintf($fcmd,"start;\n");
}else if ($cmd=="stop"){
	fprintf($fcmd,"stop;\n");
	exec('sync');
}else if ($cmd=="exit"){
	fprintf($fcmd,"exit;\n");
	exec('sync');
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
92
}else if ($cmd=="default"){
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
93
	fprintf($fcmd,"format=mov;exif=0;prefix=/mnt/sda1/;\n");
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
}else{
	fprintf($fcmd,"$cmd\n");
	//exec('sync');
}

fclose($fcmd);

$res  = "<channel>$chn</channel>\n";
$res .= "<cmd>$cmd</cmd>\n";
xml_response("<camogm>\n$res</camogm>\n",true);
die("done");

function xml_response($msg,$addheader=false){
	if ($addheader) $msg = "<?xml version='1.0' standalone='yes' ?>\n$msg";
	header("Content-Type: text/xml");
	header("Content-Length: ".strlen($msg)."\n");
	header("Pragma: no-cache\n");
	echo $msg;
	flush();
	die();
}

?>