SSH tunnel to Oracle database

Some companies have a strict security policy to connect with a database. Mostly the acceptance or production databases are accessable trough the specific hosts and ports, but not with your client.
So, if you can connect to such host trough SSH and you are running Linux, the command below could help you:

Linux users

ssh -L 7100:dbserver:1521 user@host

dbserver => The database server where the shema’s reside.
user => The linux user which has access to the linuxhost.
host => The host which had a firewall rule to connect to the databaseserver.
7100 => Your port on your localhost machine to connect to the database. (user ports => 1024-49151)
1521 => The database server connection port.

Now you could connect your client with the database by using:
dbserver = localhost
port = 7100

Poor Micr$s$ft users

You could use Putty to create a tunnel:

putty_tunnel

 

 

 

Advertisements

Oracle Weblogic password reset script

If you want to reset the ‘GOD’ password for Weblogic Server

Start the script and follow instructions

  <path_to_wlst>/wlst.sh resetWLS_password.py

Code for resetWLS_password.py

import datetime
import os
import random
import re
import string
import sys
import traceback

def tempname():
    return "/tmp/resetPassLog" + str(random.randint(1000, 9999))

def shout(cmd, check_returncode=False, check_output=False):
    tmpfile = tempname()
    retval = os.system(cmd + " >" + tmpfile + " 2>&1")
    file = open(tmpfile)
    out = file.read()
    file.close()
    os.system("rm -f " + tmpfile + " >/dev/null 2>&1")
    if check_returncode:
        if retval <> 0:
            print string.strip(out)
            raise Exception("Error: return code " + str(retval) + " from command: " + cmd)
    if check_output:
        if re.search(('ERROR|[Ee]rror|FAIL|[Ff]ail|TIMEOUT|[Tt]imeout'), out):
            print string.strip(out)
            raise Exception("Error message found from command: " + cmd)
    return string.strip(out)

def shlines(cmd):
    return string.split(shout(cmd), "\n")

# RETURN LIST OF PROCESS IDS FROM GREPING PROCESS COMMANDS
def psgrep(str):
    pat = re.compile(str)
    cmd = "ps -e -o pid,command"
    lines = shlines("ps -e -o pid,command")
    pids = []
    for line in lines:
        cols = string.split(line)
        if cols[1] == "grep": continue
        for col in cols[1:]:
            if pat.search(col):
                pids.append(cols[0])
                continue
    return pids
def stop_process_tree(ppid):
    java.lang.Thread.sleep(1)
    pids = get_child_processes(ppid)
    while len(pids) > 0:
        for pid in pids:
            stop_process_tree(pid)
        pids = get_child_processes(ppid)
    kill_process(ppid)
    return

def kill_process(pid):
    if pid == None or pid == '':
        return
    java.lang.Thread.sleep(1)
    if shout("ps -o pid= --pid " + pid) != '':
        os.system("kill " + pid)
    for i in range(30):
        java.lang.Thread.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    os.system("kill -9 " + pid)
    for i in range(30):
        java.lang.Thread.sleep(1)
        if shout("ps -o pid= --pid " + pid) == '':
            return
    error("Cannot kill " + pid)
    return

def get_child_processes(ppid):
    return string.split(shout("ps -o pid= --ppid " + ppid))

#Stop adminserver
def stop_adminserver(name, domain_home):
    print "stopping adminserver " + name
    pids = psgrep("weblogic.Name=" + name)
    for pid in pids:
        stop_process_tree(pid)
    pids = psgrep(domain_home + "/startWebLogic.sh")
    for pid in pids:
        stop_process_tree(pid)
    pids = psgrep(domain_home + "/pointbase.ini")
    for pid in pids:
        stop_process_tree(pid)
    lok = domain_home + "/servers/" + name + "/tmp/" + name + ".lok"
    os.system("rm -f " + lok)
    print "stopped  adminserver " + name
    return ""

