Check if a client is connected to the OwnCloud server - shell

How one could check on the server where ownloud is running if currently a client is connected? Is there a command provided by ownloud itself or can this be done via Bash?

Not possible, yet! You can make an plugin which looks up the last sync time.
And if $time < 60 secs ago then client is online.

Related

bash ncat / nc / netcat connection won't close / stays open too long

I'm using Ubuntu 18.04 LTS with bash 4.4.20.
I'm trying to create a little daemon to schedule data transmission between threads.
On the server I am doing this:
ncat -l 2001 -k -c 'xargs -n1 ./atc-worker.sh'
On the client I am doing this:
echo "totally-legit-login-token" | nc 127.0.0.1 2001 -w 1
And it works well!
Here is the response:
LaunchCode=1589323120.957093305 = Now=1589323120.957093305 = URL=https://totally-legit-url.com/ = AuthToken=totally-legit-auth-token = LastID=167
When the server receives a request from a client, it calls my little atc-worker.sh script. The server spits out a single line of text and it is back to business, serving other clients.
Thanks to the -k option, the server listens continuously. Multiple clients can connect at the same time. The only problem, is that I cannot end the connection programmatically. I need the daemon -k functionality on the server to answer requests from the clients, but I need the clients to quit listening after receiving a response and get on to their other work.
Is there an EOF signal/character I can send from my atc-worker.sh script that would tell nc on the client side to disconnect?
On the client, I use the -w 1 option to tell the client to connect for no more than a second.
But this -w 1 option has some drawbacks.
Maybe a second is too long. The connection should just take ~150 milliseconds and waiting out the rest of the second slows each client down even if it already has its answer. And -as I said before- the client has chores to do! The client shouldn't be wasting its time after it has its answer!
Bad actors Rogue clients could connect to the server that have no intention to close out in a timely manner and I want the server to have better control and shut down bad actors.
Maybe a second is too short. atc-worker.sh has a mechanism to wait for a lock file to be removed if there is one. If that lock file is there for more than a second, the connection will close before the client can receive its response.
Possible solutions.
The atc-worker.sh script could send a magic character set to terminate the connection. Problem solved.
On the client-side set of solutions, maybe curl would be a suitable choice instead of nc? But it would not solve my concern of being able to deal with bad actors. Maybe these are two different problems? Client-side closing the connection immediately after an answer is received, and server-side dealing with bad actors who will use what ever clients they choose.
Maybe use expect? I'm investigating that now.
Thanks in advance!
OK. After a lot of digging, I found someone else with a similar problem. Here is a link to his answer.
Original question: Client doesn't close connection to server after receiving all responses
Original Answer: https://stackoverflow.com/a/50528286/3055756
Thanks #Unyxos
I modified my daemon to send an "ENDRESPONSE" line when it was done even though it does not drop the connection. And I modified the client to look for that "ENDRESPONSE" line. When the client gets the line, it drops the connection using the logic that #Unyxos uses below in his answer.
Here is his simple and elegant answer:
Finally found a working way (maybe not the best but at least it's perfectly doing what I want :D)
after all functions I send a "ENDRESPONSE" message, and on my client, I test if I have this message or not :
function sendMessage {
while read line; do
if [[ $line == "ENDRESPONSE" ]]; then
break
else
echo $line
fi
done < <(netcat "$ipAddress" "$port" <<< "$*")
}
Anyway thanks for your help, I'll try to implement other solutions later !

golang http server tailing logs kubeapi proxy

Maybe anyone faced a similar problem. We have a kubeapi proxy which impersonates users using sso.
Kubectl tool works just fine with any commands unless you do tail -f
I do see that app data is coming back every 1-5 seconds, but to output it takes ~ 45 seconds.
We use http/server from standard go packages and our proxy is based of https://github.com/ericchiang/kube-oidc/issues
TCP Dump attached. Thanks

Bash script to generate lots of ssl/tls connections for performance testing

I'm currently trying to perf test my application running in production. Specifically, I'm trying to see how many ssl connections my jetty server can handle. Let's call this host my.webserver.prod.com and it expects secure traffic on port 443. I would like to write a bash script that I can run from another host and have it generate as many ssl connections as possible. How can I do this?
What have you tried till now?
Still you could checkout this tool that bash has ab. Its apahce benchmarking.
This helps in checking performance. And In the end it provides you a summary.
The command goes like :
ab -n 10 -c 2 http://my.webserver.prod.com
Where
-n -> total number of requests to be made
-c -> number of concurrent requests
You could do more resarch on this.
Hope this helps.

Avoid ssh session time out

I am remotely working on a server that automatically logs me out after 5 minutes of inactivity. Here's the message that it usually provides when it does so:
Read from remote host XXXXXXX: Operation timed out
I typically have several sessions open, which I use at roughly 30-minute intervals, so I wonder what I could do to avoid getting disconnected. I've already tried:
[a] hiring a monkey to hit some keys before the session logs me out
[b] running the top command
[c] threatening the server administrator :)
Any other suggestions? Thanks.
This has been answered on StackOverFlow - I add the link here for people that don't want to go to a third party forum when they search for this answer (as I did):
https://stackoverflow.com/questions/13390710/mac-terminals-how-to-keep-alive
Add to ~/.ssh/config
ServerAliveInterval 30
or start your ssh session using:
ssh -o ServerAliveInterval 30 username#hostname
And BTW: the answer is not specific to Mac.
You might consider using vi or more to edit a file.

Windows Phone 7 > How to abort asynchronous download

I implement asynchronous download to retrieve remote file and store it in IsolatedStorage in order to use it when out of the network.
Everything works great when network is up. However when out of network, I noticed that async donwload may take up to 2 minutes before to fire my MessageBox (which say that connection to server has failed).
Question:
Is there any way to define a timeout ? Let's say that if my application does not receive any answer for X seconds then stop the Async Download and call a method.
Maybe a timeout is not the best pratices. In this case could you give me suggestion ?
I do not want my user wait for 15 seconds max.
PS: my application is suppose to run on wifi only, so I consider that 'network speed' is optimal.
Thx for your help
What I would recommend doing is check the network type first via NetworkInterface. If NetworkInterfaceType is Wireless80211, you have a wireless connection (Wi-Fi). The returned connection can be None in case there is no available way to connect - so you won't even have to start the download if there is no accessible network.
Answering your question, if you are using WebClient, you can't define a timeout. However, you can call instance.CancelAsync(). For a HttpWebRequest you can call instance.Abort().

Resources