-
Notifications
You must be signed in to change notification settings - Fork 2
/
checkstatus.php
143 lines (132 loc) · 4.87 KB
/
checkstatus.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
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
<?php // this file used onlt for s400w scanner
include_once 'phppagestart.php';
include_once 'lang.php';
include_once 'config.inc.php';
// session_start();
// include_once 'checkscanner.php';
//$_SESSION['modulerunning']='no';
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
if ($demomode=='yes')
{
//$refresh='1800';
$statusmessagetxt=$pagereadytxt;
//sleep(4);
}
elseif (($demomode!='yes') && ($scanner=='s400w')) // Get s400w status
{
usleep(500000);
if (($_SESSION['scanneronline']=='yes') && ($requireauth=='yes') && ($_SESSION['loggedin'] == 'yes') && ($scanner=='s400w'))
{
$status = "$s400w $host $port status";
$statusoutput = shell_exec("$status");
$string = $statusoutput;
$last_word_start = strrpos($string, ' ') + 1; // +1 so we don't include the space in our result
$last_word = substr($string, $last_word_start); // $last_word = PHP.
$lastword=preg_replace('/\s+/', '', $last_word);
if ($lastword=='nopaper'){ //online but no page loaded -nested if
$statusmessagetxt=$insertpagetxt;
}
elseif (($lastword=='scango') || (trim($lastword)=='')) { //online device is busy -nested if
$statusmessagetxt=$scanningtxt;
}
elseif ($lastword=='devbusy'){ //online device is busy -nested if
$statusmessagetxt=$devbusytxt;
}
elseif ($lastword=='battlow'){ //online but battery low -nested if
$statusmessagetxt=$battlowtxt;
}
elseif ($lastword=='scanready'){ //online with page loaded -nested elseif
$statusmessagetxt=$pagereadytxt;
}
else { //other- unknown paper condition -nested else
$statusmessagetxt= '<span style="color:#FFF; font-weight:bold"> </span>';
}
}
elseif (($requireauth!='yes') && ($_SESSION['scanneronline'] =='yes') && ($scanner=='s400w'))
{
$status = "$s400w $host $port status";
$statusoutput = shell_exec("$status");
$string = $statusoutput;
$last_word_start = strrpos($string, ' ') + 1; // +1 so we don't include the space in our result
$last_word = substr($string, $last_word_start); // $last_word = PHP.
$lastword=preg_replace('/\s+/', '', $last_word);
if ($lastword=='nopaper'){ //online but no page loaded -nested if
$statusmessagetxt=$insertpagetxt;
}
elseif ($lastword=='devbusy'){ //online device is busy -nested if
$statusmessagetxt=$devbusytxt;
}
elseif ($lastword=='battlow'){ //online but battery low -nested if
$statusmessagetxt=$battlowtxt;
}
elseif ($lastword=='scanready'){ //online with page loaded -nested elseif
$statusmessagetxt=$pagereadytxt;
}
else { //other- unknown paper condition -nested else
$statusmessagetxt= '<span style="color:#FFF; font-weight:bold"> </span>';
}
}
elseif (($requireauth=='yes') && ($_SESSION['loggedin'] != 'yes') && ($_SESSION['scanneronline'] =='yes') && ($scanner=='s400w'))
{
$statusmessagetxt= '<span style="color:#FFF; font-weight:bold"> </span>';
}
elseif (($requireauth=='yes') && ($_SESSION['loggedin'] == 'yes') && ($_SESSION['scanneronline'] !='yes') && ($scanner=='s400w'))
{
$statusmessagetxt= '<span style="color:#FFF; font-weight:bold"> </span>';
}
elseif (($_SESSION['scanneronline']=='no') && ($scanner=='s400w'))
{
$statusmessagetxt= '<span style="color:#FFF; font-weight:bold"> </span>';
}
}
elseif (($_SESSION['scanneronline'] =='yes') && ($scanner=='SANE')) // get eSCL Scanner Status
{
$statusmessagetxt='<span style="color:#484; font-weight:bold">Ready</span>';
}
elseif (($_SESSION['scanneronline'] =='yes') && ($scanner=='eSCL')) // get eSCL Scanner Status
{
function get_string_between($string, $start, $end)
{
$string = ' ' . $string;
$ini = strpos($string, $start);
if ($ini == 0) return '';
$ini += strlen($start);
$len = strpos($string, $end, $ini) - $ini;
return substr($string, $ini, $len);
}
usleep(500000);
$scannerstatus=file_get_contents('http://'.$_SESSION["esclip"].':'.$_SESSION["esclport"].'/eSCL/ScannerStatus');
if (($scannerstatus==NULL) ||($scannerstatus==''))
{
//echo 'EMPTY!';
//echo 'AAA'.$scannerstatus;
}
else
{
//echo 'CCC'.$scannerstatus;
}
$beginafter='<pwg:State>'; //application/pdf or image/jpeg some scanners may support other formats like TIFF or PNG
$endbefore='</pwg:State>';
$pwgstatetext= trim(get_string_between($scannerstatus, $beginafter, $endbefore));
if ($pwgstatetext=='Stopped')
{
$statusmessagetxt=$stopped;
}
elseif ($pwgstatetext=='Idle')
{
$statusmessagetxt=$idle;
}
elseif ($pwgstatetext=='Processing')
{
$statusmessagetxt=$processing;
}
else
{
$statusmessagetxt= '<span style="color:#FFF; font-weight:bold"> </span>';
}
//$statusmessagetxt=${$pwgstatetext};
}
//$_SESSION['modulerunning']='';
echo "retry: $refresh\n\ndata: {$statusmessagetxt}\n\n";
?>