66# to you under the Apache License, Version 2.0 (the
77# "License"); you may not use this file except in compliance
88# with the License. You may obtain a copy of the License at
9- #
9+ #
1010# http://www.apache.org/licenses/LICENSE-2.0
11- #
11+ #
1212# Unless required by applicable law or agreed to in writing,
1313# software distributed under the License is distributed on an
1414# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@@ -64,7 +64,7 @@ def main(argv):
6464 deletefile (ip , folder , file )
6565 else :
6666 createfile (ip , folder , file , data )
67-
67+
6868 if fpath != '' :
6969 fh .close ()
7070 os .remove (fpath )
@@ -77,7 +77,7 @@ def deletefile(ip, folder, file):
7777
7878def createfile (ip , folder , file , data ):
7979 dest = "/var/www/html/" + folder + "/" + ip + "/" + file
80- metamanifestdir = "/var/www/html/" + folder + "/" + ip
80+ metamanifestdir = "/var/www/html/" + folder + "/" + ip
8181 metamanifest = metamanifestdir + "/meta-data"
8282
8383 # base64 decode userdata
@@ -105,7 +105,7 @@ def createfile(ip, folder, file, data):
105105 sys .exit (1 )
106106 if os .path .exists (metamanifest ):
107107 fh = open (metamanifest , "r+a" )
108- exflock (fh )
108+ exflock (fh )
109109 if not file in fh .read ():
110110 fh .write (file + '\n ' )
111111 unflock (fh )
@@ -121,33 +121,6 @@ def createfile(ip, folder, file, data):
121121 os .chmod (metamanifest , 0644 )
122122
123123def htaccess (ip , folder , file ):
124- entry = "RewriteRule ^" + file + "$ ../" + folder + "/%{REMOTE_ADDR}/" + file + " [L,NC,QSA]"
125- htaccessFolder = "/var/www/html/latest"
126- htaccessFile = htaccessFolder + "/.htaccess"
127-
128- try :
129- os .mkdir (htaccessFolder ,0755 )
130- except OSError as e :
131- # error 17 is already exists, we do it this way for concurrency
132- if e .errno != 17 :
133- print "failed to make directories " + htaccessFolder + " due to :" + e .strerror
134- sys .exit (1 )
135-
136- if os .path .exists (htaccessFile ):
137- fh = open (htaccessFile , "r+a" )
138- exflock (fh )
139- if not entry in fh .read ():
140- fh .write (entry + '\n ' )
141- unflock (fh )
142- fh .close ()
143- else :
144- fh = open (htaccessFile , "w" )
145- exflock (fh )
146- fh .write ("Options +FollowSymLinks\n RewriteEngine On\n \n " )
147- fh .write (entry + '\n ' )
148- unflock (fh )
149- fh .close ()
150-
151124 entry = "Options -Indexes\n Order Deny,Allow\n Deny from all\n Allow from " + ip
152125 htaccessFolder = "/var/www/html/" + folder + "/" + ip
153126 htaccessFile = htaccessFolder + "/.htaccess"
@@ -166,32 +139,14 @@ def htaccess(ip, folder, file):
166139 unflock (fh )
167140 fh .close ()
168141
169- if folder == "metadata" or folder == "meta-data" :
170- entry = "RewriteRule ^meta-data/(.+)$ ../" + folder + "/%{REMOTE_ADDR}/$1 [L,NC,QSA]"
171- htaccessFolder = "/var/www/html/latest"
172- htaccessFile = htaccessFolder + "/.htaccess"
173-
174- fh = open (htaccessFile , "r+a" )
175- exflock (fh )
176- if not entry in fh .read ():
177- fh .write (entry + '\n ' )
178-
179- entry = "RewriteRule ^meta-data/?$ ../" + folder + "/%{REMOTE_ADDR}/meta-data [L,NC,QSA]"
180-
181- fh .seek (0 )
182- if not entry in fh .read ():
183- fh .write (entry + '\n ' )
184- unflock (fh )
185- fh .close ()
186-
187142def exflock (file ):
188143 try :
189144 flock (file , LOCK_EX )
190145 except IOError as e :
191146 print "failed to lock file" + file .name + " due to : " + e .strerror
192147 sys .exit (1 )
193148 return True
194-
149+
195150def unflock (file ):
196151 try :
197152 flock (file , LOCK_UN )
0 commit comments