Ejemplo n.º 1
0
 /**
  * __construct
  *
  * constructor sets up connectivity to servers
  *
  * @since		version 1.0
  * @acess	public
  * @param string $username username
  * @param string $which defaults to prod
  */
 public function __construct($username, $which = 'prod')
 {
     if ($which == 'dev') {
         $which = 'zimbra_dev';
         $this->_dev = true;
     } else {
         $which = 'zimbra';
     }
     // load the following configuration settings via PSU's credential storage mechanism
     require_once 'PSUDatabase.class.php';
     $conf = PSUDatabase::connect('other/' . $which, 'return');
     $this->_preAuthKey = PSUSecurity::password_decode($conf['key']);
     $this->_protocol = $conf['protocol'];
     $this->_server = $conf['server'];
     // end of PSU proprietary configuration load
     /* **** if not PSU, do something similar to the following:
     		$this->_preAuthKey = '<insert key string acquired from Zimbra server>';
     		$this->_protocol = 'https://'; // could also be http://
     		$this->_server = 'zimbra.hostname.edu';
     		*** */
     $this->_username = $username;
     $this->_timestamp = time() . '000';
 }
 /**
  * __construct
  *
  * fixes all the of options for passing up to the parent constructer
  *
  * @param array $options
  */
 function __construct($options = array())
 {
     $conf = PSUDatabase::connect('ldap/password', 'return');
     $conf['password'] = PSUSecurity::password_decode($conf['password']);
     if (empty($options)) {
         $options['account_suffix'] = "@plymouth.edu";
         $options['base_dn'] = $conf['dn'];
         $options['domain_controllers'] = array($conf['hostname'], $conf['hostname2']);
         $options['ad_username'] = $conf['username'];
         $options['ad_password'] = $conf['password'];
         $options['real_primarygroup'] = true;
         $options['use_ssl'] = true;
         $options['recursive_groups'] = true;
     }
     parent::__construct($options);
 }
 /**
  * Connect to a database, or return connection parameters.
  *
  * @since     version 1.0.0
  * @param     string $connect_data Connection identifier(s).
  * @param     string $return Return type. One of: adodb (ADOdb object), mysql (raw mysql_connect() resource), return (connection parameters as an array).
  * @return    mixed See the $return parameter.
  */
 public function connect($connect_data, $return = 'adodb', $memcache = true)
 {
     //if the connect_data is not an array, lets make it one so life is easier
     if (!is_array($connect_data)) {
         $connect_data = array($connect_data);
     }
     //end if
     $dbs = array();
     //loop over connection array and connect to the databases!
     foreach ($connect_data as $key => $connect) {
         $connect = explode('/', $connect);
         //include the db connection info
         include $connect[0] . '/' . $connect[1] . '.php';
         StatsD\StatsD::increment("db.attempt.{$connect[0]}.{$connect[1]}");
         $options = array_slice($connect, 2);
         //decide which object to create
         switch ($return) {
             case 'adodb':
                 require_once 'adodb5/adodb.inc.php';
                 switch ($connect[0]) {
                     case 'oracle':
                         $driver = in_array('fixcase', $options) ? 'oci8po' : 'oci8';
                         break;
                     case 'mssql':
                         $driver = 'mssqlpo';
                         break;
                         // disabled by defautl because ADO_RecordSet::RecordCount() does not work on
                         // PDO connections. PDO supports rowCount(), but ADOdb will not use it unless
                         // $ADODB_COUNTRECS is true. -- ambackstrom, 4 sept 2009
                     // disabled by defautl because ADO_RecordSet::RecordCount() does not work on
                     // PDO connections. PDO supports rowCount(), but ADOdb will not use it unless
                     // $ADODB_COUNTRECS is true. -- ambackstrom, 4 sept 2009
                     case 'mysql':
                         $driver = 'mysql';
                         break;
                         // DEBUG: disabling pdo support for now, it's not enabled on perseus
                         if (!in_array('pdo', $options)) {
                             $driver = 'mysql';
                             break;
                         }
                         $driver = 'pdo';
                         $port = null;
                         $host = $_DB[$connect[0]][$connect[1]]['hostname'];
                         if (strpos($host, ':') !== false) {
                             list($host, $port) = explode(':', $host);
                         }
                         $_DB[$connect[0]][$connect[1]]['hostname'] = 'mysql:host=' . $host . ($port ? ';port=' . $port : '');
                         unset($host, $port);
                         break;
                     default:
                         $driver = $connect[0];
                         break;
                 }
                 //end switch
                 global $ADODB_COUNTRECS;
                 global $ADODB_CACHE_DIR;
                 global $ADODB_FORCE_TYPE;
                 global $ADODB_GETONE_EOF;
                 global $ADODB_QUOTE_FIELDNAMES;
                 $user = posix_getpwuid(posix_geteuid());
                 $ADODB_COUNTRECS = false;
                 $ADODB_CACHE_DIR = '/web/temp/ADOdbCache_' . md5($user['name']);
                 $ADODB_GETONE_EOF = false;
                 $ADODB_QUOTE_FIELDNAMES = true;
                 $ADODB_FORCE_TYPE = ADODB_FORCE_IGNORE;
                 if (!file_exists($ADODB_CACHE_DIR)) {
                     mkdir($ADODB_CACHE_DIR, 0700);
                 }
                 //end if
                 if (!ADODB_PREFETCH_ROWS) {
                     define('ADODB_PREFETCH_ROWS', 50);
                 }
                 $db = ADONewConnection($driver);
                 if (substr($driver, 0, 4) == 'oci8') {
                     $db->_initdate = false;
                     // persistent oracle connections
                     $db->autoRollback = true;
                     // must rollback; don't use existing transaction
                     $connect_method = 'PConnect';
                 } else {
                     $connect_method = 'NConnect';
                 }
                 if (in_array('debug', $options)) {
                     $db->debug = true;
                 }
                 if (in_array('nocache', $options)) {
                     $db->cacheSecs = 0;
                 } else {
                     $db->cacheSecs = 600;
                 }
                 $db->SetFetchMode(ADODB_FETCH_ASSOC);
                 if ($memcache) {
                     $db->memCache = true;
                     $db->memCacheHost = 'sualocin.plymouth.edu';
                     // $db->memCacheHost = $ip1; will work too
                     $db->memCachePort = PSU::isdev() ? 21217 : 11217;
                     // this is default memCache port
                     $db->memCacheCompress = MEMCACHE_COMPRESSED;
                     // Use 'true' to store the item compressed (uses zlib)
                 }
                 // modify some fields so date inserts get hour/minute/second as
                 // well as the date. affects SYSDATE
                 $db->dateformat = $db->NLS_DATE_FORMAT = 'RRRR-MM-DD HH24:MI:SS';
                 $db->fmtDate = "'Y-m-d H:i:s'";
                 $db->fmtTimeStamp = "'Y-m-d H:i:s'";
                 //$db->sysDate = 'TRUNC(SYSDATE)'; // function that returns today's date. this is adodb-oci8's default
                 $connected = $db->{$connect_method}($_DB[$connect[0]][$connect[1]]['hostname'], $_DB[$connect[0]][$connect[1]]['username'], PSUSecurity::password_decode($_DB[$connect[0]][$connect[1]]['password']), $_DB[$connect[0]][$connect[1]]['database']);
                 // need the default PDO MySQL behavior to be non-fixcase, for legacy code
                 if ($connected && $driver === 'pdo' && $connect[0] === 'mysql') {
                     if (in_array('fixcase', $options)) {
                         $db->_connectionID->setAttribute(PDO::ATTR_CASE, PDO::CASE_LOWER);
                     } else {
                         $db->_connectionID->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
                     }
                 }
                 if (!$connected) {
                     StatsD\StatsD::increment("db.failure.{$connect[0]}.{$connect[1]}");
                 }
                 if ($connect[0] == 'oracle') {
                     $sql = "ALTER SESSION SET nls_date_format = 'YYYY-MM-DD HH24:MI:SS'";
                     $db->Execute($sql);
                 }
                 break;
             case 'mysql':
                 $db = mysql_connect($_DB[$connect[0]][$connect[1]]['hostname'], $_DB[$connect[0]][$connect[1]]['username'], PSUSecurity::password_decode($_DB[$connect[0]][$connect[1]]['password']));
                 mysql_select_db($_DB[$connect[0]][$connect[1]]['database'], $db);
                 break;
             case 'return':
                 $db = $_DB[$connect[0]][$connect[1]];
                 break;
         }
         //end switch
         //unset the password so it doesn't appear in debug
         unset($db->password);
         $dbs[$key] = $db;
     }
     //end foreach
     return count($dbs) == 1 ? $dbs[0] : $dbs;
 }
