Sunday, December 31, 2023

mac laptop copy paste to iphone not working

 Here are the steps:


  • Open the Terminal app on your Mac (Applications > Utilities)


  • Now, we will first delete Clipboard sharing and then enable it again. Here is how:
defaults delete ~/Library/Preferences/com.apple.coreservices.useractivityd.plist ClipboardSharingEnabled


  • Now, copy and paste this code and hit Enter:
defaults write ~/Library/Preferences/com.apple.coreservices.useractivityd.plist ClipboardSharingEnabled 1


  • Now check if copy and paste is working.



https://discussions.apple.com/thread/254811288?sortBy=best


Friday, October 2, 2020

Wednesday, September 16, 2020

Serve Django3 Applications with Apache2.4 and mod_wsgi on Ubuntu 20

Software versions: here are my application versions:

Python 3.8.2
Django 3.1.1 
Apache/2.4.41 (Ubuntu)
Ubuntu 20.04.1 LTS

Installation:

Step 1: Install apache 2,  Django and other packages

sudo apt-get install libapache2-mod-wsgi-py3
sudo apt-get install python3-pip
sudo pip3 install Django
sudo pip3 install mysql-python
sudo apt-get install python3-mysqldb

Step 2: create Django project - I create project under /var/www, but you may put anywhere, it's up to you

django-admin.py startproject myproject

You will see these files and folder under /var/www/myproject
myproject/
django.wsgi*
manage.py*

Step 3: Create apache vhost file 

cat /etc/apache2/sites-available/xxxx.com.conf

<VirtualHost *:80>

    #My site Name

    ServerName xxxx.com

    DocumentRoot /var/www/myproject

    WSGIDaemonProcess xxxx.com processes=2 threads=5 display-name=%{GROUP} python-path=/usr/local/lib/python3.8

    #Pointing wsgi script to config file

    WSGIScriptAlias / /var/www/myproject/myproject/wsgi.py

    WSGIProcessGroup xxxx.com


    #Your static files location

    Alias /static/ "//var/www/myproject/static/"

    <Location "/media">

        SetHandler None

    </Location>

    <LocationMatch "\.(jpg|gif|png|js|css)$">

        SetHandler None

    </LocationMatch>

    <Directory /var/www/myproject >

        AllowOverride all

        Require all granted

        Options FollowSymlinks

    </Directory>

</VirtualHost>

Step 4: modify this file /var/www/myproject/myproject/wsgi.py

cat /var/www/myproject/myproject/wsgi.py

import os

import time

import traceback

import signal

import sys

from django.core.wsgi import get_wsgi_application

sys.path.append('/var/www/myproject')

sys.path.append('/usr/local/lib/python3.8/dist-packages')


os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CVE.settings')


try:

    application = get_wsgi_application()

except Exception:

    # Error loading applications

    if 'mod_wsgi' in sys.modules:

        traceback.print_exc()

        os.kill(os.getpid(), signal.SIGINT)

        time.sleep(2.5)

Step 5: enable wsgi mod and enable site

sudo a2enmod wsgi
sudo a2ensite xxxx.com

Summary: you may see these errors, please check RED part

mod_wsgi (pid=1059622): Failed to exec Python script file '/var/www/myproject/django.wsgi'.
 mod_wsgi (pid=1059622): Exception occurred processing WSGI script '/var/www/myproject/django.wsgi'.
 Traceback (most recent call last):
   File "/var/www/myproject/django.wsgi", line 12, in <module>
     application = django.core.handlers.wsgi.WSGIHandler()
   File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/wsgi.py", line 127, in 
     self.load_middleware()
   File "/usr/local/lib/python3.8/dist-packages/django/core/handlers/base.py", line 40, in 
     middleware = import_string(middleware_path)
   File "/usr/local/lib/python3.8/dist-packages/django/utils/module_loading.py", line 17, in 
     module = import_module(module_path)
   File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
     return _bootstrap._gcd_import(name[level:], package, level)
   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
   File "<frozen importlib._bootstrap_external>", line 783, in exec_module
   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/middleware.py", line 3, in <
     from django.contrib.auth.backends import RemoteUserBackend
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/backends.py", line 2, in <
     from django.contrib.auth.models import Permission
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/models.py", line 2, in <
     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
   File "/usr/local/lib/python3.8/dist-packages/django/contrib/auth/base_user.py", line 48, in <
     class AbstractBaseUser(models.Model):
   File "/usr/local/lib/python3.8/dist-packages/django/db/models/base.py", line 108, in __new__
     app_config = apps.get_containing_app_config(module)
   File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 252, in 
     self.check_apps_ready()
   File "/usr/local/lib/python3.8/dist-packages/django/apps/registry.py", line 135, in 
     raise AppRegistryNotReady("Apps aren't loaded yet.")
 django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.



