Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ jobs
bin/shptree
bin/gdalwarp
bin/ogr2ogr
venv
5 changes: 4 additions & 1 deletion bin/mapgen-server
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ def main():
{
"tools.encode.on": True,
"tools.encode.encoding": "UTF-8",
"tools.decode.on": True,
"server.socket_host": "0.0.0.0",
"server.socket_port": 9090,
"log.access_file": "",
"log.error_file": "",
}
)
cherrypy.quickstart(
Expand Down
16 changes: 3 additions & 13 deletions container/frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# Creates a mapgen-worker instance for building maps
FROM debian:bullseye-slim
FROM debian:bookworm-slim
ENV MAPFRNT_PKG="ca-certificates python3-cherrypy3 python3-genshi"
ENV NGINX_PKG="nginx"
ENV SUPERVISOR_PKG="supervisor"
ENV DEBIAN_FRONTEND=noninteractive

# Deploy Mapgen
RUN apt-get update && apt-get install -y --no-install-recommends $MAPFRNT_PKG $NGINX_PKG $SUPERVISOR_PKG && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y --no-install-recommends $MAPFRNT_PKG && apt-get clean && rm -rf /var/lib/apt/lists/*

# use git during install only smaller size
COPY lib/ /opt/mapgen/lib/
Expand All @@ -15,15 +13,7 @@ COPY bin/ /opt/mapgen/bin/
## Volume for jobs used by mapgen-worker
VOLUME /opt/mapgen/jobs

# Nginx for reverse proxy
COPY ./container/frontend/files/default /etc/nginx/sites-available/default
RUN ln -fs /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default

EXPOSE 9090

# Supervisord for running two processes inside container
RUN mkdir -p /var/log/supervisor
COPY ./container/frontend/files/supervisord.conf /etc/supervisor/conf.d/supervisord.conf

# Launch supervisord on container startup
CMD ["/usr/bin/supervisord"]
CMD ["/opt/mapgen/bin/mapgen-server"]
2 changes: 1 addition & 1 deletion container/worker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Creates a mapgen-worker instance for building maps
FROM debian:bullseye-slim
FROM debian:bookworm-slim
ENV MAPWRK_PKGS="ca-certificates python3-jsonschema python3-requests p7zip gdal-bin mapserver-bin wget"
ENV DEBIAN_FRONTEND=noninteractive

Expand Down
2 changes: 1 addition & 1 deletion lib/xcsoar/mapgen/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def __download(self, file, dest):
url = self.__base_url + file
if not os.path.exists(os.path.dirname(dest)):
os.makedirs(os.path.dirname(dest))
subprocess.check_call([self.__cmd_wget, "-O", dest, url])
subprocess.check_call([self.__cmd_wget, "-c", "-O", dest, url])

def __remove(self, *files):
for file in files:
Expand Down
8 changes: 6 additions & 2 deletions lib/xcsoar/mapgen/server/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ def error(self):
self.__move(".error")
try:
os.unlink(self.__status_file())
except:
pass
except FileNotFoundError:
logging.warning("Status file not found, unable to delete.")
except PermissionError:
logging.error("Permission denied when trying to delete the status file.")
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")

def done(self):
self.__move()
Expand Down
167 changes: 0 additions & 167 deletions lib/xcsoar/mapgen/server/static/jquery.js

This file was deleted.

46 changes: 35 additions & 11 deletions lib/xcsoar/mapgen/server/static/mapgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,46 @@ draw_box.on("drawend", function(draw_event){
fill_boxes([box_corners[0],box_corners[2]]);
});

// sort coordinates and fill input fields
function fill_boxes(box_coords) {
var coords = [[],[]];
for (i = 0; i < 2; i++) {
coords[i] = ol.proj.transform(box_coords[i],"EPSG:900913","EPSG:4326");
}
coords[i] = ol.proj.transform(box_coords[i],"EPSG:900913","EPSG:4326");
}

var dirs = [["#left","#right"],["#bottom","#top"]];

for (i = 0; i < 2; i++) {
if (coords[0][i] < coords[1][i]) {
$(dirs[i][0]).val(coords[0][i]);
$(dirs[i][1]).val(coords[1][i]);
} else {
$(dirs[i][0]).val(coords[1][i]);
$(dirs[i][1]).val(coords[0][i]);
if (Array.isArray(coords) && coords.length === 2 && Array.isArray(dirs) && dirs.length === 2) {
for (let i = 0; i < 2; i++) {
if (typeof coords[0][i] === 'number' && typeof coords[1][i] === 'number') {
if (coords[0][i] < coords[1][i]) {
const dir1 = dirs[i][0];
const dir2 = dirs[i][1];

// Validate dir1 and dir2 to ensure they are safe selectors
if (isValidSelector(dir1) && isValidSelector(dir2)) {
document.querySelector(dir1).value = coords[0][i];
document.querySelector(dir2).value = coords[1][i];
} else {
console.error("Invalid selector:", dir1, dir2);
}
} else {
console.error("Coordinates one not smaller than coordinates two");
}
} else {
console.error("Invalid coordinate values");
}
}
}
} else {
console.error("Invalid input data");
}

// Function to validate CSS selectors
function isValidSelector(selector) {
try {
document.querySelector(selector);
return true;
} catch (e) {
return false;
}
}
}
1 change: 0 additions & 1 deletion lib/xcsoar/mapgen/server/views/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
<button type="submit">Generate</button>
</div>
</form>
<script src="/static/jquery.js"/>
<script src="https://openlayers.org/en/v4.6.5/build/ol.js"></script>
<script src="/static/mapgen.js"/>
</body>
Expand Down