• Python ile dosya replace

    php dosylarındaki mysql server ip adresini değiştirmek için kullanmıştım.

    import fileinput, string, sys,os
    Maindir = "/var/vhost"
    OldIP = "123123"
    NewIP = "345345"
    LogFilePath = "test.log"
    def replacemachine(fileName):
    ##################################################################
    file = open(fileName, "r") #Opens the file in read-mode
    text = file.read() #Reads the file and assigns the value to a variable
    file.close() #Closes the file (read session)
    file = open(fileName, "w") #Opens the file again, this time in write-mode
    file.write(text.replace(OldIP, NewIP)) #replaces all instances of our keyword
    # and writes the whole output when done, wiping over the old contents of the file
    file.close() #Closes the file (write session)
    logactions(fileName)
    ##################################################################
    def listdir(ParentPath):
    for f in os.listdir(ParentPath):
    if os.path.isfile(os.path.join(ParentPath,f)):
    if f.rfind(".php") > 0:
    print("file being replaced:",os.path.join(ParentPath,f))
    replacemachine(os.path.join(ParentPath,f))
    print("file replaced:",os.path.join(ParentPath,f))
    else:
    #print("directory:",f)
    listdir(os.path.join(ParentPath,f))
    def logactions(FileName):
    LogStr = FileName + " replace edildi\n"
    LogFile = open(LogFilePath,"a")
    LogFile.write(LogStr)
    if __name__ == "__main__":
    listdir(Maindir)

  • NuSOAP ile Webservis Oluşturmak

    PHP 5 ile gelen SOAP extension yerine NuSOAP ile webservis oluşturmanın getirdiği en büyük kolaylık, NuSOAP’ın kendisinin wsdl dosyasını otomatik oluşturması.

    Bir Webservis en basit şekilde şu şekilde oluşturulabilir;

    
    include('nusoap.php'); // soap kütüphanesini include ettik
    
    $server = new soap_server();
    $server->service->charencoding = 'UTF-8'; // türkçe karakterlerde sorun yasamamak icin karakter seti utf-8 yapıyoruz
    
    $server->configureWSDL('Servis','urn:Servis');
    
    // basit bir fonksiyon yazarsak
    
    function SoapDeneme(){
    
    return array('ilk soap servisim');
    
    }
    
    // yazilan fonksiyonu servise register ediyoruz
    
    $server->register("SoapDeneme",array(),array('return' => 'xsd:string'),'urn:Servis','urn:Servis#SoapDeneme','rpc','encoded');
    
    // servisin gelen datayi islemesi icin servisi baslatiyoruz
    
    $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
    $server->service($HTTP_RAW_POST_DATA);
    exit;
    

    tabiki yukarıdaki benzeri bir servis hiçbir işinize yaramayacaktır; kendi objeleriniz kendi veri tiplerinizi tanımlamanız gerekecektir.
    Kendi veri tipinizi (objenizi) tanımlamak için aşağıdaki addComplexType methodunu kullanmanız gerekiyor.

    $server->wsdl->addComplexType('KendiTipim','complexType','struct','all','',
    array(
    'TipStr' => array('name' => 'TipStr','type' => 'xsd:string'),
    'TipDbl' => array('name' => 'TipDbl','type' => 'xsd:double')
    ));
    

    şeklinde kendi veri tipinizi tanımladıktan sonra bu veritipini bir methoddan döndürmek için ilk önce fonksiyonu aşağıdakine benzer bir şekle getirmeniz gerekiyor;

    function SoapDeneme(){
    return array('TipStr' => 'methoddan donen string','TipDbl' => (double) 1.10);
    }
    

    ardından register ettiğiniz methodu aşağıdaki gibi güncellemek gerekir;

    $server->register("SoapDeneme",array(),array('return' => 'tns:KendiTipim'),'urn:Servis','urn:Servis#SoapDeneme','rpc','encoded');
    

    Yukarıdan anlaşılacağı gibi register methodunun 3. parametresi methodun cevap olarak döndüreceği tipi belirliyor.

    Kodlanacak serviste tabiki sadece veri döndüren fonksiyonlar değil, veri alan ve bu verilere göre işlem yapan fonksiyonlar  da olacaktır; serviste clienttan veri almak için register methodunun ikinci parametresi kullanılır. aşağıdaki fonksiyon client tan ismini alıp Merhaba [Isim] şeklinde cevap döndürür.

    
    function SoapDeneme2($isim){
    
    return array('Merhaba '.$isim);
    
    }
    $server->register("SoapDeneme2",array('isim' => 'xsd:string'),array('return' => 'xsd:string'),'urn:Servis','urn:Servis#SoapDeneme2','rpc','encoded');
    
  • netscaler ‘ a yeni sata disk takmak

    Diyelim ki netscalerinizin sata diski bozuldu yeni bir disk taktınız. Taktığınız sistemin netscalerın anlayacağı şekle çevirmek çevirmek için

    netscaler ‘ a login olun
    Login olduktan sonra shell ‘ e düşün

    > shell
    Copyright (c) 1992-2008 The FreeBSD Project.
    Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
            The Regents of the University of California. All rights reserved.
    

    /flash/.recovery klasörüne giriyoruz

    [email protected] cd /flash/.recovery

    /flash/.recovery klasörüne içine bakalım

    [email protected] /flash/.recovery# ls -la
    total 66572
    drwxrwxrwx  5 root  wheel       512 Jun  4  2007 .
    drwxr-xr-x  6 root  wheel       512 Nov 18 20:33 ..
    drwxrwxrwx  2 root  wheel       512 May  1  2007 Xad2
    drwxrwxrwx  2 root  wheel       512 May  1  2007 Xflash
    drwxrwxrwx  2 root  wheel       512 May  1  2007 boot
    -rw-rw-rw-  1 root  wheel  68088012 May  1  2007 hd.recovery.tgz
    -rw-rw-rw-  1 root  wheel      4380 May  1  2007 rc.flash
    -rw-rw-rw-  1 root  wheel      3055 May  1  2007 rc.manufacture
    -rw-rw-rw-  1 root  wheel      6143 May  1  2007 rc.recovery
    -rw-r--r--  1 root  wheel      1122 Nov 18 20:31 recovery.log
    Manufacturing ad2 for 1200210 started at Mon Jun  4 17:05:32 GMT 2007
    

    rc.recovery dosyasını çalışıtıyoruz.

    [email protected] /flash/.recovery# sh rc.recovery  
    Recovery requested for disk ad2, system 940030
    Attention! Attempt to 'recover' mounted disk ad2!
    Please unmount the disk manually and then type 'exit'!
    Filesystem     Size    Used   Avail Capacity  Mounted on
    /dev/md0c      155M    145M    6.3M    96%    /
    devfs          1.0K    1.0K      0B   100%    /dev
    procfs         4.0K    4.0K      0B   100%    /proc
    /dev/ad0s1a    226M    192M     16M    92%    /flash
    /dev/ad2s1e     66G    749M     60G     1%    /var
    Unmount ad2> 
    

    ad2 diskini seçtiğimizde taktığımız diske formatlayıp eksik dosyaları atacaktır.

    Recovery ad2 for 1200210 started at Mon Jun  4 17:05:32 GMT 2007
    1+0 records in
    1+0 records out
    512 bytes transferred in 0.000106 secs (4825806 bytes/sec)
    fdisk: WARNING line 2: number of cylinders (9964) may be out-of-range
        (must be within 1-1024 for normal BIOS operation, unless the entire disk
        is dedicated to FreeBSD)
    New filesystems have been created
    Using /flash/.recovery/hd.recovery.tgz for ad2s1e data recovery
    /dev/ad2s1e    66G    68M    61G     0%    /var
    /dev/ad2s1a  1004M   126M   798M    14%    /mnt
    
    Recovery ad2 for 940030 started at Fri Nov 18 10:30:10 PST 2011
    1+0 records in
    1+0 records out
    512 bytes transferred in 0.000431 secs (1187768 bytes/sec)
    
    fdisk: WARNING line 2: number of cylinders (9964) may be out-of-range
        (must be within 1-1024 for normal BIOS operation, unless the entire disk
        is dedicated to FreeBSD)
    New filesystems have been created
    Using /flash/.recovery/hd.recovery.tgz for ad2s1e data recovery
    /dev/ad2s1e    66G    69M    61G     0%    /var
    /dev/ad2s1a  1004M   128M   796M    14%    /mnt
    
  • windows icin üretilmiş ssl li linux e çevirmek

    İlk önce issimizden ssl i .pfx olarak export ediyoruz. http://www.slproweb.com/products/Win32OpenSSL.html adresinden makinemize open ssl kuruyoruz.

    Sertifikasiz bir şekilde .pem formatına dönüştürüyoruz.

    openssl.exe pkcs12 -in publicAndprivate.pfx -nocerts -out privateKey.pem

    sertifikayı alıyoru

    openssl.exe pkcs12 -in publicAndprivate.pfx -clcerts -nokeys -out publicCert.pem

    .pem dosyasını rsa ‘ ya çeviriyoruz ve şifreden kuruluyor.

    openssl.exe rsa -in privateKey.pem -out private.pem
  • 20 saniyede 1 cron çalıştırmak

    Linux de crontab ‘ ın servisi cronda iş varmı kontrolunu 1 dakika aralıkla yapmaktadır. Diyelim ki 1 dakikadan daha kısa sürede cron çalıştırmak istiyorsak bunu 2 tane yolu mevcuttur.
    1. yol sleep ile crondaki işlemi uyutmak

    */1 * * * * /home/script
    */1 * * * * sleep 20 && /home/script
    */1 * * * * sleep 40 && /home/script

    2. yol bash script yazmak.

    #!/bin/bash
    while true
    do /home/script
    sleep 20
    done
Posts navigation