def start_adminserver(name, domain_home):
    if len(psgrep(domain_home + "/startWebLogic.sh")) > 0:
        print "adminserver " + name + " already running"
        return ""
    print "starting adminserver " + name
    scriptfile = domain_home + "/startAdminServer.sh"
    outfile = domain_home + "/nohup.out"
    file = open(scriptfile, "w")
    file.write("#!/bin/bash\n")
    file.write(domain_home + "/startWebLogic.sh >" + outfile + " 2>&1 &\n")
    file.close()
    os.system("rm -f " + outfile)
    os.system("chmod 0755 " + scriptfile)
    os.system(scriptfile)
    n = 1900
    while n > 0:
        n = n - 1
        java.lang.Thread.sleep(1)
        file = open(outfile, "r")
        text = file.read()
        file.close()
        if string.find(text, "Server state changed to RUNNING") > -1:
            print "started  adminserver " + name
            return ""
        if string.find(text, "Server state changed to FAILED") > -1:
            errmsg = "ERROR STARTING ADMIN SERVER " + name
            print errmsg
            return errmsg
    errmsg = "ERROR: timeout starting " + name
    return errmsg

##############################
print "Please enter domain data: "
now = datetime.datetime.now()
adminUser = raw_input("Enter Admin user: ")
oldAdminPassword = raw_input("Enter OLD password: ")
newAdminPassword = raw_input("Enter NEW password: ")
url = raw_input("Please, enter url (t3 or http): ")

print "Connection to Oracle Weblogic Adminserver"
connect(adminUser, oldAdminPassword, url)
domainName=cmo.getName()
domainHome = cmo.getRootDirectory()
adminServerName = cmo.getAdminServerName()

cd('/SecurityConfiguration/'+domainName+'/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')
cmo.resetUserPassword(adminUser,newAdminPassword)
disconnect()
print "Adminpassword succesfully changed"
print "Connecting Using New Credentials....."
connect(adminUser,newAdminPassword,url)
print "Successfully Connected Using New Credentials !!!!"
disconnect()

print " Resetting boot.properties "
bootfile = domainHome + "/boot.properties"
f = open(bootfile, "w")
bootfilestr = "Password file changed by reset adminpass script on " + str(now) + "\n"
bootfilestr += "username=" + adminUser + "\n"
bootfilestr += "password=" + newAdminPassword
f.write(bootfilestr)
f.close()
print "Boot.properties succesfully set"
stop_adminserver(adminServerName, domainHome)
os.system("rm " + domainHome + "/servers/" + adminServerName + "/security/boot.properties")
os.system("cp " + bootfile + " " + domainHome + "/servers/" + adminServerName + "/security/")
start_adminserver(adminServerName, domainHome)

Jdeveloper: Remove/edit subversion repo connection

To remove a subversion connection from your jdeveloper installation do this:

1. Navigate to
D:\oracle\middleware\jdeveloper\jdev\bin\Developjdev\system11.1.1.5.37.60.13\o.jdeveloper.subversion

2. Edit or remove the file repositories.xml

 

Oracle Virtual Box Kernel driver not installed (rc=-1908)

To solve this problem run this script as root:

#!/bin/bash
sudo apt-get install linux-headers-$(uname -r)
sudo apt-get remove virtualbox-dkms
sudo apt-get install virtualbox-dkms

Java -xmx -xms total memory set in bash

Use following commands to know how much memory all java processes take of your Linux server with bash. Handy for Oracle Weblogic administrators:

MINIMUM

[oracle@heuring.com ~]$ ps -ef | grep -oh 'Xms[0-9]*' | cut -d's' -f2 | awk '{SUM += $1} END { print SUM}'

MAXIMUM

[oracle@heuring.com ~]$ ps -ef | grep -oh 'Xmx[0-9]*' | cut -d'x' -f2 | awk '{SUM += $1} END { print SUM}'

 

Scala PlayFrameWork 2.04: Get pages dynamically

