13.05.2015 г.

Simple iptalables allow acces from ip (open for ftp)

#!/bin/bash
#ip 192.168.168.123
IPTABLES=/usr/sbin/iptables
test -x $IPTABLES || exit 5

if [ -z "$1" ];then
   set start
fi


#Case statment
case "$1" in
start)
echo "Looding config "
#load module
modprobe ip_tables
#clearn rule's
$IPTABLES --flush
$IPTABLES --delete-chain
#set default rule for chain
$IPTABLES -P INPUT DROP
$IPTABLES -P OUTPUT DROP
$IPTABLES -P FORWARD DROP
#accept loopback
$IPTABLES -A INPUT -i lo -j ACCEPT
$IPTABLES -A OUTPUT -o lo -j ACCEPT

#$IPTABLES -A INPUT -s 255.0.0.0/8 -j LOG --log-prefix "spoof"
#$IPTABLES -A INPUT -s 255.0.0.0/8 -j DROP
#$IPTABLES -A INPUT -s 0.0.0.0/8 -j LOG --log-prefix "spoof"
#iptalbes -A INPUT -s 0.0.0.0/8 -j DROP
#$IPTABLES -A INPUT -s 192.168.168.100 -LOG --log-prefix "spoof"
#$IPTABLES -A INPUT -s 192.168.168.100 -j DROP
#$IPTABLES -A INPUT -s 192.168.0.0/16 -LOG --log-prefix "spoof"
#$IPTABLES -A INPUT -s 192.168.0.0/16 -j DROP
#Access from ip 192.168.168.108
$IPTABLES -A INPUT -p tcp -j ACCEPT -s 192.168.168.108 --dport 21 -m state --state NEW
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "spoof2"
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
#allow 22,21,80
$IPTABLES -A INPUT -j ACCEPT -m state --state ESTABLISHED,RELATED
$IPTABLES -A INPUT -p tcp -j ACCEPT --dport 22 -m state --state NEW
$IPTABLES -A INPUT -p tcp -j ACCEPT --dport 21 -m state --state NEW
$IPTABLES -A INPUT -p tcp -j ACCEPT --dport 80 -m state --state NEW
$IPTABLES -A INPUT -j LOG --log-prefix "Droped by default"
#outgoing chain rule
$IPTABLES -I OUTPUT 1 -m state --state RELATED,ESTABLISHED -j ACCEPT
#stop ping after firewall configure corect
#$IPTABLES -A OUTPUT -p icmp -j ACCEPT --icmp-type echo request
$IPTABLES -A OUTPUT -p udp --dport 53 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -j LOG --log-prefix "Droped by default"
;;
open_allow)
echo "Danger!!!"
$IPTABLES --flush
$IPTABLES -P INPUT ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
;;
stop)
echo -n "Clean and set default politics"
$IPTABLES --flush
$IPTABLES --delete-chain
;;
status)
echo -e "Query of $IPTABLES is\n"
$IPTABLES --line-number -v --list
;;
*)
echo "This not agrument!!!"
exit 1
;;
esac

12.05.2015 г.

Simple samba share

Add in the end of the file /etc/samba/smb.conf
[samba]
comment = samba_share
path = /real_path/to/share
read only = no
guest ok = no
valid users user1,user2 (or @users for access group user to access samba share folder)


In a above uncheck line:
security user


With root access in new shell write this:
smbpasswd -a user1
If user1 not in group users write this:
usermod -a -G users user1

Create folder /real_path/to/share and write:
chmod -R 770 share
chown -R test:users share

If you whant to check somebody connect in samba share write this:
smbstatus

1.05.2015 г.

Tkinter menu for play movie's found in comouter

#--*-- coding:utf-8 --*--
#-----------Import Some module's-------------------------------------
from Tkinter import *
from tkFileDialog   import askopenfilename
import os, subprocess

#-----------Define Global Variable here------------------------------

#List of variant movie extensions
file_implement=["mkv", "avi", "mp4"]
#Define dictionary for add name and readlpath
real_path=[]
d={}

#-----------Define Function's----------------------------------------

def search_movie():
    """Search for movie in target folder"""
    movie_sr_name=[]
    for root,dirname,filename in os.walk("/home/borko/Video"):
        for movie_file in filename:
            if movie_file.startswith(tuple([i for i in ("Sample", "sample")])):
                continue
        if movie_file.endswith(tuple([i for i in file_implement])):
            d[movie_file]=os.path.join(root,movie_file)    


def Popalni():
    """After start serch_movie insert result in mylist Form"""
    search_movie()
    for i in sorted(d.keys()):
        mylist.insert(END,i)
        mylist.see(END)
        mylist.update()


def choose():
    """Sort dictionary and load real path to movie"""
    firstIndex =  mylist.curselection()[0]
    val =  d[sorted(d.keys())[firstIndex]]
    os.system("%s '"'%s'"'" % ("vlc", val))
 
  
def Open_Directory():
    """Use for add additional file"""
    name = askopenfilename()
    print name


#-----------Tkinter define----------------------------------------
root = Tk()
root.title("Film's playlist")
root.geometry("500x250")
#Scrol bar settings
scrollbar = Scrollbar(root)
scrollbar.pack( side = RIGHT, fill=Y )

#Menu Bar settings
menubar = Menu(root)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Load_All", command=Popalni)
filemenu.add_command(label="Open_Directory", command=Open_Directory)
filemenu.add_command(label="Edit")
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.quit)
menubar.add_cascade(label="Menu", menu=filemenu)
root.config(menu=menubar)

mylist = Listbox(root, yscrollcommand = scrollbar.set , bg="#99CC99")

frame=Frame(root)
frame.pack()
#Label(text="Anchor").pack(side=LEFT)
chooseButton = Button(frame, text="Load_Movie", command=Popalni ,bg="#FFCC00")
chooseButton.pack(side=LEFT,anchor=NW)
chooseButton1 = Button(frame, text="Run_Movie", command=choose, bg="#FFCC00")
chooseButton1.pack(anchor=NW)
mylist.pack( side = LEFT, fill = BOTH, expand=1 )
scrollbar.config( command = mylist.yview )


if __name__ == "__main__":
 mainloop()