eyesis4pi_interface.php 3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
<?php
/*
*!***************************************************************************
*! FILE NAME  : eyesis4pi_interface.php
*! DESCRIPTION: command interface for the eyesis4pi gui
*! 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/>.
*! --------------------------------------------------------------------------
*/

23
include 'include/elphel_functions_include.php';
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
24

25 26 27 28 29 30
$cmd = "donothing";
if (isset($_GET['cmd']))
  $cmd = $_GET['cmd'];
else if (isset($argv[1]))
  $cmd = $argv[1];

Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
31
#hardcoded for eyesis4pi
32 33
$symlink = "/www/pages/ssd";
$mountpoint = "/mnt/sda1";
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
34
$camogmdisk = "/home/root/camogm.disk";
35 36 37
  
switch($cmd){
  case "symlink":
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
38 39
    if (is_link($symlink)) die("already exists");
    die(symlink($mountpoint,$symlink));
40
    break;
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
41
  case "free_space":
42
    //sda1
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
43 44 45 46
    if (is_dir($mountpoint)){
      $sda1 = round(disk_free_space($mountpoint)/1024/1024/1024,2);
      $sda1 .= "G";
    }
47 48 49 50 51 52
    
    //sda2
    if (!is_file($camogmdisk)){
      $devices = get_raw_dev();
      foreach($devices as $device=>$size){
        //size in MB
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
53 54 55 56
        if ($device=="/dev/sda2") {
          $sda2 = round($size/1048576,2);
          $sda2 .= "G";
        }
57 58 59
      }
    }else{
      //read camogm.disk file
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
60 61 62 63 64 65 66 67 68
      //tmp
      $devices = get_raw_dev();
      foreach($devices as $device=>$size){
        //size in MB
        if ($device=="/dev/sda2") {
          $sda2 = round($size/1048576,2);
          $sda2 .= "G";
        }
      }
69 70
    }
    
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
71
    respond_xml("{$sda1} {$sda2}");
72 73 74
    
    break;
  case "free_space_bkp":
75
    // results are in GB
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
76
    // /dev/sda2 is not a mountpoint but a device because it does not have a file system
77
    $res = 0;
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
78 79 80 81 82
    if ($_GET['mountpoint']=="/dev/sda2"){
      //root@elphel393:~# cat /home/root/camogm.disk
      //Device          Start LBA       Current LBA     End LBA
      ///dev/sda2       195334335       545641716       976768065
      if (!is_file($camogmdisk)){
83 84 85 86 87
        $devices = get_raw_dev();
        foreach($devices as $device=>$size){
          //size in MB
          if ($device=="/dev/sda2") $res = round($size/1048576,2);
        }
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
88
      }else{
89 90
        //read camogm.disk file
        $res = 10;
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
91
      }
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
92
    }else{
93
      if (is_dir($mountpoint)) $res = round(disk_free_space($mountpoint)/1024/1024/1024,2);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
94
    }
95
    respond_xml($res);
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
96
    break;
97
  default:
Oleg Dzhimiev's avatar
Oleg Dzhimiev committed
98
    print("nothing has been done");
99 100 101
}
  
?>