public function getValidationSummary() { //load production gip summary if (!file_exists(config()->gip_summary)) { throw new exception("Can't find the gip summary xml: " . config()->gip_summary); } if (file_exists(config()->gip_summary) && filesize(config()->gip_summary) > 0) { $cache_xml = file_get_contents(config()->gip_summary); $gip = new SimpleXMLElement($cache_xml); } else { elog("Can't find the valid gip summary xml: " . config()->gip_summary); } /* //load ITB gip summary (and merge!) if(file_exists(config()->gip_summary_itb)) { $cache_xml_itb = file_get_contents(config()->gip_summary_itb); $this->merge($gip, new SimpleXMLElement($cache_xml_itb)); } else { elog("Can't find the gip summary xml (ignoring): ".config()->gip_summary_itb); } */ $ret = array(); //parse it out foreach ($gip->ResourceGroup as $rg) { $name = (string) $rg->Name; $attrs = $rg->attributes(); $grid_type = $attrs["type"]; //TODO - what should I do with grid type? $ret[$name] = $rg; } return $ret; }
public function isLoggedIn() { // already logged in if (isset($_SESSION['hash'])) { if ($_SESSION['hash'] == md5($this->username . $this->pass . app('request')->ip)) { return true; } else { //hacker or credentials was changed $this->logout(); } // login by cookies } elseif ($this->autologin == 1 && isset($_COOKIE['hash'])) { $hash = md5($this->username . $this->pass . app('request')->ip); if ($_COOKIE['hash'] == $hash) { $_SESSION['hash'] = $hash; elog($this->username . ' is logged on with a cookie'); return true; } else { $this->logout(); elog($this->username . ' is not logged on. Wrong cookie'); sleep(2); } } return false; }
public function cron_update($type) { $this->load->model('grab_model'); $this->load->library('forkjobs'); $sites = $this->grab_model->read_sites(); $self =& $this; if (GRAB_FORK) { $this->db->close(); } foreach ($sites as $row) { $job = function () use(&$self, &$row, $type) { $self->db->reconnect(); $site = $row['name']; $self->load->model('sites/site_' . $site, 'site_model_' . $site); try { $self->{'site_model_' . $site}->execute($type); } catch (Exception $e) { elog('site[' . $site . '] Caught exception: ', $e->getMessage()); } }; if (GRAB_FORK) { $this->forkjobs->add($job); } else { $job(); } } if (GRAB_FORK) { $this->forkjobs->waitall(); $this->db->reconnect(); } $this->grab_model->regen_title_info(); }
public function login($email, $password) { elog(func_get_args(), 'notice'); $this->password = md5($email . $password); $this->email = strtolower($email); $this->load(); session()->start(); if (is_object(session()) && $this->uid) { session()->store('email', $this->email); session()->store('user', serialize($this)); } }
public function query($sql) { $this->sql = $sql; if ($this->result = mysql_query($sql, $this->connection)) { } else { print $sql . "\n<br/>\n"; elog('Query failed: ' . mysql_error() . ' SQL: ' . $this->sql, 'error'); die('Query failed: ' . mysql_error()); } if ($this->log) { log_query($this->sql, $this->vars); } return $this; }
public function query($sql) { $this->sql = $sql; if ($this->result = mysql_query($sql, $this->connection)) { } else { elog('Query failed: ' . mysql_error() . ' SQL: ' . $this->sql, 'error'); $res = array('status' => 500, 'msg' => '', 'sql' => $sql); $res['msg'] = 'Query failed: ' . mysql_error(); die(json_encode($res)); } if ($this->log) { log_query($this->sql, $this->vars); } return $this; }
private function load4sq() { $json = $this->foursquare->GetPublic('venues/' . $this->id); $response = json_decode($json); if (!is_object($response)) { elog($json); return false; } if ($response->meta->code != 200) { return false; } $response = $response->response->venue; $this->name = $response->name; $this->data = $response; $this->updated = time(); $this->lat = $response->location->lat; $this->lng = $response->location->lng; $this->save(); }
function sendSMS($users, $subject, $body) { $recipient = ""; foreach ($users as $user) { if (isset(config()->sms_address[$user])) { if ($recipient != "") { $recipient .= ", "; } $recipient .= config()->sms_address[$user]; } else { elog("couldn't find user {$user} in sms_address configuration"); } } $Name = config()->app_name; $email = "*****@*****.**"; //senders e-mail adress $header = "From: " . $Name . " <" . $email . ">\r\n"; mail($recipient, $subject, $body, $header); slog("Sent SMS notification to {$recipient} user:" . print_r($users, true)); }
public function get() { //shiould take less than 5 seconds to pull this data $ctx = stream_context_create(array('http' => array('timeout' => 5))); //load OpenTickets XML $c = new Cache(config()->gocticket_open_cache); if (!$c->isFresh(60)) { try { slog("loading " . config()->gocticket_open_url); $xml = file_get_contents(config()->gocticket_open_url, 0, $ctx); //try parsing it.. $obj = new SimpleXMLElement($xml); //store good xml $c->set($xml); return $obj; } catch (exception $e) { elog($e->getMessage() . " -- using cache."); } } slog("Using cache"); return new SimpleXMLElement($c->get()); }
public function render_image($params) { $params['referer'] = isset($params['referer']) ? $params['referer'] : False; $params['thumbnail'] = isset($params['thumbnail']) ? $params['thumbnail'] : False; $params['type'] = isset($params['type']) ? $params['type'] : 'jpeg'; if ($params['referer']) { $this->CI->curl->referer($params['referer']); } $image = $this->CI->curl->url($params['url'])->proxy($this->read_proxys())->add()->get(); $reasonable_size = $params['thumbnail'] ? 1024 : 1024 * 10; if (strlen($image) < $reasonable_size || strlen($image) == 36974) { elog('grab_model - image error, url=' . $params['url']); return False; } $offset = 3600 * 24 * 30; // calc the string in GMT not localtime and add the offset header_remove('Pragma'); $this->CI->output->set_header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', time() + $offset)); $this->CI->output->set_header('Cache-Control: max-age=' . $offset); $this->CI->output->set_content_type('image/' . $params['type']); $this->CI->output->set_output($image); return True; }
public function errorAction() { $errors = $this->_getParam('error_handler'); switch ($errors->type) { case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER: case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION: // 404 error -- controller or action not found //$this->getResponse()->setRawHeader('HTTP/1.1 404 Not Found'); //looks like this gets overriden by render() $this->render('404'); break; default: //application error !! $exception = $errors->exception; $log = ""; $log .= "Error Message ---------------------------------------\n"; $log .= $exception->getMessage() . "\n\n"; $log .= "Stack Trace -----------------------------------------\n"; $log .= $exception->getTraceAsString() . "\n\n"; $log .= "Server Parameter ------------------------------------\n"; $log .= print_r($_SERVER, true) . "\n\n"; if (config()->debug) { $this->view->content = "<pre>" . $log . "</pre>"; } else { $this->view->content = "Encountered an application error.\n\n"; $this->view->content .= "<div style=\"padding: 10px;\"><pre>" . $exception->getMessage() . "</pre></div>"; $this->view->content .= "Detail of this error will be sent to GOC for further analysis."; /* if(config()->elog_email) { mail(config()->elog_email_address, "[myosg] Error: ".$exception->getMessage(), $log, "From: ".php_uname('n')); $this->view->content .= "Detail of this error has been sent to the development team for further analysis."; } */ } elog($log); break; } }
/** * detach设计师 */ $app->put('/cp/detach/:id/:cid', function ($id, $cid) use($app) { if (empty($cid)) { echo '{"error":{"text":"empty cp id"}}'; return; } $sql = 'update tb_require set cp_desginer =' . $cid . ' where require_id =' . $id . ' limit 1'; try { $db = getConnection(); $stmt = $db->prepare($sql); $stmt->execute(); $db = null; echo '{"ret":"success"}'; elog("detach cp desginer " . $sql); } catch (PDOException $e) { echo '{"error":{"text":"' . $e->getMessage() . '"}}'; } }); /** * cp设计师数据 */ $app->put('/desgin/:id/:user/:state', function ($id, $user, $state) use($app) { switch ($state) { case 4: $sql = "select tb_require.*,tb_rank.*,tb_type.*,tb_cp.*,tb_users.english_name,tb_users.user_qq,tb_users.user_phone from tb_require\n INNER JOIN tb_rank ON tb_require.require_rank_id=tb_rank.rank_id\n INNER JOIN tb_type ON tb_type.type_id=tb_require.require_type_id\n INNER JOIN tb_users ON tb_users.login_name=tb_require.require_creator\n LEFT JOIN tb_cp ON tb_cp.cp_id=tb_require.require_cp_id where `is_del` = 0 and\n cp_desginer = '{$user}' and require_cp_id = " . $id . " and require_desgin_attachment is null\n and require_state = 4 and `is_email` IS NOT NULL and\n DATE_FORMAT(tb_require.require_finish_date,'%Y-%m-%d') <= date(now()) order by `require_add_time` desc"; break; case 9: $sql = "select tb_require.*,tb_rank.*,tb_type.*,tb_cp.*,tb_users.english_name,tb_users.user_qq,tb_users.user_phone from tb_require\n INNER JOIN tb_rank ON tb_require.require_rank_id=tb_rank.rank_id\n INNER JOIN tb_type ON tb_type.type_id=tb_require.require_type_id\n INNER JOIN tb_users ON tb_users.login_name=tb_require.require_creator\n LEFT JOIN tb_cp ON tb_cp.cp_id=tb_require.require_cp_id where `is_del` = 0 and\n cp_desginer = '{$user}' and require_cp_id = " . $id . " and require_desgin_attachment is null\n and require_state = 9 order by `require_add_time` desc"; break;
ini_set('default_charset', 'UTF-8'); ini_set('default_socket_timeout', 120); remove_quotes(); fix_eol(); setup_logs(); greet(); cert_authenticate(); /* if(!date_default_timezone_set(user()->getTimeZone())) { addMessage("Your timezone '".user()->getTimeZone()."' is not valid. Please try using location based timezone such as 'America/Chicago'. Reverting to UTC."); } */ error_reporting(E_ALL | E_STRICT); } catch (exception $e) { /* //when a catastrohpic failure occure (like disk goes read-only..) emailing is the only way we got.. if(!config()->debug) { mail(config()->elog_email_address, "[gocticket] Caught exception during bootstrap", $e, "From: ".config()->email_from); } */ header("HTTP/1.0 500 Internal Server Error"); echo "Boot Error"; echo "<pre>" . $e->getMessage() . "</pre>"; elog($e->getMessage()); exit; } //dispatch $frontController = Zend_Controller_Front::getInstance(); $frontController->setControllerDirectory('app/controls'); $frontController->dispatch(); //slog("-- end --------------------------------------------------------------");
function getDefaultMAUrls($fqdn, $sids) { //override all fqdn if pfds fqdn is set if (isset($_REQUEST["psds"])) { $fqdn = $_REQUEST["psds"]; } //for backward compability with "pf" if (isset($_REQUEST["pfds"])) { $fqdn = $_REQUEST["pfds"]; } $mas = array(); foreach ($sids as $sid) { switch ($sid) { case 130: $mas[] = array("read_url" => "http://{$fqdn}/esmond/perfsonar/archive/", "type" => "perfsonarbuoy/bwctl"); $mas[] = array("read_url" => "http://{$fqdn}/esmond/perfsonar/archive/", "type" => "perfsonarbuoy/traceroute"); break; case 131: $mas[] = array("read_url" => "http://{$fqdn}/esmond/perfsonar/archive/", "type" => "perfsonarbuoy/owamp"); break; default: elog("unknown sid:{$sid} while constructing default ma for {$fqdn}"); } } return $mas; }
$paths = exec_hook('routes'); foreach ($paths as $module_name => $module) { current_module($module_name); if (array_key_exists($path, $module)) { $callback = $module[$path]; $access = true; if (isset($callback['access_callback']) && function_exists($callback['access_callback'])) { $access = call_user_func_array($callback['access_callback'], $args); } if ($access) { if (isset($callback['callback']) && function_exists($callback['callback'])) { $returned = call_user_func_array($callback['callback'], $args); print $returned; } else { $status = 500; elog('either callback is not set or is invalid', 'error', 'bootstrap'); } } else { $status = 403; } } } $contents = ob_get_contents(); ob_end_clean(); //this is a lame way to determine a 404, need to fix this if (!empty($contents)) { $status = 200; print $contents; } else { if (!$status) { print call_user_func($paths['pages']['404']['callback']);
break; case 'diagram': if (!isset($dt)) { printf('Data type (-dt) not set. Defaulting to \'sloc:complexity\'%s', PHP_EOL); $dt = 'sloc:complexity'; } if (!isset($ds)) { printf('Data scales (-ds) not set. Defaulting to \'log:log\'%s', PHP_EOL); $ds = 'log:log'; } $reporter = new DiagramReporter($data, $report_f, $dt, $ds); break; case 'db': $reporter = new DatabaseReporter($data, $report_f); break; case 'xml': $reporter = new XMLReporter($data, $report_f); break; default: usage(); } echo "Writing {$reporter->describe()} report.\n"; try { $reporter->report(); } catch (Exception $e) { elog($e->getMessage(), 'Error'); exit(1); } if ($report_f !== '/dev/null') { printf('Report written to \'%s\'.%s', $report_f, PHP_EOL); }
private function parse_chapters() { if (preg_match_all("/comics\\/\\d+o(\\d+)\\/'>([^<]+)/", $this->html, $matches, PREG_SET_ORDER)) { $isset = []; foreach ($matches as $row) { if (!isset($isset[$row[1]])) { $isset[$row[1]] = True; $result[] = ['uri' => $row[1], 'chapter' => $this->chapter_fix($row[2])]; } } return $result; } else { elog('site_' . $this->siteName . ' - Error Chapter Parsing.'); } }
function detail($rec_id, $host, $port, $base) { $conn = ldap_connect($host, $port); $rec_id = explode(",", $rec_id); if (!isset($rec_id[1])) { elog("rec_id looks strange:" . print_r($rec_id, true) . " for {$host} {$port} {$base}"); } //access protocols $results = ldap_search($conn, "GlueClusterUniqueID=" . $rec_id[0] . "," . "Mds-Vo-name=" . $rec_id[1] . "," . $base, "(objectClass=GlueSubCluster)"); //slog("ldap_search for cluster aggregator:"."GlueClusterUniqueID=".$rec_id[0].","."Mds-Vo-name=".$rec_id[1].",".$base); $entries = ldap_get_entries($conn, $results); $subrecs = array(); if ($entries[0] > 0) { foreach ($entries as $entry) { if (is_array($entry)) { #error_log(print_r($entry["gluehostapplicationsoftwareruntimeenvironment"], true)); //create env list $env = "<div style=\"max-height: 150px; overflow-y: scroll;\"><ul>"; foreach ($entry["gluehostapplicationsoftwareruntimeenvironment"] as $id => $value) { if ($id == "count") { continue; } $env .= "<li>{$value}</li>"; } $env .= "</ul></div>"; $subrecs[] = array(null, "<div class=\"dot\">" . $entry["gluesubclusteruniqueid"][0] . "</div>", (int) $entry["gluesubclusterlogicalcpus"][0], (int) $entry["gluesubclusterphysicalcpus"][0], (int) $entry["gluehostmainmemoryramsize"][0], $entry["gluehostoperatingsystemname"][0] . " " . $entry["gluehostoperatingsystemrelease"][0], $entry["gluehostprocessormodel"][0], $env); } else { //why wouldn't it be an array? //$protocols.="<pre>".print_r($entry, true)."</pre>"; } } } //cluster detail $results = ldap_search($conn, "GlueClusterUniqueID=" . $rec_id[0] . "," . "Mds-Vo-name=" . $rec_id[1] . "," . $base, "(objectClass=GlueCluster)"); #error_log("ldap: GlueClusterUniqueID=".$rec_id[0].","."Mds-Vo-name=".$rec_id[1].",".$base); $entries = ldap_get_entries($conn, $results); $entry = $entries[0]; $detail = ""; $detail .= "<b>Cluster Temp Directory</b> " . $entry["glueclustertmpdir"][0] . "<br>"; $detail .= "<b>Cluster Worker Node Temp Directory</b> " . $entry["glueclusterwntmpdir"][0] . "<br>"; $assoc = ""; $token = "GlueCEUniqueID="; for ($id = 0; $id < $entry["glueforeignkey"]["count"]; ++$id) { $key = $entry["glueforeignkey"][$id]; if (strpos($key, $token) === 0) { $assoc .= "<div class=\"dot\">" . substr($key, strlen($token)) . "</div>"; } } $out = "<div class=\"row-fluid\">"; $out .= "<div class=\"span6\"><h3>Detail</h3>" . $detail . "</div>"; $out .= "<div class=\"span6\"><h3>Associated CEs</h3>" . $assoc . "</div>"; $out .= "</div>"; return array("status" => "OK", "subrecords" => $subrecs, "info" => $out); }
public function getWLCGSites($key_fqdns) { if (empty($key_fqdns)) { return array(); } $oim = db("oim"); $pkeys = array(); //dlog($key_fqdns, "key"); foreach ($key_fqdns as $key_fqdn) { $pkeys[] = $key_fqdn["primary_key"]; } //first load all endpoints $sql = "SELECT * FROM wlcg_endpoint WHERE primary_key in (" . implode($pkeys, ",") . ")"; $endpoints = $oim->fetchAll($sql); if (empty($endpoints)) { return array(); } //get all sites we need $site_ids = array(); foreach ($endpoints as $endpoint) { $site_ids[] = $oim->quote($endpoint->site_id); } $sql = "SELECT * FROM wlcg_site WHERE primary_key IN (" . implode($site_ids, ",") . ")"; $sites = $oim->fetchAll($sql); if (empty($sites)) { return array(); } //now, put everything together site/resource $org = array(); foreach ($sites as $site) { //look for all resources under this site $site_endpoints = array(); foreach ($endpoints as $endpoint) { if ($endpoint->site_id == $site->primary_key) { //convert service_type to array of sid $sid = null; switch ($endpoint->service_type) { case "net.perfSONAR.Bandwidth": $sid = 130; $endpoint->service_type = "BW"; break; case "net.perfSONAR.Latency": $sid = 131; $endpoint->service_type = "LAT"; break; default: elog("unknown wlcg endpoint service type :" . $endpoint->service_type); } $endpoint->sids = array($sid); //even though there could be multiple endpoint (with different primary_key) //with the same hostname with different service type, I need to dedupe by //hostname instead of primary key because mesh config are keyed by hostname //and we can only list each hostname once under /site. if (isset($site_endpoints[$endpoint->hostname])) { //merge sid $current = $site_endpoints[$endpoint->hostname]; $current->sids = array_merge($current->sids, $endpoint->sids); $current->service_type .= " & " . $endpoint->service_type; } else { $site_endpoints[$endpoint->hostname] = $endpoint; } } } $site_admin = array("email" => $site->contact_email); $org[$site->primary_key] = array("detail" => $site, "endpoints" => $site_endpoints, "admin" => $site_admin); } return $org; }
public function load() { parent::load(); $this->view->rgs = $this->rgs; //pull commonly needed information $gridtype_model = new GridTypes(); $this->view->gridtypes = $gridtype_model->getindex(); $model = new ResourceGroup(); $this->view->resourcegroups = $model->getgroupby("id"); /////////////////////////////////////////////////////////////////////////////////////////// //pull other optional stuff if (isset($_REQUEST["summary_attrs_showservice"])) { $servicetype_model = new Service(); $this->view->servicetypes = $servicetype_model->getindex(); $resourceservice_model = new ServiceByResourceID(); $this->view->resource_services = $resourceservice_model->getindex(); //load details (all of them for now..) and attach it to resource_services $detail_model = new ResourceServiceDetail(); $resource_service_details = $detail_model->get(); foreach ($this->view->resource_services as $rid => $services) { foreach ($services as $service) { $service->details = array(); //search for details for this service foreach ($resource_service_details as $detail) { if ($detail->resource_id == $rid && $detail->service_id == $service->service_id) { $service->details[$detail->key] = $detail->value; } } } } } if (isset($_REQUEST["summary_attrs_showrsvstatus"])) { $model = new LatestResourceStatus(); $this->view->resource_status = $model->getgroupby("resource_id"); $downtime_model = new Downtime(); $this->view->downtime = $downtime_model->getindex(array("start_time" => time(), "end_time" => time())); } if (isset($_REQUEST["summary_attrs_showgipstatus"])) { $model = new LDIF(); $this->view->gipstatus = $model->getValidationSummary(); } if (isset($_REQUEST["summary_attrs_showvomembership"])) { $cache_filename = config()->vomatrix_xml_cache; $cache_xml = file_get_contents($cache_filename); $vocache = new SimpleXMLElement($cache_xml); $resourcegrouped = $vocache->ResourceGrouped[0]; $this->view->vos_supported = array(); $this->view->vos_errors = array(); foreach ($resourcegrouped as $resource) { $attr = $resource->attributes(); $resource_id = (int) $attr->id; $this->view->vos_supported[$resource_id] = $resource->Members[0]; $this->view->vos_errors[$resource_id] = $resource->ErrorMessage[0]; } } if (isset($_REQUEST["summary_attrs_showvoownership"])) { $model = new ResourceOwnership(); $this->view->resource_ownerships = $model->getindex(); } if (isset($_REQUEST["summary_attrs_showwlcg"])) { $model = new ResourceWLCG(); $this->view->resource_wlcg = $model->getindex(); //append bdii link foreach ($this->rgs as $rg_id => $rg) { foreach ($rg as $resource_id => $resource) { //get resource group name $rgroup = $this->view->resourcegroups[$rg_id][0]; $rgname = $rgroup->name; if (isset($this->view->resource_wlcg[$resource_id][0])) { $this->view->resource_wlcg[$resource_id][0]->ldap_url = "ldap://is.grid.iu.edu:2180/mds-vo-name={$rgname},o=grid"; } } } } if (isset($_REQUEST["summary_attrs_showenv"])) { $model = new ResourceEnv(); $details = $model->getindex(array("metric_id" => 0)); $this->view->envs = array(); //convert to XML String to SimpleXMLElement object foreach ($this->rgs as $rg) { foreach ($rg as $resource_id => $resource) { if (isset($details[$resource_id])) { $rec = $details[$resource_id][0]; $env = null; if ($rec !== null) { try { $env = new SimpleXMLElement($rec->xml); } catch (exception $e) { elog((string) $e); elog($rec->xml); } } $this->view->envs[$resource_id] = $env; } } } } if (isset($_REQUEST["summary_attrs_showcontact"])) { $model = new ResourceContact(); $contacts = $model->getindex(); //group by contact_type_id $this->view->contacts = array(); foreach ($this->rgs as $rg) { foreach ($rg as $resource_id => $resource) { $types = array(); if (isset($contacts[$resource_id])) { foreach ($contacts[$resource_id] as $contact) { if (!isset($types[$contact->contact_type])) { $types[$contact->contact_type] = array(); } //group by contact name $types[$contact->contact_type][] = $contact; } $this->view->contacts[$resource_id] = $types; } } } } if (isset($_REQUEST["summary_attrs_showfqdn"])) { $amodel = new ResourceAlias(); $this->view->aliases = $amodel->getindex(); } if (isset($_REQUEST["summary_attrs_showhierarchy"])) { $this->view->hierarchy = array(); $model = new Facilities(); $facilities = $model->getgroupby("id", array("filter_disabled" => false)); $model = new Site(); $sites = $model->getgroupby("id", array("filter_disabled" => false)); $this->view->sites = $sites; $model = new SupportCenters(); $scs = $model->getgroupby("id"); foreach ($this->rgs as $rgid => $rg) { $rginfo = $this->view->resourcegroups[$rgid][0]; $siteinfo = $sites[$rginfo->site_id][0]; $facilityinfo = $facilities[$siteinfo->facility_id][0]; $scinfo = $scs[$siteinfo->sc_id][0]; $this->view->hierarchy[$rgid] = array("facility" => $facilityinfo, "site" => $siteinfo, "sc" => $scinfo); } } if (isset($_REQUEST["summary_attrs_showticket"])) { $ticketmodel = new OpenTickets(); $this->view->tickets = $ticketmodel->getGroupByRID(); } $this->setpagetitle(self::default_title()); }
public function create_db($db) { $this->check(); elog(LNOTICE, "Creating DB: {$db}"); $ret = mysqli_create_db($db, $this->db); return $ret; }
private function apply_sort(&$ids) { global $sort_info, $sort_reverse; //pull user query $sort_key = "name"; if (isset($_REQUEST["sort_key"])) { $sort_key = $_REQUEST["sort_key"]; } $sort_reverse = false; if (isset($_REQUEST["sort_reverse"])) { $sort_reverse = true; } $sort_info = array(); switch ($sort_key) { case "name": $model = new VirtualOrganization(); foreach ($model->getindex() as $id => $vo) { $vo[0]->header = $vo[0]->name; $sort_info[$id] = strtoupper($vo[0]->name); } break; case "long_name": $model = new VirtualOrganization(); foreach ($model->getindex() as $id => $vo) { $vo[0]->header = $vo[0]->long_name; $sort_info[$id] = strtoupper($vo[0]->long_name); } break; case "sc": $scmodel = new SupportCenters(); $scs = $scmodel->getindex(); $model = new VirtualOrganization(); foreach ($model->getindex() as $id => $vo) { $vo[0]->header = $scs[$vo[0]->sc_id][0]->name; $sort_info[$id] = strtoupper($scs[$vo[0]->sc_id][0]->name); } break; default: elog("Unknown sort_key given for mysort: VoController: " . $sort_key); } usort($ids, "mysort"); }
public function load() { parent::load(); $dirty_type = @$_REQUEST["bdiitree_type"]; switch ($dirty_type) { default: case "total_jobs": $sub_title = "Number of Jobs"; $key = "TotalJobs"; break; case "free_cpus": $sub_title = "Number of Free CPUs"; $key = "FreeCPUs"; break; case "estimated_response_time": $sub_title = "Estimated Response Time"; $key = "EstimatedResponseTime"; break; case "waiting_jobs": $sub_title = "Number of Waiting Jobs"; $key = "WaitingJobs"; break; case "running_jobs": $sub_title = "Number of Running Jobs"; $key = "RunningJobs"; break; case "free_job_slots": $sub_title = "Number of Free Job Slots"; $key = "FreeJobSlots"; break; } $model = new BDII(); $rgs = $model->get(); $model = new ResourceGroup(); $oim_rgs = $model->getindex(); $this->view->total_area = 0; $this->view->key = $key; $this->view->sub_title = $sub_title; $this->view->rgs = array(); foreach ($this->rgs as $rgid => $rg) { //filter ones that passed mysql query for resource group if (isset($rgs[$rgid])) { $bdii_rg = $rgs[$rgid]; $rg_view = array(); //has resources information? if (isset($bdii_rg->resources)) { //for each resource.. foreach ($bdii_rg->resources as $rid => $resource) { //filter ones that passed mysql query for resource if (isset($rg[$rid])) { //aggregate data for each services $agg = new Aggregator(); $num = 0; $services = $resource["bdii"]->Services; foreach ($services as $service) { $service = $service->Service; $servicename = $service->ServiceName; //$serviceuri = $service->ServiceUri; //for each queue if ($service->Queues === null) { continue; } foreach ($service->Queues as $queue) { $queue = $queue->Queue; $state = $queue->State; $agg->sum("TotalJobs", $state->GlueCEStateTotalJobs); $agg->sum("FreeCPUs", $state->GlueCEStateFreeCPUs); $agg->sum("EstimatedResponseTime", $state->GlueCEStateEstimatedResponseTime); $agg->sum("WaitingJobs", $state->GlueCEStateWaitingJobs); $agg->sum("RunningJobs", $state->GlueCEStateRunningJobs); $agg->sum("FreeJobSlots", $state->GlueCEStateFreeJobSlots); ++$num; } } if ($num > 0) { $rg_view[$rid] = array("info" => $rg[$rid], "agg" => $agg); $this->view->total_area += $agg->get($key); } } } } $this->view->rgs[$rgid] = array("info" => $oim_rgs[$rgid][0], "resources" => $rg_view); /* $bdii = $rg->bdii; $this->view->rgs[$rgid] = $bdii; foreach($bdii->aggregates as $aggregate) { } */ } else { elog("Can't find information for resource group {$rgid}"); } } $this->setpagetitle($this->default_title() . " - " . $sub_title); }
/** * @preserveGlobalState disabled * @runInSeparateProcess */ public function test_elog() { $this->assertTrue(elog('test')); }
private function update_chapter() { $this->CI->load->model('comic_model', 'comic'); $titles = $this->CI->grab->read_title_by_sid($this->sid); $urls = array(); foreach ($titles as $row) { $urls[] = $this->url['title'] . $row['index'] . '.html'; } try { $htmls = $this->grab->curlUseProxy($this->CI->curl)->getData_multi_tmp($urls); } catch (Exception $e) { throw $e; } foreach ($titles as $j => $row) { $this->html =& $htmls[$j]; $title = array(); try { $title['author_id'] = $this->CI->grab->get_author_id($this->parse_author_name()); $title['intro'] = $this->parse_intro(); $title['stop_renew'] = $this->parseStopRenew(); $title['meta'] = array('catid' => $this->parseCatid()); } catch (Exception $e) { elog("site_8comic - " . $row['name'] . 'parse error:' . $e); continue; } $chapters = $this->parseChapters(); $update = $title; $update['meta'] = json_encode($title['meta']); $this->db->where('id', $row['id'])->update('index_title', $update); if ($this->checkInDB($chapters, $row['id']) !== False) { continue; } $url = $this->getUrlByCatId($title['meta']['catid']) . $row['index'] . '.html'; $this->html = $this->grab->curlUseProxy($this->CI->curl)->url($url)->add()->get(); if (!$this->html) { throw new Exception('Cannot access Comic Page.'); } try { $codes = $this->parseCode(); } catch (Exception $e) { elog("site_8comic - parse code error!"); continue; } $each_vol = $this->code_opt($codes); $comics = $this->CI->comic->read_chapters_by_tid($row['id']); $i = 1; $grabbed_chapter_names = array(); foreach ($chapters as $index => $c_name) { $meta = $each_vol[$index]; $pages = $meta['pages']; unset($meta['pages']); $dbcomic = isset($comics[$i - 1]) ? $comics[$i - 1] : NULL; if ($dbcomic == NULL or $dbcomic->name != $c_name or $dbcomic->meta->num != $index) { $sql = 'UPDATE index_chapter SET `index` = `index` + 10000 WHERE tid = ' . $row['id'] . ' AND `index` = ' . $i; $this->db->query($sql); $insert = array('sid' => $this->sid, 'tid' => $row['id'], 'index' => $i, 'name' => $c_name, 'pages' => $pages, 'meta' => json_encode($meta), 'update_time' => date('Y/m/d H:i:s')); $this->db->replace('index_chapter', $insert); // reload new comics $comics = $this->CI->comic->read_chapters_by_tid($row['id']); $grabbed_chapter_names[] = $c_name; } else { if ($dbcomic->error == 1) { $update = array('name' => $c_name, 'pages' => $pages, 'meta' => json_encode($meta), 'error' => 0); $this->db->where('cid', $dbcomic->cid)->update('index_chapter', $update); } } $i++; } // if db's comic > grabbed comic, remove 多出來的 $diff = count($comics) - count($chapters); if ($diff) { $this->db->where('tid', $row['id'])->where('index >', count($chapters))->delete('index_chapter'); } elog("site_8comic - {$row['name']}'s new chapters: " . implode(",", $grabbed_chapter_names), 'grab'); } }
private function get_title_info() { $titles = []; if (!preg_match_all('/<a href="\\/colist_(\\d+).html"[^>]+>([^<]+)</', $this->html, $title_infos, PREG_SET_ORDER)) { elog('site_xxbh - Error Title Parsing.'); } else { if (!preg_match_all('/img src="([^"]+)" alt/', $this->html, $imgs)) { elog('site_xxbh - Error Title Image Parsing.'); } else { foreach ($imgs[1] as $i => $img) { $row = []; list(, $row['index'], $row['title']) = $title_infos[$i]; $row['title'] = gb2big5($row['title']); $row['image'] = $img; $titles[] = $row; } } } return $titles; }