Skip to content

Commit 4d9c42b

Browse files
committed
docker image working properly
1 parent a2a50f2 commit 4d9c42b

File tree

7 files changed

+712
-3
lines changed

7 files changed

+712
-3
lines changed

AI_MultiBarcodes_Capture/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ dependencies {
6868
// Dependency for CriticalPermissionHelper
6969
implementation(libs.criticalpermissionhelper)
7070

71+
// Dependency to use internal scanner for endpoint configuration
72+
implementation(libs.datawedgeintentwrapper)
73+
7174
// For Excel Export
7275
implementation(libs.poi)
7376
implementation(libs.poiooxml)

WebInterface/src/api/barcodes.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,11 @@ private function updateBarcodeStatus($barcode_id) {
194194
WHERE id = :barcode_id
195195
");
196196

197-
$stmt->bindParam(':processed', $input['processed'] ?? false, PDO::PARAM_BOOL);
198-
$stmt->bindParam(':notes', $input['notes'] ?? '');
197+
$processed = $input['processed'] ?? false;
198+
$notes = $input['notes'] ?? '';
199+
200+
$stmt->bindParam(':processed', $processed, PDO::PARAM_BOOL);
201+
$stmt->bindParam(':notes', $notes);
199202
$stmt->bindParam(':barcode_id', $barcode_id);
200203
$stmt->execute();
201204

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?php
2+
header('Content-Type: application/json');
3+
header('Access-Control-Allow-Origin: *');
4+
header('Access-Control-Allow-Methods: GET, OPTIONS');
5+
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');
6+
7+
// Handle preflight requests
8+
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
9+
http_response_code(200);
10+
exit();
11+
}
12+
13+
function getServerIPs() {
14+
$ips = array();
15+
16+
// Get local network IP addresses
17+
$localIPs = array();
18+
19+
// Method 0: Check if HOST_IP is provided via environment variable
20+
$hostIP = getenv('HOST_IP');
21+
if ($hostIP && filter_var($hostIP, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
22+
$localIPs[] = $hostIP;
23+
}
24+
25+
// Method 1: Use hostname -I command (Linux/Unix)
26+
$output = shell_exec('hostname -I 2>/dev/null');
27+
if ($output) {
28+
$addresses = explode(' ', trim($output));
29+
foreach ($addresses as $ip) {
30+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
31+
$localIPs[] = $ip;
32+
}
33+
}
34+
}
35+
36+
// Method 2: Use ifconfig command
37+
if (empty($localIPs)) {
38+
$output = shell_exec('ifconfig 2>/dev/null | grep -oP "inet \K(\d+\.\d+\.\d+\.\d+)" | grep -v 127.0.0.1');
39+
if ($output) {
40+
$addresses = explode("\n", trim($output));
41+
foreach ($addresses as $ip) {
42+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) && !preg_match('/^127\./', $ip) && !preg_match('/^169\.254\./', $ip)) {
43+
$localIPs[] = $ip;
44+
}
45+
}
46+
}
47+
}
48+
49+
// Method 3: Use ip command (modern Linux) - get host IP via route
50+
if (empty($localIPs)) {
51+
$output = shell_exec("ip route get 8.8.8.8 2>/dev/null | awk '{for(i=1;i<=NF;i++) if(\$i==\"src\") print \$(i+1)}'");
52+
if ($output) {
53+
$ip = trim($output);
54+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
55+
$localIPs[] = $ip;
56+
}
57+
}
58+
}
59+
60+
// Method 3.5: Get host IP from Docker gateway
61+
if (empty($localIPs)) {
62+
$output = shell_exec("ip route | grep default | awk '{print \$3}' 2>/dev/null");
63+
if ($output) {
64+
$gateway = trim($output);
65+
if (filter_var($gateway, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
66+
// Try to resolve the local network from the gateway
67+
$networkBase = implode('.', array_slice(explode('.', $gateway), 0, 3));
68+
for ($i = 1; $i <= 254; $i++) {
69+
$testIP = $networkBase . '.' . $i;
70+
if ($testIP !== $gateway) {
71+
// Check if this IP responds (simplified check)
72+
$localIPs[] = $gateway; // Use gateway as fallback
73+
break;
74+
}
75+
}
76+
}
77+
}
78+
}
79+
80+
// Method 4: Fallback - get server's hostname and resolve it
81+
if (empty($localIPs)) {
82+
$hostname = gethostname();
83+
$ip = gethostbyname($hostname);
84+
if ($ip !== $hostname && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
85+
$localIPs[] = $ip;
86+
}
87+
}
88+
89+
$ips['local'] = !empty($localIPs) ? $localIPs[0] : $_SERVER['SERVER_ADDR'] ?? '127.0.0.1';
90+
91+
// Get external IP
92+
$externalIP = getExternalIP();
93+
$ips['external'] = $externalIP;
94+
95+
return $ips;
96+
}
97+
98+
function getExternalIP() {
99+
$services = [
100+
'http://ipinfo.io/ip',
101+
'http://icanhazip.com',
102+
'http://ident.me',
103+
'http://whatismyipaddress.com/api'
104+
];
105+
106+
$context = stream_context_create([
107+
'http' => [
108+
'timeout' => 10,
109+
'user_agent' => 'Mozilla/5.0 (compatible; ServerInfoBot/1.0)'
110+
]
111+
]);
112+
113+
foreach ($services as $service) {
114+
try {
115+
$ip = @file_get_contents($service, false, $context);
116+
if ($ip) {
117+
$ip = trim($ip);
118+
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
119+
return $ip;
120+
}
121+
}
122+
} catch (Exception $e) {
123+
continue;
124+
}
125+
}
126+
127+
return 'Unable to detect';
128+
}
129+
130+
try {
131+
$serverIPs = getServerIPs();
132+
133+
echo json_encode([
134+
'success' => true,
135+
'local_ip' => $serverIPs['local'],
136+
'external_ip' => $serverIPs['external'],
137+
'hostname' => gethostname(),
138+
'server_addr' => $_SERVER['SERVER_ADDR'] ?? 'unknown'
139+
], JSON_PRETTY_PRINT);
140+
141+
} catch (Exception $e) {
142+
http_response_code(500);
143+
echo json_encode([
144+
'success' => false,
145+
'error' => $e->getMessage()
146+
], JSON_PRETTY_PRINT);
147+
}
148+
?>

0 commit comments

Comments
 (0)