Thursday, March 1, 2018

less /var/lib/logrotate/logrotate.status


less /var/lib/logrotate/logrotate.status

Monday, February 19, 2018

MAC "fatal error: 'openssl/opensslconf.h' file not found"


Run these two command to fix it

export CPPFLAGS=-I/usr/local/opt/openssl/include
export LDFLAGS=-L/usr/local/opt/openssl/lib

Thursday, October 12, 2017

corenlp


step 1: tokenize

  java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.process.PTBTokenizer 2-malware.txt > 2-malware.tok

  less 2-malware.tok

Step 2: mark:
  perl -ne 'chomp; print "$_\tO\n"' 2-malware.tok > 2-malware.tsv

Step 3: generate tsv file using customized KEYWORD file

generate final.tsv

Step 4: generate customized NER using malware.prop: => will create malware-ner-model.ser.gz

 java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.ie.crf.CRFClassifier -prop malware.prop

Step 5: using custom NER to detect text

java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.ie.crf.CRFClassifier -loadClassifier  malware-ner-model.ser.gz -testFile sample.tsv.ini


--------------------------------------
java -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.process.PTBTokenizer jane-austen-emma-ch1.txt > jane-austen-emma-ch1.tok

java -mx15g -cp "stanford-corenlp-full-2017-06-09/*" edu.stanford.nlp.pipeline.StanfordCoreNLP -outputFormat json -file jane-austen-emma-ch1.txt


Tuesday, July 25, 2017

transmission 403 unauthorized ip address

When trying to access transmission from web-browswer i got the message :
403: Forbidden
Unauthorized IP Address.
Either disable the IP address whitelist or add your address to it.
If you're editing settings.json, see the 'rpc-whitelist' and 'rpc-whitelist-enabled' entries.
If you're still using ACLs, use a whitelist instead. See the transmission-daemon manpage for details.
I setup whitelist before and it was working fine. So, it is not setting.json issue. I check the log file:
root@ubuntu:~# less /var/log/syslog | grep trans
Jul 25 12:16:48 ubuntu transmission-daemon[26035]: [2017-07-25 12:16:48.151] Couldn't save temporary file "/home/debian-transmission/.config/transmission-daemon/settings.json.tmp.0uKjqQ": No such file or directory (variant.c:1280)
Jul 25 12:16:48 ubuntu transmission-daemon[26035]: Closing transmission session... done.
Jul 25 12:16:49 ubuntu transmission-daemon[26365]: [2017-07-25 12:16:49.422] Couldn't create "/home/debian-transmission": Permission denied (file-posix.c:189)
Jul 25 12:16:49 ubuntu transmission-daemon[26365]: message repeated 2 times: [ [2017-07-25 12:16:49.422] Couldn't create "/home/debian-transmission": Permission denied (file-posix.c:189)]
Jul 25 12:16:49 ubuntu transmission-daemon[26365]: [2017-07-25 12:16:49.422] UDP Failed to set receive buffer: requested 4194304, got 425984 (tr-udp.c:84)
Jul 25 12:16:49 ubuntu transmission-daemon[26365]: [2017-07-25 12:16:49.422] UDP Failed to set send buffer: requested 1048576, got 425984 (tr-udp.c:95)
Jul 25 12:16:49 ubuntu transmission-daemon[26365]: [2017-07-25 12:16:49.422] Couldn't save temporary file "/home/debian-transmission/.config/transmission-daemon/settings.json.tmp.7GNxAD": No such file or directory (variant.c:1280)
Jul 25 12:38:04 ubuntu transmission-daemon[26365]: Closing transmission session... done.
Jul 25 12:38:10 ubuntu transmission-daemon[26698]: [2017-07-25 12:38:10.154] UDP Failed to set receive buffer: requested 4194304, got 425984 (tr-udp.c:84)
Jul 25 12:38:10 ubuntu transmission-daemon[26698]: [2017-07-25 12:38:10.154] UDP Failed to set send buffer: requested 1048576, got 425984 (tr-udp.c:95)
Jul 25 12:38:48 ubuntu transmission-daemon[26698]: Closing transmission session... done.
Somehow, the system looking for /home/debian-transmission/.config/transmission-daemon/settings.json, but my file is located: /etc/transmission-daemon/settings.json I am not sure how this happened, looks like it is transmission bug, but I fixed it:
service transmission-daemon stop
mkdir -p /home/debian-transmission/.config/transmission-daemon
chown debian-transmission:debian-transmission /home/debian-transmission/.config/transmission-daemon
cp /etc/transmission-daemon/settings.json /home/debian-transmission/.config/transmission-daemon/settings.json
service transmission-daemon start

Monday, July 17, 2017

push docker image to ecr

aws ecr create-repository --repository-name my_lamp docker tag my_lamp:latest 953643660.dkr.ecr.us-west-2.amazonaws.com/my_lamp:latest docker push 953643660.dkr.ecr.us-west-2.amazonaws.com/my_lamp:latest

update ruby version

cng@ACP:/opt/newdisk/mydockers/docker-lamp$ source /usr/local/rvm/scripts/rvm cng@ACP:/opt/newdisk/mydockers/docker-lamp$ rvm use 2.4.1 Using /home/chang/.rvm/gems/ruby-2.4.1 cng@ACP:/opt/newdisk/mydockers/docker-lamp$ ruby -v ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]

