Tech C**P
15 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
How to upgrade Axigen mail server?

The procedure is dead simple! Mail server itself notifies you about the new updates in its admin panel. Head over to the given link and download the the appropriate file related to your OS. Usually a .run file.

1- First make it executable:

chmod +x axigen-10.2.2.x86_64.rpm.run

NOTE: here my version update may differ from yours.

2- Now stop Axigen.

3- Run the installer and go in an interactive way. JUST be sure to skip the Axigen post-install configuration wizard.

4- Now start Axigen.

NOTE: in case you want to take backup copy the folder /var/opt/axigen in a safe place. This path may differ based on your OS and your distro.

#mail_server #axigen #upgrade #update
Have you heard about CORS (Cross Origin Resource Sharing)?

If you know it, but like me you don't know it as you should and every time the bowser gives you a new error in console you again get wandered in the wilderness, I'd suggest going to the awesome link below and read thoroughly line by line:

https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

NOTE: this article is fantastic! Believe you me. You will understand eveything you need to know exactly what is CORS and how to handle it properly.


#browser #mozilla #CORS #cross_origin #cross_origin_resource_sharing
nginX by default does not set CORS headers for requests with error status codes like 401. There are 2 options here to add CORS headers:

1- If your nginX version is new you have the option of always to add to add_header:
add_header 'Access-Control-Allow-Origin' $http_origin always;

2- If you got error of invalid number of arguments in "add_header" directive, then use more_set_headers:
more_set_headers -s '401 400 403 404 500' 'Access-Control-Allow-Origin: $http_origin';

NOTE: when this error happens then in $.ajax or any similar method you wont have access to status codes. So be extremely catious!!!

#nginX #web_server #CORS #more_set_headers #add_header #ajax
How to upload a text content as a file in $.Ajax()?

FormData class is used to create a multipart/form-data inside of JS code. A sample code speaks thousand words:


var formData = new FormData();
var blob = new Blob([YOUR_CONTENT_HERE], { type: "text/html"});
formData.append("file", blob);


We have created a binary data from the text which is in the format of text/html, then I have appended the data as an input file with the name of file (which will be captured on server-side).

The Ajax part is utterly simple:


$.ajax({
type: 'POST',
url: 'https://www.example.com/storage',
data: formData,
processData: false,
contentType: false
}).done(function(data) {});


NOTE: DO NOT OMIT processData, contentType parameters.

#javascript #jQuery #ajax #FormData #Blob #upload
Does that happen for you too, to CD into a wrong directory and need to get back to the previous directory?

Let's say you are in a long path like /mnt/new_volume/backup/files/archive, now you switch to home of your directory. In order to get back to the previous directory, you just need to issue the below command:

cd -

#linux #cd
How to convert ByteArray to PDF and then upload it via jQuery?

var docData = [ yourByteArray ];
var blob = new Blob([new Uint8Array(docData)], { type: 'application/pdf' });

// Now create form to upload the file
var formData = new FormData();
formData.append("file", blob);

// Let's now upload the file
$.ajax({
type: 'POST',
url: 'https://www.YOUR-UPLOAD-FILE-ENDPOINT.com/storage',
beforeSend: request => set_ajax_headers(request),
data: formData,
processData: false,
contentType: false
}).done(function(data) {
console.log('File is uploaded!');
});

NOTE: function set_ajax_headers is a function that sets headers on the given request.

#javascript #ByteArray #PDF #Uint8Array #Blob #jQuery
Forwarded from Pavel Durov
We’ve just started Instant View 2.0 Competition – our crowdsourcing contest with a prize fund of $300,000, ending on the 4th of April.

The goal is to create sets of rules (“templates”) that are used to generate beautiful “Instant View” previews for links shared on Telegram. Anyone with an understanding of HTML/CSS can participate. Participants get $100 for each correct template + $10,000 and $5,000 to top 2 contributors.

Check out the rules here – https://instantview.telegram.org/contest

We’ll launch more similar competitions for developers soon. Eventually there’ll be a competition for everything we do (Android, C++, voice calls etc). Winners get mighty prizes and a chance to join our dev team.

Stay tuned – we’ll announce the next competition within 10 days.
How to SSH login without password?

You want to use Linux and OpenSSH to automate your tasks. Therefore you need an automatic login from host A / user a to Host B / user b. You don't want to enter any passwords, because you want to call ssh from a within a shell script.

How to do it?
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:

a@A:~> ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/a/.ssh/id_rsa):
Created directory '/home/a/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/a/.ssh/id_rsa.
Your public key has been saved in /home/a/.ssh/id_rsa.pub.
The key fingerprint is:
3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A


Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):

a@A:~> ssh b@B mkdir -p .ssh
b@B's password:


Finally append a's new public key to b@B:.ssh/authorized_keys and enter b's password one last time:

a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys'
b@B's password:


From now on you can log into B as b from A as a without password:

a@A:~> ssh b@B


