Skip to content

Instantly share code, notes, and snippets.

View Alireza2n's full-sized avatar

Alireza Amouzadeh Alireza2n

View GitHub Profile
@Alireza2n
Alireza2n / check_pjsip_endpoint.py
Last active July 15, 2021 13:21 — forked from jfinstrom/asterisk.py
Checks for Availablity of a PJSIP endpoint to use with Nagios or similar software, requires python3. Based on portions of jfinstrom/asterisk.py but rewritten using asterisk command.
#!/home/user/check_peers/venv/bin/python
"""
Based on portions of jfinstrom/asterisk.py but rewritten using asterisk command,
checks for Availablity of a PJSIP endpoint to use with Nagios or similar software, requires python3.
Usages: ./check_pjsip_endpoint.py <ext> (e.g. ./check_pjsip_endpoint.py 200)
Output: Endpoint 200 is Available at 200/sip:200@172.16.16.16:5060;transport=ud, is not in use and RTT is 26.426.
"""
import subprocess
@Alireza2n
Alireza2n / README-setup-tunnel-as-systemd-service.md
Created March 11, 2019 10:11 — forked from drmalex07/README-setup-tunnel-as-systemd-service.md
Setup a secure (SSH) tunnel as a systemd service. #systemd #ssh #ssh-tunnel #ssh-forward

README

Create a template service file at /etc/systemd/system/secure-tunnel@.service. The template parameter will correspond to the name of target host:

[Unit]
Description=Setup a secure tunnel to %I
After=network.target
@Alireza2n
Alireza2n / admin.py
Created May 16, 2018 04:49 — forked from reorx/admin.py
Django Admin: hide permission for UserAdmin, exclude useless permissions for GroupAdmin
# coding: utf-8
from django.contrib import admin
from django.contrib.auth.models import Group, User
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.utils.translation import ugettext_lazy as _
class CustomUserAdmin(UserAdmin):
fieldsets = (
@Alireza2n
Alireza2n / squidanonymousproxy.md
Created May 15, 2018 02:34 — forked from RobinDev/squidanonymousproxy.md
Install a SQUID anonymous proxy
  1. Install SQUID
apt-get install squid
  1. Create an user
htpasswd -md /etc/squid3/users myuserlogin`
@Alireza2n
Alireza2n / mixins.py
Created May 6, 2018 04:51 — forked from vst/mixins.py
Some Django model mixins
# Copyright (c) 2012, Vehbi Sinan Tunalioglu <vst@vsthost.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
@Alireza2n
Alireza2n / mixins.py
Created April 23, 2018 09:43 — forked from fabiocerqueira/mixins.py
Success Message Mixin
from django.core.exceptions import ImproperlyConfigured
from django.contrib import messages
class SuccessMessageMixin(object):
success_message = None
def get_success_message(self):
if self.success_message:
@Alireza2n
Alireza2n / models.py
Created December 18, 2017 06:28 — forked from jacobian/models.py
An example of using many-to-many "through" to augment m2m relationships. See http://www.quora.com/How-do-you-query-with-a-condition-on-a-ManyToMany-model-in-Django for context.
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=200)
groups = models.ManyToManyField('Group', through='GroupMember', related_name='people')
class Meta:
ordering = ['name']
def __unicode__(self):
@Alireza2n
Alireza2n / iptables.sh
Created September 13, 2017 08:42 — forked from thomasfr/iptables.sh
iptable rules to allow outgoing DNS lookups, outgoing icmp (ping) requests, outgoing connections to configured package servers, outgoing connections to all ips on port 22, all incoming connections to port 22, 80 and 443 and everything on localhost
#!/bin/bash
IPT="/sbin/iptables"
# Server IP
SERVER_IP="$(ip addr show eth0 | grep 'inet ' | cut -f2 | awk '{ print $2}')"
# Your DNS servers you use: cat /etc/resolv.conf
DNS_SERVER="8.8.4.4 8.8.8.8"
# Allow connections to this package servers
@Alireza2n
Alireza2n / nationalCodeGenerator.py
Last active August 17, 2024 09:53 — forked from omidp/nationalCodeGenerator.java
تولید کننده کد ملی در پایتون
def national_code_generator():
number_list = []
_sum = 0
out = ""
for i in reversed(range(2, 11)):
_j = random.randint(0, 9)
number_list.append(str(_j))
_sum += _j * i
_m = _sum % 11
if _m < 2: