Skip to content

Commit 5cf0c37

Browse files
add server
1 parent a34b034 commit 5cf0c37

File tree

2 files changed

+94
-1
lines changed

2 files changed

+94
-1
lines changed

examples/Maestro/eg002EmbedWorkflow.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,19 @@ if [ -z "$instance_url" ]; then
2020
echo "No instance URL found. Please run the trigger workflow script first."
2121
exit 1
2222
fi
23-
2423
# Step 3: Decode any escaped characters
2524
decoded_instance_url=$(echo "$instance_url" | sed 's/\\u0026/\&/g')
2625

26+
27+
host_url="http://localhost:8080"
28+
if which xdg-open &> /dev/null ; then
29+
xdg-open $host_url
30+
elif which open &> /dev/null ; then
31+
open $host_url
32+
elif which start &> /dev/null ; then
33+
start $host_url
34+
fi
35+
php ./examples/Maestro/lib/startServerForEmbeddedWorkflow.php "$decoded_instance_url"
2736
# Step 4: Output for developer
2837
echo ""
2938
echo "✅ Workflow instance URL retrieved for workflow ID: $workflow_id"
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
$PORT = '8080';
4+
$IP = 'localhost';
5+
6+
$state = bin2hex(random_bytes(5));
7+
8+
$triggerUrl = "$argv[1]";
9+
10+
$socket = 'tcp://' . $IP . ':' . $PORT;
11+
12+
$responseOk = "HTTP/1.0 200 OK\r\n"
13+
. "Content-Type: text/html\r\n\r\n"
14+
. "
15+
<!--
16+
#ds-snippet-start:eSign44Step6
17+
-->
18+
<br />
19+
<h2>The document has been embedded with focused view.</h2>
20+
<br />
21+
22+
<!DOCTYPE html>
23+
<html>
24+
<head>
25+
<meta charset=\"utf-8\" />
26+
<title>Signing</title>
27+
<style>
28+
html,
29+
body {
30+
padding: 0;
31+
margin: 0;
32+
font: 13px Helvetica, Arial, sans-serif;
33+
}
34+
</style>
35+
</head>
36+
<body>
37+
<div>
38+
<iframe src=$triggerUrl width=800 height=600>
39+
</iframe>
40+
</div>
41+
</body>
42+
</html>
43+
44+
<p><a>Continue</a></p>
45+
46+
<!--
47+
#ds-snippet-end:eSign44Step6
48+
-->";
49+
50+
ini_set('default_socket_timeout', 60 * 5);
51+
$server = stream_socket_server($socket, $errno, $errstr);
52+
if (!$server) {
53+
Log::err('Error starting HTTP server');
54+
return false;
55+
}
56+
do {
57+
$sock = stream_socket_accept($server);
58+
if (!$sock) {
59+
Log::err('Error accepting socket connection');
60+
exit(1);
61+
}
62+
$contentLength = 0;
63+
$headers = [];
64+
$body = null;
65+
while (false !== ($line = trim(fgets($sock)))) {
66+
if ($line === '') break;
67+
$regex = '#^Content-Length:\s*([[:digit:]]+)\s*$#i';
68+
if (preg_match($regex, $line, $matches)) {
69+
$contentLength = (int)$matches[1];
70+
}
71+
$headers[] = $line;
72+
}
73+
if ($contentLength > 0) {
74+
$body = fread($sock, $contentLength);
75+
}
76+
list($method, $url, $httpver) = explode(' ', $headers[0]);
77+
if ($method == 'GET') {
78+
fwrite($sock, $responseOk);
79+
fclose($sock);
80+
return;
81+
}
82+
} while (true);
83+
84+
?>

0 commit comments

Comments
 (0)