Kaid Control Pad update?
#46
Figured out the post part. Compared KCP to the original WRTKaidCommander and found differences on the HTTP string.
Code:
KCP:
self.open("http://" + router_ip + "/apply.cgi?"+ parameter)

WKC:
self.open("http://"+router_ip+"/apply.cgi", parameter)
If I remove the question mark after apply.cgi and also change the plus symbol before "parameter" to a comma the script now performs a POST operation. Progress!

Unfortunately, still not working.

It seems that when the script runs a GET process it first receives back a 401 unauthorized message. It then GETs again but passing login credentials and receives back a 200 Ok packet. Once I've made the updates to trigger a POST operation I don't get either of these. I can see in the packet that credentials are not being passed, I'm wondering if maybe on a POST operation there is no 401 response? I can't think of a way to recreate this non-logged in POST from my browser, so I can't confirm if the response would be the same. Is there a way to trigger the urllib to pass the credentials on first request?

I also noticed that the newer versions of DD-WRT send a next_page=Diagnostics.asp string in the POST. I've added that to the version of the script I am working with but it hasn't changed anything.

-Whoopin'
Reply
#47
you are ambitious Smile

Are you saying the new DD-wrt is using a redirect, if so here is some code from the accuweather script. I don't have time to play with it now, but I'm sure you can edit as needed.

Quote:
request = urllib2.Request(self.codeURL + location)
opener = urllib2.build_opener()
usock = opener.open(request)
htmlSource = usock.read()
usock.close()
Reply
#48
I sometimes think of it as "stupidly determined." Big Grin

Not sure what to make of the code you posted, as I'm still at the point where I'm just having a hard time following the logic of python scripts let alone understand what each line is *doing*. Interesting to see that the Accuweather script uses urllib2 tho. From the packet monitoring I've done I think the wall I'm currently up against is that DD-WRT isn't kicking back a 401 error to trigger urllib to try again with credentials. Based on what I've read of urllib on the python.org website this is the logic the lib uses. If I capture all http packets between XBMC and the WRT I'll only see the one POST from XBMC and no reply from the WRT. This isn't working the same as when it does a GET, which is the one GET followed by a 401 reply, then the second authorized GET followed by a 200 reply, then the HTML output. I've posed the question on the DD-WRT forums (http://www.dd-wrt.com/phpBB2/viewtopic.php?t=7996) looking to find out if anyone knows if the 401 error is missing from the POST method of using apply.cgi or if it is normal in form submission that an unauthorized POST just gets no response at all. If it is the former hopefully it is something that Brainslayer can correct in the next beta release of v23 SP3 or v24, but if it is the latter then there is work to be done in the KCP script.

While I am learning bit by bit it is frustrating being in so far over my head. Sure, every now and then I'll hit the needle in the haystack (like figuring out why the script wasn't using POST) but it just leads to another, bigger haystack. Bleh.

-Whoopin'
Reply
#49
Does the accuweather script (or any other script that you are aware of) use POST to a site that requires authorization? If you could point me to one that does I could run it on my Xbox, capture the packets and see if it has a POST/401/POST/200 pattern. If so that nails DD-WRT as the culprit, lacking a 401 response.

-Whoopin'
Reply
#50
I think at this point that unless I find some basic python training I'm stuck. I'm sure it doesn't help that the code I'm looking at probably beyond entry-level. I've found an example that shows how to do automatic authentication with the urllib module but it isn't clear if this is the same "automatic" authentication that is already happening, automatic being that a 401 error comes through. And even if the code would do the test I would like to see, passing authentication on first POST/GET without waiting for the 401, I've got no idea how to put it in place. Does this code work any differently than the code in KCP? Copied from http://www.effbot.org/librarybook/urllib.htm
Code:
import urllib

class myURLOpener(urllib.FancyURLopener):
    # read an URL, with automatic HTTP authentication

    def setpasswd(self, user, passwd):
        self.__user = user
        self.__passwd = passwd

    def prompt_user_passwd(self, host, realm):
        return self.__user, self.__passwd

urlopener = myURLOpener()
urlopener.setpasswd("mulder", "trustno1")

fp = urlopener.open("http://www.secretlabs.com")
print fp.read()
-Whoopin'
Reply
#51
From http://docs.python.org/lib/module-urllib.html
"FancyURLopener subclasses URLopener providing default handling for the following HTTP response codes: 301, 302, 303, 307 and 401. "

I guess that nails the missing 401 as the cause of the failure when posting. Now I just need to either 1) get DD-WRT updated so that unauthorized use of apply.cgi returns a 401 error, or 2) get KCP updated to use a lib and class other than urllib.FancyURLopener that can pass authentication first go. Neither of these I can do on my own. I know each person's time is valuable, but can anyone jump in and help? Even if just to provide insight as to if it is possible to update KCP to a different lib capable of passing authentication to DD-WRT without first receiving a 401 error, and without breaking functionality for other kaid servers?

-Whoopin'
Reply
#52
I just did a rewite of KCP, it's now skinnable, language support and more modulized. It's also a little faster to check status. The only firmware settings i have complete is for Hyper-wrt(tofu/thibor 13)

This does require a newer build of XBMC, it uses the new progressbar in python.