Ejemplo n.º 4
0
 /**
  * workflow
  *
  * constructor initializes SOAP connection to the workflow wsdl
  *
  * @access		public
  * @since		version 0.1.0
  */
 function __construct($in = null)
 {
     if (is_null($in)) {
         if (PSU::isDev()) {
             $which = 'test';
             $domain = 'https://www.dev.plymouth.edu/';
         } else {
             $which = 'psc1';
             $domain = 'https://www.plymouth.edu/';
         }
     } else {
         $which = $in;
     }
     $this->_instance = $which;
     try {
         //$wsdl_url = "https://draco.plymouth.edu/wf".$this->_instance."/ws/services/WorkflowWS/v1_1?WSDL";
         $wsdl_url = $domain . "webapp/workflow/" . $this->_instance . ".wsdl.xml";
         if (PSU::curl($wsdl_url, PSU::FILE_GET_CONTENTS)) {
             $this->_client = new SoapClient($wsdl_url, array('trace' => 1, 'connection_timeout' => 5, 'cache_wsdl' => WSDL_CACHE_MEMORY));
         } else {
             return false;
         }
     } catch (Exception $e) {
         return false;
     }
     $this->_num_soap_calls++;
     include 'oracle/' . $this->_instance . '_wf_webservice.php';
     $this->_authentication = array('principal' => $_DB['oracle'][$this->_instance . '_wf_webservice']['username'], 'credential' => PSUSecurity::password_decode($_DB['oracle'][$this->_instance . '_wf_webservice']['password']));
     // auth string for lookup
 }
 /**
  * Run the specified job.
  * @param $jobname \b string the job name
  * @param $params \b array a list of parameters for BannerJobs::jobValidateParams()
  */
 function runJob($jobname, $params)
 {
     $sql = $this->jobValidateParams($jobname, $params);
     if ($sql) {
         // Populate general.gjbprun with paramters
         foreach ($sql as $cmd) {
             if (!($result = PSU::db('banner')->Execute($cmd['sql'], $cmd['params']))) {
                 $this->error = "SQL Error: " . PSU::db('banner')->ErrorMsg();
                 // Please turn the next two lines into a function if I get used too much ... kthx bye
                 $delete = PSU::db('banner')->Execute("DELETE FROM GJBPRUN WHERE GJBPRUN_ONE_UP_NO = :seqno", array('seqno' => $this->getJobSequenceNumber()));
                 unset($this->job_sequence_number);
                 return false;
             }
         }
         // Execute system command for program to run job
         if (in_array($jobname, $this->_shell_programs)) {
             $sysstr = "sh " . $GLOBALS['BANNER_HOME'] . "/links/" . strtolower($jobname) . ".shl " . $this->_conf['username'] . " " . PSUSecurity::password_decode($this->_conf['password']) . " " . $this->getJobSequenceNumber() . " " . strtoupper($jobname) . " DATABASE";
         } else {
             $sysstr = "echo \"{$this->job_sequence_number}\" | " . $GLOBALS['BANNER_HOME'] . "/general/exe/" . strtolower($jobname) . " -o /u02/SCT/banjobs/" . strtolower($jobname) . "_{$this->job_sequence_number}.lis " . $this->_conf['username'] . "/" . PSUSecurity::password_decode($this->_conf['password']) . " 1> /u02/SCT/banjobs/" . strtolower($jobname) . "_{$this->job_sequence_number}.log 2>&1";
         }
         $result = shell_exec($sysstr);
         unset($this->job_sequence_number);
         if ($retval == 0) {
             return true;
         } else {
             return $retval;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
$GLOBALS['SHOP_EMAIL'] = "*****@*****.**";
$GLOBALS['IP'] = explode(".", $_SERVER['REMOTE_ADDR']);
$sql = "SELECT ip FROM shop_authorized_ips";
$GLOBALS['HD_IPS'] = \PSU::db('systems')->GetCol($sql);
$GLOBALS['IS_HD'] = in_array($_SERVER['REMOTE_ADDR'], $GLOBALS['HD_IPS']);
/*******************[Includes]**********************/
require_once 'xtemplate.php';
//XTemplates
require_once "adldap/adLDAP.php";
// AD integration
require_once "functions.php";
// local functions
/*******************[End Includes]**********************/
if (!isset($GLOBALS['AD'])) {
    $conf = PSUDatabase::connect('ldap/password', 'return');
    $conf['password'] = PSUSecurity::password_decode($conf['password']);
    $options['account_suffix'] = "@plymouth.edu";
    $options['base_dn'] = $conf['dn'];
    $options['domain_controllers'] = array($conf['hostname'], $conf['hostname2']);
    $options['ad_username'] = $conf['username'];
    $options['ad_password'] = $conf['password'];
    $options['real_primarygroup'] = true;
    $options['use_ssl'] = true;
    $options['recursive_groups'] = true;
    $GLOBALS['AD'] = new adLDAP($options);
}
$GLOBALS['SYSTEMS_DB'] = PSU::db('systems');
// do whatever you do to authenticate the user....set the
// username into a session variable.
// at PSU we use phpCAS:
if ($GLOBALS['IS_HD'] || $GLOBALS['IP'][2] == 112 || $GLOBALS['IP'][2] == 114 || $GLOBALS['IP'][2] == 33 || $GLOBALS['IP'][2] == 32 || $GLOBALS['IP'][2] == 115 || $GLOBALS['IP'][2] == 1) {