Getting gps coordinates without a gps module - gps

I am working on Raspberry PI B+.
I have to get the current location of the system in python.
Is there a way to do that without using a GPS Module ?
The PI is always connected to the Internet

Take a look at the GeoIP2.
It won't work like a GPS but depending on the purpose, might be useful.

If you have a Wifi network adaptor connected, you can query Google's geocoding API with the access point data to get location.
The following command line will retrieve the location:
sudo iwlist wlan0 scan | sed -E '1s/.*/{"wifiAccessPoints":[/;s/^ *Cell.*: (.*)/{"macAddress":"\1",/;s/^ *Channel:(.*)/"channel":\1,/;s/^.*nal level=(-[0-9]+) .*/"signalStrength":\1},/;/^ /d;$d' | sed '$s/.$/]}/' | curl -d #- -H "Content-Type: application/json" "https://www.googleapis.com/geolocation/v1/geolocate?key=${APIKEY}"
You'll need to set the APIKEY environment variable. You can get an API key from https://developers.google.com/maps/documentation/geocoding/get-api-key.

curl https://ipvigilante.com, this is the best you can do.

I don't know the application, but this is close enough to freak me out.
html5_geolocation_watchposition
Click the button to Try it; Share you location with w3schools.com; Modify the script in the other panel of the webpage to suit.
Edit: Sorry, just noticed the "in Python" but will leave it up.

Related

Thruk cgi authentication override

I have the latest version of thruk installed with naemon and livestatus. I want to be able to post commands from a python script to cmd.cgi from the same server without the interference of authentication. I have tried the settings of:
use_authentication=0
default_user_name=thrukadmin
but it doesn't seem to work in the thruk gui. When trying to post to the cgi from the thruk gui I get the error, "I'm sorry Dave......"
Any thoughts on why this not working right? The apache server on that system uses ldap to authenticate to the gui, could this be an issue?
Other thoughts?
It's much easier, you don't even need Thruk in the middle. You can simply write to Naemons command_file.
The external command list at https://www.naemon.org/documentation/developer/externalcommands/ contains an example for every possible command.
Here is a shell snippet which schedules a host downtime:
printf "[%lu] SCHEDULE_HOST_DOWNTIME;host1;1478648441;1478638441;1;0;3600;naemonadmin;This is an example comment.\n" `date +%s` > /var/lib/naemon/naemon.cmd
When using Thruk, you can use thruks cli script to send commands:
thruk r -d comment_data=test /hosts/localhost/cmd/schedule_host_downtime
Authentication is only required if you want to send commands by HTTP.

Azure Container Instances stuck in "Creating" state

Whether I have the azure agent plugin for Jenkins make my container, or if I do it manually, it seems like either way it never enters a running state.
az container create \
--os-type Windows \
--location eastus \
--registry-login-server SERVER.azurecr.io \
--registry-password PASSWORD \
--registry-username USERNAME \
--image namespace/image \
--name jenkins-permanent \
--resource-group devops-aci \
--cpu 2 \
--memory 3.5 \
--restart-policy Always \
--command-line "-jnlpUrl http://host:8080/computer/NAME/slave-agent.jnlp -secret SECRET -workDir \"C:\\jenkins\""
I've gone through all the troubleshooting steps that apply, tried a different region, but to no avail.
Here's a current event that I got which seems to be the most progress I've had yet:
{
"count": 1,
"firstTimestamp": "2017-12-07T03:02:56+00:00",
"lastTimestamp": "2017-12-07T03:02:56+00:00",
"message": "Failed to pull image \"MYREPO.azurecr.io/my-company/windows-agent:latest\": Error response from da
emon: {\"message\":\"Get https://MYREPO.azurecr.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout
exceeded while awaiting headers)\"}",
"name": "Failed",
"type": "Warning"
}
The funny thing is, this event happens before and after one case of the instance working (but unfortunately my entrypoint command was wrong, so it never started).
I really feel like Azure is punting on this and I just have no way to change the order I do anything. It's simply one command.
Alexander, here's a lead to actually check what could be causing the delay, or if the deployment has failed in the background, this information would be critical to narrow down what the issue is: https://learn.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-troubleshoot-tips#determine-error-code
From the article above check on deployment logs:
Enable debug logging:
PowerShell
In PowerShell, set the DeploymentDebugLogLevel parameter to All, ResponseContent, or RequestContent.
New-AzureRmResourceGroupDeployment -ResourceGroupName examplegroup -TemplateFile c:\Azure\Templates\storage.json -DeploymentDebugLogLevel All
or Azure CLI:
az group deployment operation list --resource-group ExampleGroup --name vmlinux
Check Also Check deployment sequence:
Many deployment errors happen when resources are deployed in an unexpected sequence. These errors arise when dependencies are not correctly set. When you are missing a needed dependency, one resource attempts to use a value for another resource but the other does not yet exist.
The above link contains more details. Let me know if this helps.
Figured it out, turns out the backslashes in the command in my executable path were not having their escapes honoured. Either because I was calling az from bash, or because something Azure side isn't handling the escaping correctly, or not escaping them itself.
My solution has been to just use forward slashes in the paths. Windows seems to be handling them correctly, and I prefer to not be bothered with its odd preference for backslashes.
Related to my issue is that the speed of the service makes troubleshooting very difficult. It takes a long time to go round trip with any fixes. So if you're using Azure Container Instances and want better performance, go upvote this feedback item that I've created.
How big is your image? You can always debug with 2 steps.
Run az container show -g devops-aci -n jenkins-permanent. It should contain a list of container events in the container json object. The event message should give you hint what's going on.
Run az container logs -g devops-aci -n jenkins-permanent. It should give you the logs of your container. If it's a problem within your image, you should be able to see some error output.