You can grab a copy in the scripting svn. http://xbmc-scripting.googlecode.com/svn/trunk

Currently settings doesn't work, so you either need to edit the kcputil.py file or launch the script, then exit out and edit the q:\\userdata\\script_data\\KCP\\settings.txt file.

I'm interested in see if we can get this to work with DD-wrt and other firmware. I'll need a few things first.

In the routers web page, find where you can Run Command and do these:

ps
ls /path-to-kaid/kaid (successful and unsuccessful)
/path-to-kaid/kaid -V (successful and unsuccessful)

then view the source and post a link or better yet follow the below settings and replace with what is needed for DD-WRT or any firmware other than Hyper-WRT (thibor/tofu 13).

Quote:
{
"url_form": "http://%s/apply.cgi?%s",
"wget_ftp_kaid": "wget ftp://%s:%s@%s/%s -O %s.gz",
"wget_ftp_kaid_conf": "wget ftp://%s:%s@%s/%s -O %s",
"wget_http_kaid": "wget http://%s/%s -O %s.gz",
"wget_http_kaid_conf": "wget http://%s/%s -O %s",
"method": "POST",
"bin_filename": "/tmp/kaid",
"conf_filename": "/tmp/kaid.conf",
"command_key": "command_cmd",
"form_data": { "submit_button": "Command", "submit_type": "start", "change_action": "gozila_cgi", "action": "Apply", "command_cmd": "" },
"ls_command": "ls %s",
"ps_command": "ps",
"kill_command": "killall -9 %s",
"run_command": "%s -s -c %s -d",
"finalize_command": "sleep 3;gunzip %s.gz;sleep 2;chmod +x %s",
"reboot_command": "/sbin/reboot",
"version_command": "%s -V",
"version_regex_pat": "var log = .*\\\\x0a\\\\x0a([0-9a-zA-Z]*)",
"version_command_failed": "not found",
"ls_command_failed": "No such file or directory"
}

The most important are "version_regex_pat" for parsing the version and the command failed values.

If anybody besides me still uses this and would like to get this working for another firmware, let me know.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#53
I thought we had this going with custom settings in DD-WRT already or before Nuka... getting ready to update my router but will give it a try Wink
Image
Reply
#54
Hey Nuka1195, here is the results of the ps in DD-WRT v23 SP3 (03/04/07) std

Code:
PID  Uid     VmSize Stat Command
    1 root        396 S   /sbin/init noinitrd
    2 root            SW  [keventd]
    3 root            SWN [ksoftirqd_CPU0]
    4 root            SW  [kswapd]
    5 root            SW  [bdflush]
    6 root            SW  [kupdated]
   11 root            SW  [mtdblockd]
   14 root        312 S   /sbin/watchdog
   79 root        304 S   resetbutton
  113 root        428 S   /usr/sbin/telnetd
  129 root        304 S   /sbin/wland
24824 root        388 S   dnsmasq --conf-file /tmp/dnsmasq.conf
20462 root        316 S   /tmp/ppp/redial 30
20464 root        452 S   nas -P /tmp/nas.wl0lan.pid -H 34954 -l br0 -i eth1 -A
20468 root       1052 S   httpd -p 80
31757 root        512 S   /usr/sbin/pppd file /tmp/ppp/options.pppoe
31794 root        264 S   igmprt ppp0
31795 root        368 S   process_monitor
31865 root        280 S   /usr/sbin/cron
7759 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7760 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7761 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7762 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7763 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7764 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7765 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7766 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7767 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7768 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7769 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7774 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7775 root       1036 S   kaid -s -d -c /tmp/kaid.conf
7776 root       1036 S   kaid -s -d -c /tmp/kaid.conf
12079 root        488 S   sh -c alias ping='ping -c 3'; eval "ps" > /tmp/ping.l
12080 root        452 R   ps

there seems to be a kaid.conf file in /tmp/kaid.conf and theres also one in /etc/kaid/kaid.cong

hope that helps
Reply
#55
the one in /etc/ i take it, is built in to the firmware.

What I need from the above, is for you to View source and post that. in internet explorer it's view/source not sure with other browsers

What i need if you want to use the builtin version:
1. the location of kaid if it's built in.


Also run the following, then do a view source and post those.
1. ls /tmp/kaid (with kaid not installed in /tmp/
2. /tmp/kaid -V (or wherever you have kaid installed)

I think that would do it.
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#56
Ok, here is the

ls source
http://pastebin.ca/396202

ls /etc/kaid
http://pastebin.ca/396207

ls /usr/sbin
http://pastebin.ca/396208

/usr/sbin/kaid -V
http://pastebin.ca/396212
Reply
#57
Source hasnt been updated as yet... BB if you have this working can you send me a copy...
Image
Reply
#58
i just committed a DD-WRT firmware settings, It'll be luck if it works, but give it a shot. I couldn't test it
For python coding questions first see http://mirrors.xbmc.org/docs/python-docs/
Reply
#59
Well.... Im using v23 sp 2 required minor alterations to some of your paths....

"bin_filename": "/usr/sbin/kaid",
"conf_filename": "/tmp/kaid.conf",
Image
Reply

Logout Mark Read Team Forum Stats Members Help
Kaid Control Pad update?0