-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfota.php
62 lines (56 loc) · 1.74 KB
/
fota.php
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
30
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
<?php
/**
* [API] FOTA.
*
* FOTA(Farmware update On The Air)
* Return FOTA settings provided for the account as JSON.
*
* Requires $_GET['serial_id']
*
* @author Dr. Takeyuki UEDA
* @copyright Copyright© Atelier UEDA 2016 - All rights reserved.
*
*/
ini_set( 'display_errors', 0 ); // エラー出力しない場合
#ini_set( 'display_errors', 1 ); // エラー出力する場合
require_once("vendor/autoload.php");
#require_once("Log.php");
$logfilename = "fota.out.log";
$logfile = &Log::factory('file', $logfilename, 'TEST');
$logfile->log('['.__LINE__.']'.'*** STARTED ***');
$json=null;
$json['serial_id'] = $_GET['serial_id'];
// 必用に応じて log ファイルのコンパクションを行う
$p=pathinfo($_SERVER['SCRIPT_FILENAME']);
$logfile->log('['.__LINE__.']'.'$_SERVER[SCRIPT_FILENAME] = '.$_SERVER['SCRIPT_FILENAME']);
$command = "".$p['dirname']."/compaction.sh ".$logfilename;
$logfile->log('['.__LINE__.']'.'$command = '.$command);
`$command`;
# 設定の読み込み
if (isset($_GET['file'])){
$configfile = "uploads/".$_GET['serial_id']."/".$_GET['file'];
} else {
$configfile = "uploads/".$_GET['serial_id']."/fota.ini";
}
$fota = parse_ini_file($configfile);
# 設定値の json への設定
if (array_key_exists('restart',$fota)){
$json['restart']=$fota['restart'];
$fota['restart']=null;
}
if (array_key_exists('command',$fota)){
$json['command']=$fota['command'];
$fota['command']=null;
}
# 設定値の上書き
$fp = fopen($configfile, 'w');
foreach ($fota as $k => $i) fputs($fp, "$k=$i\n");
fclose($fp);
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
$json_str = json_encode( $json );
//error_log('$json_str = '.$json_str);
echo $json_str;
// echo json_encode( $json );
exit;
?>