Wednesday, May 24, 2017

chef 12 opsworks github issue

I had some issue to checkout git repo from private repo.
Took couple of hours to figure it out.

1: add application cookbook in "Berksfile"
cookbook 'application',             '~> 5.2.0'

2: run 
berks update

3: create recipe:

app = search(:aws_opsworks_app).first
app_path = "/srv/#{app['shortname']}"

application app_path do
  git  app['app_source']['url'] do
    deploy_key  app['app_source']['ssh_key']
  end
end


Sunday, May 7, 2017

rails binding to all ip

rails server --binding=0.0.0.0

rails server --binding=0.0.0.0 -d


ROR Dockerfile


FROM ubuntu:16.04

# Set the working directory to /app
WORKDIR /ROR

# Copy the current directory contents into the container at /app
ADD . /ROR

# Install any needed packages specified in requirements.txt
RUN \
  apt-get update && \
  apt-get -y upgrade && \
  apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev nodejs  && \
  mkdir /ROR && \
  cd /ROR && \
  git clone https://github.com/rbenv/rbenv.git ~/.rbenv && \
  echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc && \
  echo 'eval "$(rbenv init -)"' >> ~/.bashrc && \
  exec $SHELL \ &&
  git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build && \
  echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc && \
  exec $SHELL && \
  rbenv install 2.4.0 && \
  rbenv global 2.4.0 && \
  ruby -v

Thursday, May 4, 2017

oozie enable extjs


  327  locate core-site.xml

  330  vim /usr/local/hadoop/etc/hadoop/core-site.xml

<property>
<name>hadoop.proxyuser.hduser.hosts</name>
<value>localhost</value>
</property>
<property>
<name>hadoop.proxyuser.hduser.groups</name>
<value>hadoop</value>
</property>


  331  bin/oozie-setup.sh prepare-war
  332  bin/oozied.sh stop
  333  bin/oozie-setup.sh prepare-war
  334  bin/oozied.sh start

Friday, February 17, 2017

Wednesday, November 9, 2016

load csv into mysql

cng@ACP:/opt/nwdisk/pubm$ mysqlimport --ignore-lines=1 --local -u dg  -p hem CIDCAS

Tuesday, August 23, 2016

snort install

1:  install all the prerequisites

sudo apt-get install -y build-essential libpcap-dev libpcre3-dev libdumbnet-dev bison flex zlib1g-dev


apt-get install pkg-config
apt-get install luajit*
apt-get install libluajit*
apt-get install libssl-dev

ldconfig

ldconfig -v

2: Install DAO (2.1.0 failed for me)

wget https://www.snort.org/downloads/snortplus/daq-2.1.0.tar.gz tar zxvf daq-2.1.0.tar.gz cd daq-2.1.0/ ./configure make make install

3: Install Snort

28 wget https://www.snort.org/downloads/snortdev/snort-2.9.9_beta.tar.gz 29 tar zxvf snort-2.9.9_beta.tar.gz 30 cd snort-2.9.9_beta/ 32 apt-get install luajit* 33 apt-get install libluajit* 34 ldconfig 35 pkg-config 37 apt-get install libssl-dev 38 ldconfig 39 ./configure --enable-file-inspect --enable-open-appid --enable-sourcefire 41 make 42 make install


