From b5a17f11bd25d7f339ebc9341c5e83f4592ba4cd Mon Sep 17 00:00:00 2001 From: Tobias Kessels Date: Thu, 18 Apr 2019 22:38:13 +0200 Subject: [PATCH] added mutliple files added docker_killall alias ; for killing all ontainers of an image added flatpdf docker file ; container for secure pdf flattening added flatpdf.sh ; script for pdf flattening using the flatpdf container added showgm.sh ; opens google maps for exif geo location of picture added showosm.sh ; opens open street map for exif geo location of picture --- aliases | 1 + dockerfiles/flatpdf/Dockerfile | 12 +++ flatpdf.sh | 16 +++ puzzlebox/solve_mp.py | 177 +++++++++++++++++++++++++++++++++ showgm.sh | 4 + showosm.sh | 4 + 6 files changed, 214 insertions(+) create mode 100644 dockerfiles/flatpdf/Dockerfile create mode 100755 flatpdf.sh create mode 100644 puzzlebox/solve_mp.py create mode 100755 showgm.sh create mode 100755 showosm.sh diff --git a/aliases b/aliases index 3b2ce15..4b43ddb 100644 --- a/aliases +++ b/aliases @@ -24,3 +24,4 @@ alias remnux_cyberchef_stop="sudo docker stop cyberchefy" alias remnux_jsdetox_start='sudo docker run --rm --name critsy -it --dns=192.168.130.1 -v ${workdir-`pwd`}:/home/nonroot/workdir -p 8443:8443 remnux/crits' alias remnux_jsdetox_stop="sudo docker stop critsy" alias drit='docker run -it --rm' +function docker_killall() { docker rm $(docker stop $(docker ps -a -q --filter ancestor="${1}" --format="{{.ID}}")) ; } diff --git a/dockerfiles/flatpdf/Dockerfile b/dockerfiles/flatpdf/Dockerfile new file mode 100644 index 0000000..6a60a4f --- /dev/null +++ b/dockerfiles/flatpdf/Dockerfile @@ -0,0 +1,12 @@ +#FROM debian:stretch +#FROM ubuntu:16.04 +FROM alpine +MAINTAINER tabledevil + +RUN adduser -D -u 1000 user user + +RUN apk add -u pdftk + +USER user + +ENTRYPOINT [ "pdftk","-","cat","output","-" ] diff --git a/flatpdf.sh b/flatpdf.sh new file mode 100755 index 0000000..7ce88ee --- /dev/null +++ b/flatpdf.sh @@ -0,0 +1,16 @@ +#!/bin/bash +if ! which zathura 1>/dev/null 2>&1 ; then + echo "zathura pdf viewer not found" + echo "sudo apt install zathura" + exit 1 +fi + +if ! which docker 1>/dev/null 2>&1 ; then + echo "docker not found" + echo "sudo apt install docker.io" + exit 1 +fi + +if [[ -f "${1}" ]] ; then + cat "${1}" | docker run -i --rm tabledevil/flatpdf | zathura - +fi diff --git a/puzzlebox/solve_mp.py b/puzzlebox/solve_mp.py new file mode 100644 index 0000000..c52b3b3 --- /dev/null +++ b/puzzlebox/solve_mp.py @@ -0,0 +1,177 @@ +import pprint +import operator +import numpy as np +import math +from copy import copy, deepcopy +import profile + +piece=[[0,0,0],[0,1,0],[0,2,0],[0,3,0],[1,2,0]] +sizeofcube=5 + +def init_cube(size=sizeofcube): + return [[[0 for x in range(0,size)] for y in range(0,size)] for z in range(0,size)] + +def move_start_position(piece,index): + return [np.subtract(x, piece[index]) for x in piece] + +def draw_cube(cube): + from mpl_toolkits.mplot3d import Axes3D + import matplotlib.pyplot as plt + fig = plt.figure() + ax = fig.gca(projection='3d') + ax.set_aspect('equal') + ax.set_xlabel('x', fontsize=10) + ax.set_ylabel('y', fontsize=10) + ax.set_zlabel('z', fontsize=10) + + ma=np.array(cube) + ax.voxels(ma, edgecolor="k") + plt.show() + +def set_cube_vals(cursors,cube,value): + for cursor in cursors: + cube[cursor[0]][cursor[1]][cursor[2]]=value + +def is_valid(piece,position): + global sizeofcube + upper_x=sizeofcube-position[0] + upper_y=sizeofcube-position[1] + upper_z=sizeofcube-position[2] + for (x,y,z) in piece: + if x<-position[0] or x>upper_x: + return False + if y<-position[1] or y>upper_y: + return False + if z<-position[2] or z>upper_z: + return False + return True + +def put_piece_in_cube(piece,cube,position,index): + if is_valid(piece,position): + # cursors = [np.add(position,p) for p in piece] + # for cursor in cursors: + cursors=[] + for (x,y,z) in piece: + cursor=[(x+position[0]),(y+position[1]),(z+position[2])] + cursors.append(cursor) + try: + if cube[cursor[0]][cursor[1]][cursor[2]]!=0: + return False + except: + return False + set_cube_vals(cursors, cube, index) + return True + else: + return False + +def remove_piece_in_cube(piece,cube,position): + cursors = [np.add(position,p) for p in piece] + set_cube_vals(cursors, cube, 0) + +def rotate_vector(vector,axis,angle): + x,y,z=vector + angle=math.radians(angle) + if axis == "z": + return (int(round((x*math.cos(angle)) - (y*math.sin(angle)))),int(round((x*math.sin(angle)) + (y*math.cos(angle)))),z) + if axis == "y": + return (int(round(x*math.cos(angle) + z*math.sin(angle))),y,int(round(-x*math.sin(angle) + z*math.cos(angle)))) + if axis == "x": + return (x,int(round(y*math.cos(angle) - z*math.sin(angle))),int(round(y*math.sin(angle) + z*math.cos(angle)))) + +def rotate_piece(piece,axis,angle): + return [rotate_vector(x, axis, angle) for x in piece] + +def shift_piece(piece,anchor_index): + anchor=piece[anchor_index] + return [np.subtract(p,anchor) for p in piece] + +def generate_rotations(piece): + all_rotations=set() + for i in range(0,4): + for j in range(0,4): + for k in range(0,4): + for p in range(0,len(piece)): + rotated_piece=rotate_piece(rotate_piece(rotate_piece(shift_piece(piece,p),"x",k*90),"y",j*90),"z",i*90) + all_rotations.add(tuple(rotated_piece)) + return frozenset(all_rotations) + +def find_empty_spot(cube): + for z in range(0,sizeofcube): + for y in range(0,sizeofcube): + for x in range(0,sizeofcube): + if cube[x][y][z]==0: + return (x,y,z) + return None + +def printstats(): + global stat_counter + global stats + stat_counter=stat_counter+1 + if stat_counter%10000==0: + print(stat_counter) + for x in stats: + print("{}:{}".format(x,stats[x])) + if x>5: + break + +def parallel_pool_init(): + global stats + global solutions + stats=dict() + solutions=list() + + +def parallel_solve(cube): + global all_rotations + all_rotations=generate_rotations(piece) + pieces=set(all_rotations.copy()) + first_position=(0,0,0) + while len(pieces)>0: + piece=pieces.pop() + if put_piece_in_cube(piece, cube, first_position, index): + stats["jobid"]={"0"=>len(pieces)} + + solve(cube, 2,): + + +def solve(cube,index,jobid): + global stats + global solutions + global all_rotations + pieces=set(all_rotations.copy()) + + # print("{}:find empty spot#########################".format(index)) + empty_pos=find_empty_spot(cube) + + if empty_pos==None: + pprint.pprint(cube) + draw_cube(cube) + solutions.append(cube) + return False + else: + (x,y,z)=empty_pos + while len(pieces)>0: + #use copy of cube without my parts + piece=pieces.pop() + if put_piece_in_cube(piece, cube, (x,y,z), index): + # print("{}:found fitting piece {} ({} left)".format(index,piece,len(pieces))) + stats[index]=len(pieces) + if solve(cube, index+1): + return True + else: + remove_piece_in_cube(piece, cube, (x,y,z)) + #nothing fits return fail + return False + + +# maxindex=0 +# stat_counter=0 +# stats=dict() +# last_stats=dict() + +def main(): + parallel_solve(init_cube()) + +if __name__ == '__main__': + # profile.run('main()') + main() diff --git a/showgm.sh b/showgm.sh new file mode 100755 index 0000000..8f38afc --- /dev/null +++ b/showgm.sh @@ -0,0 +1,4 @@ +#!/bin/bash +picture="${1}" +url="https://www.google.com/maps/place/$(exiftool -ee -p '$gpslatitude, $gpslongitude' -c "%d?%d'%.2f"\" ${picture} 2> /dev/null | sed -e "s/ //g" -e "s/?/%C2%B0/g")" +firefox -p work "$url" diff --git a/showosm.sh b/showosm.sh new file mode 100755 index 0000000..159b379 --- /dev/null +++ b/showosm.sh @@ -0,0 +1,4 @@ +#!/bin/bash +picture="${1}" +url="https://www.openstreetmap.org/search?query=$(exiftool -ee -p '$gpslatitude, $gpslongitude' -c "%d?%d'%.2f"\" ${picture} 2> /dev/null | sed -e "s/ //g" -e "s/?/%C2%B0/g")" +firefox -p work "$url"