Apache Solr 5.3.1 basic authentication plugin causing issue

I am able to setup the basic authentication plugin using the blog below, for Apache Solr5.3.1, but nothing happens and I am still able to browse through my Solr admin console using firefox without password.
http://lucidworks.com/blog/2015/08/17/securing-solr-basic-auth-permission-rules/
(http)localhost:8501/solr/#/ instead of (http)localhost:8501/solr/admin/
Also when I place the following curl commands I get different results.
curl (http)localhost:8983/solr/admin/authentication
curl (http)localhost:8983/solr/#/authentication
I think I am missing the admin prefix in the console URL but found no way to change it.
Thanks!
After lot of search & debug I finally found out the error.
The curl command was giving an error like message which I overlooked, something like curl: (3) [globbing] nested brace in column 24.
It seems there was some problem in json parsing so I copied and pasted the exact json sample and modified it precisely while keeping the indentation as is and it worked.
curl --user solr:SolrRocks -H 'Content-type:application/json' -d '{
"set-user": {"yepmeasolrupdateuser":"y08klasd"}
}' http://localhost:8983/solr/admin/authentication
Also I found that !! characters in the password field were causing the curl command not to execute properly.
Thanks anyway.

How to fork transferred data to a script with socat?

I want to analyze the transferred data between a client and a server with socat. I’ve managed to set up socat as a man-in-the-middle with the following command:
socat -x -v OPENSSL-LISTEN:4443,reuseaddr,verify=0,cert=server.crt,key=server.key OPENSSL:server.example:443,verify=0
Although I can see the transferred data, I want to send it to a script to process it for a later analysis.
Does anyone know a solution so that I can send each transferred data packet to a script?
I’ve found a solution that allows to log the transferred data into files using tee:
socat OPENSSL-LISTEN:4443,reuseaddr,verify=0,cert=server.crt,key=server.key,fork SYSTEM:'tee requests | socat - "OPENSSL:server.example:443,verify=0" | tee responses'
This is one step closer to what I’m looking for.

Telnet Automation with Expect: Slow authentication?

I'm sending a command to a Mikrotik router using Telnet.
telnet 192.168.100.100 -l admin
Password: pass1234
[admin#ZYMMA] > /interface pppoe-server remove [find user=aspeed13]
[admin#ZYMMA] > quit
It works fine.
Now I want to automate it using expect tcl script:
#!/usr/bin/expect --
spawn telnet 192.168.100.100
expect "Login:"
send "admin\r"
expect "Password:"
send "pass1234\r"
expect "\[admin#ZYMMA\] >"
send "/interface pppoe-server remove \[find user=aspeed13\]\r"
expect "\[admin#ZYMMA\] >"
send "quit\r"
It works, but after authentication (line 6: send "pass1234\r") when the Router CLI is loading it freezes for ~10seconds with the following characters ^[[?6c^[[24;3R
Then the scripts runs ok.
My question is why Telnet loads fast when accessed manually and it takes too much time when accessed via expect script? I read in forums about telnet automation they say telnet is slow, but since manually it's too fast why it takes time to load with expect?
What you're seeing is blow-back from terminal negotiation, which is because you're not running in a real terminal. (Strictly, you are – that's expect's magic – but it's not behaving as a normal terminal does.)
The easiest fix is to set the terminal to something else before spawning the telnet session, e.g.:
#!/usr/bin/expect --
set env(TERM) dumb
spawn telnet 192.168.100.100
# Rest of your script goes here ...
Alternatively, you could try to respond correctly to the request to enter VT102 mode and the report of the cursor location (which feels like a lot of work) or you could rewrite your code so that it does everything inside interact (which connects the other end with the real terminal that you're running inside). But if setting an environment variable fixes it, why go to all that extra hassle?
(NB: I suggest setting the terminal to dumb here, but the key is that you want the stupidest terminal that works. Dumb terminals are ideal, because they're just about totally stupid, making it easy to pretend to be them…)
My answer is possibly too late. This is "Telnet autoconfig command"...I was this problem and found at Mikrotik Wiki this solution:
Add +t after login name. This switch autodetect to off.
Example:
send "admin+t\r"
It is works great and not "wait cca 10 sec" after login by expect.
There is link to Mikrotik WiKi help with more "switches":
http://wiki.mikrotik.com/wiki/Manual:Console_login_process#FAQ
P.S.: Sorry for my English.
Did you try with netcat, with telnet emulation enabled?
A little bit late to answer.
But if you want to speed up your character input with expect.
Try to generate the script with "autoexpect" command, which will save the
interaction in a file named "script.exp" in the same directory from where
you ran the command.
For instance:
cd $HOME
autoexpect telnet 192.168.100.100
# some more telnet commands here
exit
All the above commands will be saved in ~/script.exp
About Tcl, I don't know if ths script can be ran via tcl.