4:Run the following command to update shared libraries:
1
sudo ldconfig
Since the Snort installation places the Snort binary at /usr/local/bin/snort, it is a good policy to create a symlink to /usr/sbin/snort:
1
sudo ln -s /usr/local/bin/snort /usr/sbin/snort
The last step of our Snort installation is to test that the Snort Binary runs. Execute Snort with the -V flag, which causes Snort to show the version number:
1
/usr/sbin/snort -V
and you should see output similar to the following:
1
2
3
4
5
6
7
8
9
10
11
12
user@snortserver:~$ /usr/sbin/snort -V
   ,,_     -*&gt; Snort! &lt;*-
  o&quot;  )~   Version 2.9.7.6 GRE (Build 285)
   ''''    By Martin Roesch &amp; The Snort Team: http://www.snort.org/contact#team
           Copyright (C) 2014 Cisco and/or its affiliates. All rights reserved.
           Copyright (C) 1998-2013 Sourcefire, Inc., et al.
           Using libpcap version 1.1.1
           Using PCRE version: 8.12 2011-01-15
           Using ZLIB version: 1.2.3.4
user@snortserver:~$
5:# Create the snort user and group:
sudo groupadd snort
sudo useradd snort -r -s /sbin/nologin -c SNORT_IDS -g snort

# Create the Snort directories:
sudo mkdir /etc/snort
sudo mkdir /etc/snort/rules
sudo mkdir /etc/snort/rules/iplists
sudo mkdir /etc/snort/preproc_rules
sudo mkdir /usr/local/lib/snort_dynamicrules
sudo mkdir /etc/snort/so_rules

# Create some files that stores rules and ip lists
sudo touch /etc/snort/rules/iplists/black_list.rules
sudo touch /etc/snort/rules/iplists/white_list.rules
sudo touch /etc/snort/rules/local.rules
sudo touch /etc/snort/sid-msg.map

# Create our logging directories:
sudo mkdir /var/log/snort
sudo mkdir /var/log/snort/archived_logs

# Adjust permissions:
sudo chmod -R 5775 /etc/snort
sudo chmod -R 5775 /var/log/snort
sudo chmod -R 5775 /var/log/snort/archived_logs
sudo chmod -R 5775 /etc/snort/so_rules
sudo chmod -R 5775 /usr/local/lib/snort_dynamicrules


# Change Ownership on folders:
sudo chown -R snort:snort /etc/snort
sudo chown -R snort:snort /var/log/snort
sudo chown -R snort:snort /usr/local/lib/snort_dynamicrules


cd snort-2.9.9_beta/etc
sudo cp *.conf* /etc/snort
sudo cp *.map /etc/snort
sudo cp *.dtd /etc/snort
cd ../src/dynamic-preprocessors/build/usr/local/lib/snort_dynamicpreprocessor/
sudo cp * /usr/local/lib/snort_dynamicpreprocessor/

sudo sed -i "s/include \$RULE\_PATH/#include \$RULE\_PATH/" /etc/snort/snort.conf

sudo vi /etc/snort/snort.conf
ipvar HOME_NET 10.0.0.0/24

Set the following file paths in snort.conf, beginning at line 104:
var RULE_PATH /etc/snort/rules
var SO_RULE_PATH /etc/snort/so_rules
var PREPROC_RULE_PATH /etc/snort/preproc_rules
var WHITE_LIST_PATH /etc/snort/rules/iplists
var BLACK_LIST_PATH /etc/snort/rules/iplists

In order to make testing Snort easy, we want to enable the local.rules file, where we can add rules that
Snort can alert on. Un-comment (remove the hash symbol) from line 545 so it looks like this:
include $RULE_PATH/local.rules

Once the configuration file is ready, we will have Snort verify that it is a valid file, and all necessary files
it references are correct. We use the -T flag to test the configuration file, the -c flag to tell Snort which
configuration file to use, and -i to specify the interface that Snort will listen on (this is a new requirement
for the 2.9.8.x version of snort). Run sudo snort -T -c /etc/snort/snort.conf -i eth0. Run this
command as shown below and look for the following output (only the last few lines of the output are shown
for clarity):
user@snortserver:~✩ sudo snort -T -i eth0 -c /etc/snort/snort.conf
(...)
Snort successfully validated the configuration!
Snort exiting
user@snortserver:~✩

Paste the following single line into the empty local rules file: /etc/snort/rules/local.rules:
alert icmp any any -> $HOME_NET any (msg:"ICMP test detected"; GID:1; sid:10000001; rev:001; classtype:icmp-event;)