Repository navigation
Expand file tree
/
Copy pathparity_list
More file actions
170 lines (159 loc) · 6.75 KB
/
Copy pathparity_list
File metadata and controls
170 lines (159 loc) · 6.75 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/php -q
<?PHP
/* Copyright 2005-2023, Lime Technology
* Copyright 2012-2023, Bergware International.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*/
?>
<?
$docroot = '/usr/local/emhttp';
$varroot = '/var/local/emhttp';
$log = '/boot/config/parity-checks.log';
$stamps = '/var/tmp/stamps.ini';
$resync = '/var/tmp/resync.ini';
$timer = time();
require_once "$docroot/webGui/include/Helpers.php";
require_once "$docroot/webGui/include/publish.php";
extract(parse_plugin_cfg('dynamix',true));
$dot = $display['number'][0];
// add translations
$_SERVER['REQUEST_URI'] = 'main';
$login_locale = $display['locale'];
require_once "$docroot/webGui/include/Translations.php";
// remember current language
$locale_init = $locale;
function new_parity_log($timestamp) {
global $log;
return file_exists($log) ? explode('|',tail($log))[0]!=$timestamp : true;
}
function my_clock($time) {
if (!$time) return _('less than a minute');
$days = floor($time/1440);
$hour = floor($time/60)%24;
$mins = $time%60;
return plus($days,'day',($hour|$mins)==0).plus($hour,'hour',$mins==0).plus($mins,'minute',true);
}
function update_translation($locale) {
global $docroot,$language;
$language = [];
if ($locale) {
$text = "$docroot/languages/$locale/translations.txt";
if (file_exists($text)) {
$store = "$docroot/languages/$locale/translations.dot";
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
$language = unserialize(file_get_contents($store));
}
$text = "$docroot/languages/$locale/main.txt";
if (file_exists($text)) {
$store = "$docroot/languages/$locale/main.dot";
if (!file_exists($store)) file_put_contents($store,serialize(parse_lang_file($text)));
$language = array_merge($language,unserialize(file_get_contents($store)));
}
}
}
function create_sync($file) {
return file_exists($file) ? explode(',',file_get_contents($file)) : [];
}
function create_file($file,...$data) {
if (!file_exists($file)) file_put_contents($file,implode(',',$data));
}
while (true) {
$var = (array)parse_ini_file("$varroot/var.ini");
// check for language changes
extract(parse_plugin_cfg('dynamix',true));
if ($display['locale'] != $locale_init) {
$locale_init = $display['locale'];
update_translation($locale_init);
}
$synced = create_sync($stamps);
$sbSynced = array_shift($synced) ?: $var['sbSynced'];
$data = [];
$spot = $var['mdResyncPos'];
if ($spot>0) {
[$size,$delta,$bytes] = [$var['mdResyncSize'],$var['mdResyncDt'],$var['mdResyncDb']];
create_file($resync,$var['mdResyncAction'],$size);
$data[] = my_scale($size*1024,$unit,-1)." $unit";
$data[] = _(my_clock(floor((time()-$sbSynced)/60)),2).($delta ? '' : ' ('._('paused').')');
$data[] = my_scale($spot*1024,$unit)." $unit (".number_format($spot/($size/100+1),1,$dot,'')." %)";
$data[] = $delta ? my_scale($bytes*1024/$delta,$unit, 1)." $unit/sec" : '---';
$data[] = $bytes ? _(my_clock(round(((($delta*(($size-$spot)/($bytes/100+1)))/100)/60),0)),2) : _('Unknown');
$data[] = $var['sbSyncErrs'];
} elseif ($var['sbSynced'] && $var['sbSynced2']) {
$timestamp = str_replace(['.0','.'],[' ',' '],date('Y.M.d H:i:s',$var['sbSynced2']));
if (new_parity_log($timestamp)) {
$idle = []; while (count($synced)>1) $idle[] = array_pop($synced)-array_pop($synced);
[$action,$size] = file_exists($resync) ? my_explode(',',file_get_contents($resync)) : [$var['mdResyncAction'],$var['mdResyncSize']];
$duration = $var['sbSynced2']-$sbSynced-array_sum($idle);
$status = $var['sbSyncExit'];
$speed = $status==0 ? round($size*1024/$duration) : 0;
$error = $var['sbSyncErrs'];
file_put_contents($log,"$timestamp|$duration|$speed|$status|$error|$action|$size\n",FILE_APPEND);
}
delete_file($stamps,$resync);
}
if ($var['fsState']=='Copying') $fsState = $var['fsCopyPrcnt']."% "._('completed');
elseif ($var['fsState']=='Clearing') $fsState = $var['fsClearPrcnt']."% "._('completed');
elseif (substr($var['fsState'],-3)!='ing') $fsState = 'stop';
else $fsState = '';
if ($var['fsState']!='Started') $process = -1;
elseif ($spot>0) $process = 1;
elseif (file_exists('/var/run/mover.pid')) $process = 2;
elseif (exec('pgrep -cf /sbin/btrfs')>0) $process = 3;
else $process = 0;
if ($process == 2) {
$moverdata = [];
if ( file_exists("$varroot/mover.ini")) {
$moverstat = parse_ini_file("$varroot/mover.ini") ;
$moverdata[] = $moverstat["File"] ;
$moverdata[] = $moverstat["Action"] ;
$perc = $moverstat["Filepercent"] ;
$moverdata[] = "<div class='usage-disk' style='width:50%'><span style='width:$perc%' class='greenbar'></span><span>$perc%</span></div>" ;
if ($moverstat["TotalToArray"]>0) {
$toperc = ($moverstat["TotalToArray"]-$moverstat["RemainToArray"])/$moverstat["TotalToArray"] * 100;
if ($moverstat["RemainToArray"]>0) {
$perc= round($toperc,2) ;
$moverdata[] = "<div class='usage-disk' style='width:50%'><span style='width:$perc%' class='greenbar'></span><span>"._("Percentage Complete ").$perc."%</span></div>" ;
} else {$moverdata[] = _("Transfer complete") ;}
} else {
$moverdata[] = _("Nothing to transfer") ;}
if ($moverstat["TotalFromArray"]>0) {
$fromperc = ($moverstat["TotalFromArray"] - $moverstat["RemainFromArray"])/$moverstat["TotalFromArray"] * 100;
if ($moverstat["RemainFromArray"]>0) {
$perc= round($fromperc,2) ;
$moverdata[] = "<div class='usage-disk' style='width:50%'><span style='width:$perc%' class='greenbar'></span><span>"._("Percentage Complete ").$perc."%</span></div>";
} else {$moverdata[] = _("Transfer complete") ;}
} else {
$moverdata[] = _("Nothing to transfer") ;}
} else {
$moverdata[] = _('Error');
$moverdata[] = _('Error');
$moverdata[] = _('Error');
$moverdata[] = _('Error');
$moverdata[] = _('Error');
}
} else {
$moverdata = [];
$moverdata[] = _('Not Running');
$moverdata[] = _('Not Running');
$moverdata[] = _('Not Running');
$moverdata[] = _('Not Running');
$moverdata[] = _('Not Running');
}
publish('parity', implode(';',$data));
if (time()-$timer >= 2) {
// update every 2 seconds
publish('paritymonitor', $spot>0 ? 1 : 0);
publish('fsState', $fsState);
publish('mymonitor', $process);
publish('mover', implode(';',$moverdata));
$timer = time();
}
sleep(1);
}
?>