-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpdcam.py
More file actions
151 lines (120 loc) · 4.15 KB
/
httpdcam.py
File metadata and controls
151 lines (120 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python
#-*- encoding: utf8 -*-
import os
import socket
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
try:
from android import Android
except ImportError:
onPC = True
else:
onPC = False
if onPC:
HTWD = '/home/pierre/dev/python/web/one'
else:
HTWD = '/sdcard/sl4a/scripts/spy'
PORT = 8080
class MyHandler(BaseHTTPRequestHandler):
def serve_file(self, content=None,binary=False):
try:
if binary:
f = open(os.curdir + self.path, 'rb')
else:
f = open(os.curdir + self.path)
try:
self.send_response(200)
if content:
self.send_header('Content-type', content)
self.end_headers()
self.wfile.write(f.read())
#f.close()
print "done : %s" % self.path
return
finally:
f.close()
except IOError, error:
print "serving the file failed %s : %s" % (self.path, str(error))
return False
except NameError, error:
print "serving the file failed %s : %s" % (self.path, str(error))
return False
def takePics_1(self):
try:
#capture_location = '/sdcard/sl4a/scripts/www/image_cam.jpg'
capture_location = HTWD + os.sep + 'image_cam.jpg'
print capture_location
droid.cameraCapturePicture(capture_location, True)
return True
except IOError, error:
print "[-] takePics_1 failed : %s" % str(error)
return False
except NameError, error:
print "[-] takePics_1 failed : %s" % str(error)
return False
def do_GET(self):
try:
if self.path == '/':
print
self.path = '/index_.html'
elif self.path == '/image_cam.jpg':
self.serve_file('image/jpeg', binary=True)
success = self.takePics_1()
if success:
print "[+] Took a picture successfully"
else:
print "[-] The shoot FAILED !!"
return
extf = self.path.split('.')[-1]
#print
#print self.path
#print os.curdir
#print os.sep
#print extf
#print
if extf in ['css', 'csv', 'html', 'plain', 'xml']:
self.serve_file('text/'+extf)
elif extf == ['js', 'java', 'javascript']:
self.serve_file('application/javascript')
elif extf in ['jpeg', 'jpg']:
self.serve_file('image/jpeg', binary=True)
elif extf in ['png', 'gif', 'bmp', 'tiff']:
self.serve_file('image/'+extf, binary=True)
elif extf in ['svg']:
self.serve_file('image/svg+xml', binary=True)
else:
self.serve_file()
except IOError:
self.send_error(405,'File Not Found: %s' % self.path)
def getIP():
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("google.com", 80))
IP = s.getsockname()
return s.getsockname()[0]
finally:
s.close()
def main():
try:
if not onPC:
global droid
droid = Android()
server = HTTPServer(('', PORT), MyHandler)
print
print "[#] Kamera-server"
print
print "[#] HTTPServer started on port %d" % PORT
print "[#] \tand local IP : %s" % getIP()
#print "[#] \tand (external)?? IP : %s" % getIP()
print
os.chdir(HTWD)
print "[#] Listing of the current directory : \n\t%s" % os.getcwd()+os.sep
for i in os.listdir(os.curdir):
print "\t\t* %s" % i
print
server.serve_forever()
except KeyboardInterrupt:
print '^C received, shutting down server'
finally:
server.socket.close()
if __name__ == '__main__':
main()