Using HTTPS on CherryPY

Here’s CherryPY app configuration for using HTTPS:


cherrypy.config.update({
  'server.ssl_module': 'builtin',
  'server.ssl_certificate': '/opt/myapp/conf/cert/cert.crt',
  'server.ssl_private_key': '/opt/myapp/conf/cert/cert.key',
})

for ssl module module you can use builtin or pyopensll (by installing pyOpenSSL module). Use this command if you want create self sign certificate.

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout cert.key -out cert.crt

Dump & Restore MongoDB With Specified Collection and DB

For example i have collection with name logs and db postfix, the output for dumped DB will be located to /tmp/backupmong


mongodump --out /tmp/backupmong/ --collection logs --db postfix

The command above will generating 2 files .bson and .metadata.json

Here’s the command for restoring the database (collection) by using .bson file.


mongorestore /tmp/backupmong/postfix/logs.bson -d anotherdb -c anotercol

[Zimbra] Sender Restriction to Distribution List

Distribution list in Zimbra is a mail grouping that makes broadcast mail much easier, but in some corporation there is restriction for limiting only for such user that can send mail to distribution list. If you are using zimbra Network Edition you may just using Zimbra Admin Console but CLI still best friend for those who using OSE ūüôā .

Grant user access for account omar@mymail.ok to send to such distribution list

zmprov grr dl distme@mymail.ok usr admin@mymail.ok sendToDistList

Revoking user access.

zmprov rvr dl distme@mymail.ok usr omar@jmymail.ok sendToDistList

Get access list (grants) to distribution list called distme@mymail.ok

zmprov gg -t dl distme@mymail.ok

Note:

  • You must activate Zimbra Milter Service for using this service.
  • i just using grantee-type usr (user) in this example, you may change to another grantee-type if you want to (grp, egp, all, dom, edom, gst, key, pub, email).
  • In every time¬†the rights is changed you must reload mta service by run command zmmtact reload

[Django] Exception AppRegistryNotReady

I Just migrate all projects application into Django version 1.8, all  django apps are migrated smoothly but there is an error in simple my script that using Django ORM (used for background tasks).


...

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.


 

After some searching in google this page helped me. so i just add these line of code on top of my django script.


import django
django.setup()

[ClearOS] Increase Content Filter Performance Using E2Guardian

ClearOS 6 using dansguardian version 2.10 as it’s web content filter service, i’ve been faced dansguardian performance issue in large client usage event though Performance Level has been set to Extra Large,¬†then i’d like to upgrade dansguardian version but it’s seem there is no development activities since 2012.¬†My finding resulted another alternative to dansguardian that has almost exactly has same configuration file, that is e2guardian. most knows as dansguardian’s fork.

e2guardian can be installed by compiling from it’s source code and for increasing performance File Descriptor will be increased until¬†8192 (1024 * 8) due i will pull up e2guardian’s maxchildren.

Continue reading “[ClearOS] Increase Content Filter Performance Using E2Guardian”

Get Trigger Value As Executed Command Line Arguments

As per my previous post about activating xp_cmdshell for executing command line application in SQLServer there is some additional needs other than just executing, we need to get triggered value such as new value or updated or deleted as argument in command line that we want to execute.

we need do some trick because we cannot directly put the trigger value directly on string that contain command that we want to be ran. so the value will be hold in some variable. for example i want to get the value of new project’s name that will be sent to another application with it’s API through Python Script.


CREATE TRIGGER sendToAPI ON projects
FOR INSERT
AS
BEGIN
DECLARE @project_name NVARCHAR(MAX)
DECLARE @runcmd VARCHAR(100)
SELECT @project_name = INSERTED.name FROM INSERTED

SET @runcmd = 'C:\Python27\python.exe C:/pyscripts/inputProject.py '+@project_name

EXEC master..xp_cmdshell @runcmd

end

 

Happy coding ūüôā

Executing Command Line Application On SQLServer

Sometime other than run sql command on trigger we need to run external application to be ran, please note there is some security concern related activating this feature (disabled by default) and there is a delay on your application due there is a locking as long as the executing command line application.

So first of all let’s activate executing command line from sqlserver this function by run this commands.


EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'xp_cmdshell', 1;
GO
RECONFIGURE;
GO

Explanation:

  • EXEC sp_configure ‘show advanced options’, 1;, Allow advance policy to be changed.
  • EXEC sp_configure ‘xp_cmdshell’, 1;, Enabling xp_cmdshell command.

 

Then you can run command run command xp_cmdshell on your SQLServer, here some example running python script when there is new record on table namely karyawan by creating trigger by name panggil.


CREATE TRIGGER panggil ON karyawan
FOR INSERT
AS
BEGIN
EXEC master..xp_cmdshell 'C:\Python27\python.exe C:/pyscripts/notify.py';
END

 

If you want to delete created trigger below then run this command


DROP TRIGGER panggil;

 

If you want dive deeply about SQLServer’s Trigger then i recommend this page to start.