#linux #sysadmin #ssh #password_less #ssh_login
Virt-builder is a tool for quickly building new virtual machines. You can build a variety of VMs for local or cloud use, usually within a few minutes or less. Virt-builder also has many ways to customize these VMs. Everything is run from the command line and nothing requires root privileges, so automation and scripting is simple.

To see available virtual machines:

virt-builder --list


Sample command to create a debian-9 image:

sudo virt-builder debian-9 --size=50G --hostname prod.example.com --network --install network-manager --root-password password:YOUR_PASS


The above command creates a debian 9 image with disk size of 50GB and sets the hostname to prod.example.com. --network enables the networking on guest and --install installs packages on the target O
S. The last parameter sets the root password to YOUR_PASS.

To read more about the axtra parameters:
- http://libguestfs.org/virt-builder.1.html

#linux #sysadmin #virt_builder #debian #image
Enable workmode in Telegram:

open settings in telegram desktop and without clicking anywhere type workmode a dialog will open to confirm that want it to be enabled. After telegram restart you willl have a new bar above chat accounts -> Hide muted chats click on it to hide muted chats from the left pane.

Spread your love for m2sh :)

#telegram #trick #fun #workmode #work_mode
For prometheus you can use an alert manager, it has a docker file in the link below:
- https://hub.docker.com/r/prom/alertmanager

Awesome Prometheus alerts:
- https://github.com/samber/awesome-prometheus-alerts

alertmanager has rules, you can see sample rules here in the following link:
- https://awesome-prometheus-alerts.grep.to/rules

So to add alertmanager service:

alertmanager:
image: prom/alertmanager:latest
restart: always
command: --config.file=/etc/alertmanager/alertmanager.yml
volumes:
- ./alert/config/alertmanager.yml:/etc/alertmanager/alertmanager.yml
dns:
- 8.8.8.8


You alert manager configuration may look something like below:

global:
resolve_timeout: 5m

route:
# When a new group of alerts is created by an incoming alert, wait at
# least 'group_wait' to send the initial notification.
# This way ensures that you get multiple alerts for the same group that start
# firing shortly after another are batched together on the first
# notification.
group_wait: 10s

# When the first notification was sent, wait 'group_interval' to send a betch
# of new alerts that started firing for that group.
group_interval: 5m

# If an alert has successfully been sent, wait 'repeat_interval' to
# resend them.
repeat_interval: 30m

# A default receiver
receiver: "slack"

# All the above attributes are inherited by all child routes and can
# overwritten on each.
routes:
- receiver: "slack"
group_wait: 10s
match_re:
severity: error|warning
continue: true

# - receiver: "sms"
# group_wait: 10s
# match_re:
# severity: error
# continue: true

receivers:
- name: "slack"
slack_configs:
- api_url: 'YOUR-WEBHOOK-URL'
send_resolved: true
channel: 'monitoring'
text: "{{ range .Alerts }}<!channel> {{ .Annotations.summary }}\n{{ .Annotations.description }}\n{{ end }}"

# - name: "sms"
# webhook_config:
# - url: http://a.b.c:8080/send/sms
# send_resolved: true


You should be up & running with this sample configurations.
Spread your love for M2SH :)

#prometheus #prom #alert #alert_manager #docker #dockerfile #slack
Echo: High performance, minimalist Go web framework
- https://echo.labstack.com
- https://github.com/labstack/echo

A sample hello-world web server using Echo:

package main

import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)

func main() {
// Echo instance
e := echo.New()

// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())

// Routes
e.GET("/", hello)

// Start server
e.Logger.Fatal(e.Start(":1323"))
}

// Handler
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
}
Did you know you can use jsonSchema in MongoDB to search for documents?

Let's say you have users collection with data below:

{ "_id" : ObjectId("5f64bd1eca8806f2c04fcbe3"), "customer_id" : 100, "username" : "john" }
{ "_id" : ObjectId("5f64bd1eca8806f2c04fcbe5"), "customer_id" : 206, "username" : "new_customer" }
{ "_id" : ObjectId("60420df441558d6671cf54f2"), "customer_id" : "123", "username" : "Ali" }


Now let's say you want to find all documents that has a customer_id of type string instead of int.
In Mongo shell:

let ms = {required: ["customer_id"], properties: {customer_id: {bsonType: "string"}}}


This schema says look for documents that have customer_id field with string type. To search:

> db.customers.find({$jsonSchema: ms})
{ "_id" : ObjectId("60420df441558d6671cf54f2"), "customer_id" : "123", "username" : "Ali" }


Interesting, right? :)

#database #mongodb #jsonSchema #json_schema
One of the issues you always face with postgres on new systems is pg_config error. If you don't want to install postgres and willing to have postgres library in Pytho operational:

1. brew install libpq
2. xcode-select --install
3. echo 'export PATH="/usr/local/opt/libpq/bin:$PATH"' >> ~/.zshrc
4. env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip3 install psycopg2

#osx #libpq #pg_config #postgres #postgresql #xcode