So you want to generate a page dynamically parsing the url. You could use a map or some hard coded matches. But i prefer to use Java reflection inside Scala.

The code

The HTTP routing file: Routes

GET     /:page       controllers.Director.index(page: String)

The controller: Director.scala

</pre>
package controllers

import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import views._
import models._
import java.util.Properties
import play.api.Play.current
import play.api.libs.iteratee.Enumerator
import java.lang.reflect.Method
import play.api.templates.Html
import models._
import play.api.http.Writeable

object Dynamic {

def render(keyword: String): Option[play.api.templates.Html] = {
 renderDynamic("views.html." + keyword)
 }

def renderDynamic(viewClazz: String): Option[play.api.templates.Html] = {
 try {
 val clazz: Class[_] = Play.current.classloader.loadClass(viewClazz)
 println(clazz.getMethods())
 val render: Method = clazz.getDeclaredMethod("render", classOf[String])
 val view = render.invoke(clazz, "test").asInstanceOf[play.api.templates.Html]
 return Some(view)
 } catch {
 case ex: ClassNotFoundException => Logger.error("Html.renderDynamic() : could not find view " + viewClazz, ex)
 }

return None
 }
}

object Director extends Controller with Secured {

def index(clazz: String) = Action {

 Dynamic.render(clazz) match {
 case Some(i) => Ok(i)
 case None => NotFound
 }
 }
}
<pre>

As you can see i used reflection by using following method: “Play.current.classloader.loadClass(viewClazz)”. Now that i have the class, i can look up the declared methods (Notice the parameters) “clazz.getDeclaredMethod(“render”, classOf[String])”.
Then we are going to invoke it with the params by doing “invoke(clazz, “test”)”. Where “test” is the param of the method. And is actually the @title in the Play! html template below:

The view: template1.html.scala
</pre>
@(title:String)
@main(title){
 <div class="content">
 Here we put some content. .......

 </div>

}
<pre>

Expanding Oracle Enterpise Repository

A nice tool to expand you’re Oracle Repository with functional documentation by Marc Kuijpers:

https://blogs.oracle.com/soacommunity/entry/expanding_the_oracle_enterprise_repository

Oracle JDBC URL types

In Oracle Weblogic we define an url for every datasource. Hereby an overview of the different types URL’s. Note the database service name which points to the RAC listeners.

Simple JDBC Connection String

jdbc:oracle:thin:@localhost:1521:xe

Load-Balanced JDBC Connection String

jdbc:oracle:thin:@(description=(address_list=
(load_balance=on)
(failover=on)
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521))
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521)))
(connect_data=(service_name=rac1)))

Failover JDBC Connection String

jdbc:oracle:thin:@(description=(address_list=
(load_balance=off)
(failover=on)
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521))
(address=(protocol=tcp)(host=dev-database-2.org.com)(port=1521)))
(connect_data=(service_name=rac1)))

Oracle Weblogic WLST console helper!!!

Every Weblogic administrator or WLST developer get’s at some point, close by a psychopathic brain state when using the WLST console. backspaces, arrows and other stuff work like an old school unix server.
The solution: Jline:

To use JLIne with WLST, follow these steps.

  1. Download JLine from http://jline.sourceforge.net/downloads.html
  2. Unzip the file and put the jline jar (current version is jline-0.9.94.jar) into a directory on your machine.
  3. Add the jline jar (current version is jline-0.9.94.jar) to the CLASSPATH
  4. Run JLine as follows:
    java jline.ConsoleRunner weblogic.WLST
    Alternatively, you can copy the $WL_HOME/common/bin/wlst.sh and then add jline.ConsoleRunner before weblogic.WLST

Oracle enterprise Linux 5: Install GIT

For those who are getting to the mext level of versioning and have to use EL5.

1. Get the extra packages for EL5:

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh ./epel-release-5-4.noarch.rpm

wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
rpm -Uvh ./epel-release-5-4.noarch.rpm

2. Use yum to get GIT

yum install git
yum install git-svn