private function cacheLastSeenData() { if ($this->lastSeenData !== null) { return; } $lua = new \Lua(); $lua->eval("function getData()\n" . file_get_contents($this->worldpath . '/last-seen') . "\nend"); $this->lastSeenData = $lua->call('getData'); }
public function user() { $_DCOOKIE = array(); $this->cookiepre = $this->cookiepre . substr(md5($this->cookiepath . '|' . $this->cookiedomain), 0, 4) . '_'; $prelength = strlen($this->cookiepre); foreach ($_COOKIE as $key => $val) { if (substr($key, 0, $prelength) == $this->cookiepre) { $_DCOOKIE[substr($key, $prelength)] = Lua::clean($val); } } unset($prelength); if (isset($_DCOOKIE['auth'])) { $authkey = md5($this->authkey . $_SERVER['HTTP_USER_AGENT']); $auth = Lua::clean(explode("\t", $this->authcode($_DCOOKIE['auth'], 'DECODE', $authkey))); list($discuz_pw, $discuz_uid) = empty($auth) || count($auth) < 2 ? array('', '') : $auth; if ($discuz_uid) { Doo::db()->reconnect('X15'); $query = "select u.uid,u.username,u.password,p.gender from pre_common_member u left join pre_common_member_profile p on p.uid=u.uid where u.uid='{$discuz_uid}'"; $query = str_replace('pre_', $this->tablepre, $query); $user = Lua::get_one($query); Doo::db()->reconnect('dev'); if (!empty($user) && $user['password'] == $discuz_pw) { unset($user['password']); return $user; } } } return array(); }
public function beforeRun($resource, $action) { $this->dir = ADMIN_ROOT . '/moban/'; $this->img = '/' . ADMIN_ROOT . '/static/'; $session = Doo::session('Lua'); $auth = $session->get('auth'); if (empty($auth)) { $sets = Doo::cache('php')->get('loginset'); if ($sets && $sets['cardit'] == 1) { $xxxx = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'); $nums = range(1, 9); shuffle($xxxx); shuffle($nums); $aaaa = $xxxx[0] . $nums[0]; $bbbb = $xxxx[1] . $nums[1]; $session->cardcode = $aaaa . '@' . $bbbb; } include Lua::display('login', $this->dir); exit; } $auth = empty($auth) ? array(0, '') : Lua::clean(explode("\t", Lua::authcode($auth, 'DECODE')), 1); $user = Lua::get_one("select * from lua_admin where uid='" . intval($auth[0]) . "' and password='******' and gid='1'"); if (empty($user) || $user && $this->clientIP() != $user['loginip']) { $session->auth = ''; Lua::admin_msg('操作提示', '请先登录', '/' . ADMIN_ROOT); } $rs = $this->acl()->process($user['perm'], $resource, $action); if ($rs) { return $rs; } $this->user = $user; $this->page = Lua::get_post('p') ? intval(Lua::get_post('p')) : 1; // 图片识别码, 借鉴自 supesite define('FILE_HASH', substr(md5($user['uid'] . '/' . time() . Lua::random(6)), 8, 16)); }
public function user() { $_DCOOKIE = array(); $prelength = strlen($this->cookiepre); foreach ($_COOKIE as $key => $val) { if (substr($key, 0, $prelength) == $this->cookiepre) { $_DCOOKIE[substr($key, $prelength)] = Lua::clean($val); } } unset($prelength); $discuz_auth_key = md5($this->authkey . $_SERVER['HTTP_USER_AGENT']); list($discuz_pw, $discuz_secques, $discuz_uid) = isset($_DCOOKIE['auth']) ? Lua::clean(explode("\t", $this->authcode($_DCOOKIE['auth'], 'DECODE', $discuz_auth_key)), 1) : array('', '', 0); $discuz_uid = intval($discuz_uid); Doo::db()->reconnect('dz7'); $query = "select m.uid,m.username,m.password,m.gender as sex,mf.avatar as icon from cdb_members m left join cdb_memberfields mf on mf.uid=m.uid where m.uid='{$discuz_uid}'"; $query = str_replace('cdb_', $this->tablepre, $query); $user = Lua::get_one($query); Doo::db()->reconnect('dev'); if ($user && $discuz_pw == $user['password']) { unset($user['password']); $user['hash'] = substr(md5(substr(TIMESTAMP, 0, -7) . iconv('utf-8', 'gbk', $user['username']) . $discuz_uid . $discuz_pw . $discuz_auth_key), 8, 8); return $user; } return array(); }
public function user() { $winduser = $this->GetCookie('winduser'); if ($winduser) { list($winduid, $windpwd, ) = explode("\t", $this->StrCode($winduser, 'DECODE')); } if (isset($winduid) && is_numeric($winduid) && strlen($windpwd) >= 16) { Doo::db()->reconnect('pw8'); $query = "SELECT m.uid,m.username,m.password,m.icon,m.gender as sex,md.onlineip FROM pw_members m LEFT JOIN pw_memberdata md ON m.uid=md.uid WHERE m.uid='{$winduid}'"; $query = str_replace('pw_', $this->tablepre, $query); $user = Lua::get_one($query); $onlineip = $this->clientIP(); if (strpos($user['onlineip'], $onlineip) === false) { $iparray = explode(".", $onlineip); if (strpos($user['onlineip'], $iparray[0] . '.' . $iparray[1]) === false) { return array(); } } else { if (empty($user)) { return array(); } else { if ($this->PwdCode($user['password']) != $windpwd) { unset($user); return array(); } else { unset($user['password']); return $user; } } } Doo::db()->reconnect('dev'); } }
private function uploadEditorImage() { $filename = Lua::upload($this->user, 'file', array(), 0); if (strstr($filename, '1@')) { $filename = '/' . SYSNAME . '/' . str_replace('1@', '', $filename); echo stripslashes(json_encode(array('filelink' => $filename))); } }
function modulo($codigo) { $arquivo = fopen('teste.por', 'w'); fwrite($arquivo, $codigo); fclose($arquivo); $lua = new Lua(); $saida = $lua->eval(<<<CODE local var = require "parser" local var2 = require "interpretador" var.interpreta("/var/www/html/mportugol/teste.por") local f = var2.retornaSaida() return f CODE ); return $saida; }
public function RegisterCallback($Name, $Callback) { if (is_callable($Callback)) { if (is_object(parent::RegisterCallback($Name, $Callback))) { return true; } else { Std::Out("[Warning] [Lua] Can't register {$Name} callback"); } } else { Std::Out("[Warning] [Lua] Can't register {$Name} callback. It is not callable"); } return false; }
public function user() { $userCookie = $this->getCookie('winduser'); if ($userCookie) { list($uid, $password) = explode("\t", $this->decrypt($userCookie)); if ($uid) { Doo::db()->reconnect('pw9'); $query = "select u.uid,u.username,u.password,i.gender as sex from pw_user u left join pw_user_info i on i.uid=u.uid where u.uid='{$uid}'"; $query = str_replace('pw_', $this->tablepre, $query); $user = Lua::get_one($query); $user['sex'] = $user['sex'] == 1 ? 2 : 1; $user['icon'] = ''; if ($this->getPwdCode($user['password']) != $password) { return array(); } else { unset($user['password']); return $user; } Doo::db()->reconnect('dev'); } } return array(); }
public function _doit() { $dirs = date('Y-m-d'); $path = $this->cache . $dirs . '/'; $configFile = $path . 'config.php'; Doo::loadHelper('DooFile'); $fileManager = new DooFile(0777); if (!file_exists($configFile)) { if (!file_exists($path)) { $fileManager->create($path); } $tables = Doo::db()->fetchAll("SHOW TABLE STATUS"); $b_table = $d_table = ''; foreach ($tables as $row) { $b_table .= $row['Name'] . ","; $d_table .= "\$tb['" . $row['Name'] . "']=0;\r\n"; } $b_table = substr($b_table, 0, strlen($b_table) - 1); $string = "<?php\r\n\$b_table=\"" . $b_table . "\";\r\n" . $d_table . "?>"; $fileManager->create($configFile, $string); $this->jsonp('写入配置文件 ...'); } else { include $configFile; } $btb = explode(",", $b_table); $count = count($btb); $t = intval(Lua::post('t')); $s = intval(Lua::post('s')); $p = intval(Lua::post('p')); $alltotal = intval(Lua::post('alltotal')); $fnum = intval(Lua::post('fnum')); $dumpsql = ''; if ($t >= $count) { echo 'success'; exit; } if (empty($s)) { $num = Doo::db()->fetchRow("SHOW TABLE STATUS LIKE '" . $btb[$t] . "';"); $num = $num['Rows']; $dumpsql .= "self::query(\"DROP TABLE IF EXISTS `" . $btb[$t] . "`;\");\r\n"; Doo::db()->query("SET SQL_QUOTE_SHOW_CREATE=1"); $r = Doo::db()->fetchRow("SHOW CREATE TABLE `" . $btb[$t] . "`;"); $create = str_replace("\"", "\\\"", $r['Create Table']); $dumpsql .= "self::create(\"" . $create . "\");\r\n"; } else { $num = (int) $alltotal; } $fields = Doo::db()->fetchAll("SHOW FIELDS FROM `" . $btb[$t] . "`"); if (empty($fnum)) { $field_num = count($fields); } else { $field_num = $fnum; } $b = 0; $list = Doo::db()->fetchAll("select * from `" . $btb[$t] . "` limit {$s},{$num}"); if ($list) { foreach ($list as $v) { $b = 1; $s++; $dumpsql .= "self::query(\"replace into `" . $btb[$t] . "` values("; $first = 1; for ($i = 0; $i < $field_num; $i++) { if (empty($first)) { $dumpsql .= ','; } else { $first = 0; } $_field_name = $fields[$i]['Field']; if (!isset($v[$_field_name])) { $dumpsql .= 'NULL'; } else { $dumpsql .= '\'' . Lua::clean($v[$_field_name]) . '\''; } } $dumpsql .= ");\");\r\n"; if (strlen($dumpsql) >= 2048 * 1024) { $p++; $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php"; $fileManager->create($sfile, "<?php\r\n" . $dumpsql . "?>"); $this->jsonp('Table Name : <b>' . $btb[$t] . '</b><br />Table : <b>' . ($t + 1) . '/' . $count . '</b><br />Record : <b>' . $s . '/' . $num . '</b><br />备份一组数据成功,正在进入下一组......', $s, $p, $t, $alltotal, $fnum); } } } if (empty($p) || $b == 1) { $p++; $sfile = $path . "/" . $btb[$t] . "_" . $p . ".php"; $fileManager->create($sfile, "<?php\r\n" . $dumpsql . "?>"); } if (empty($p)) { $p = 0; } $text = $fileManager->readFileContents($configFile); $rep1 = "\$tb['" . $btb[$t] . "']=0;"; $rep2 = "\$tb['" . $btb[$t] . "']=" . $p . ";"; $text = str_replace($rep1, $rep2, $text); $fileManager->create($configFile, $text); $t++; $this->jsonp('备份' . $btb[$t - 1] . '表成功,正在进入下一个表备份......', 0, 0, $t, 0, 0); }
private function _tree($upid = 0, $force = 0, $addn = ' ') { $and = $force == 1 ? " and upid='{$upid}' " : ""; $list = Lua::get_more("select * from lua_category where systemname='" . SYSNAME . "' {$and} order by vieworder asc,id desc"); $back = array(); if ($list) { foreach ($list as $v) { $out[$v['id']] = $v; } $tree = new Tree($out); $tree->field = 'name'; $back = $tree->get($upid, 0, $addn); } return $back; }
private function registerLuaApi(Lua $lua) { // Map getEntity $lua->registerCallback('getEntity', function ($type, $guid) { $objectTable = call_user_func(array($type . 'Table', 'getInstance')); $object = call_user_func(array($objectTable, 'find'), array($guid)); return $object->toArray(); }); // Map sendNotification $lua->registerCallback('sendNotification', function ($type, $dest, $options, $model) { caNotificationsTools::getInstance()->sendNotification($type, $dest, $options, $model); }); // Map sendMail $lua->registerCallback('sendMail', function ($dest, $subject, $message) { sfContext::getInstance()->getMailer()->composeAndSend('*****@*****.**', $dest, $subject, $message); }); // Map createMedailleVisiteur $lua->registerCallback('createVisiteurMedaille', function ($visiteur_id, $medaille_id, $connection = 'insitu') { $medaille = Doctrine_Core::getTable('Medaille')->findOneByGuid($medaille_id); $visiteur_medaille = new VisiteurMedaille(); $visiteur_medaille->setGuid(Guid::generate()); $visiteur_medaille->setMedailleId($medaille_id); $visiteur_medaille->setVisiteurId($visiteur_id); $visiteur_medaille->setConnection($connection); if (!($visiteur_medaille->hasAlreadyMedaille($connection) && $medaille->getIsUnique())) { $visiteur_medaille->save(); } }); // Map date $lua->registerCallback('date', function ($format) { return date($format); }); // Map varDump $lua->registerCallback('varDump', function ($data) { return var_dump($data); }); // Map isBestScoreInteractif $lua->registerCallback('isBestScoreInteractif', function ($logVisiteObj) { $interactif_id = $logVisiteObj['interactif_id']; $log_visite_guid = $logVisiteObj['guid']; $visiteur_id = $logVisiteObj['visiteur_id']; $score = $logVisiteObj['score']; $log_visite_highscore = LogVisiteTable::getInstance()->getHighScoreByInteractif($interactif_id); // $log_visite = Doctrine_Core::getTable('LogVisite')->findOneByGuid($log_visite_guid); if ($score == $log_visite_highscore['highscore']) { return true; } return false; }); // Map isUserBestScoreInteractif $lua->registerCallback('isVisiteurBestScoreInteractif', function ($logVisiteObj) { $interactif_id = $logVisiteObj['interactif_id']; $log_visite_guid = $logVisiteObj['guid']; $visiteur_id = $logVisiteObj['visiteur_id']; $score = $logVisiteObj['score']; //$log_visite = Doctrine_Core::getTable('LogVisite')->findOneByGuid($log_visite_guid); $log_visite_highscore = LogVisiteTable::getInstance()->getVisiteurHighScoreByInteractif($interactif_id, $visiteur_id); if ($score == $log_visite_highscore['highscore'] && $visiteur_id == $log_visite_highscore['visiteur_id']) { return true; } return false; }); // Map nbLogVisiteExposition $lua->registerCallback('nbLogVisiteExposition', function ($exposition_id, $visiteur_id) { $count_log_visite = LogVisiteTable::getInstance()->countLogVisiteByExposition($exposition_id, $visiteur_id); return $count_log_visite; }); // Map nbLogVisiteExposition $lua->registerCallback('hasVisiteMultiPlateforme', function ($logVisiteObj) { $interactif_id = $logVisiteObj['interactif_id']; $visiteur_id = $logVisiteObj['visiteur_id']; $count_log_visite = LogVisiteTable::getInstance()->hasLogVisiteMultiPlateforme($interactif_id, $visiteur_id); return $count_log_visite; }); // Map getTotalXP $lua->registerCallback('getTotalScore', function () { $capscience_total_score = XpTable::getInstance()->getTotalScore(); return $capscience_total_score; }); // Map nbLogVisiteExposition $lua->registerCallback('getTotalScoreByVisiteur', function ($visiteur_id) { $visiteur = Doctrine_Core::getTable('Visiteur')->findOneByGuid($visiteur_id); $visiteur_score = $visiteur->getTotalXp(); return $visiteur_score; }); // Map nbLogVisiteExposition $lua->registerCallback('getTotalScoreByTypologieAndVisiteur', function ($typologie_id, $visiteur_id) { $visiteur_score_by_typlogie = XpTable::getInstance()->getTotalScoreByTypologieAndVisiteur($typologie_id, $visiteur_id); return $visiteur_score_by_typlogie; }); // create new notification $lua->registerCallback('createNotification', function ($visiteur_id, $libelle, $params = array()) { $notif = new Notification(); $notif->setLibelle($libelle); $notif->setVisiteurId($visiteur_id); if (isset($params['visite_id'])) { $notif->setVisiteId($params['visite_id']); } if (isset($params['from_model'])) { $notif->setFromModel($params['from_model']); } if (isset($params['from_model_id'])) { $notif->setFromModelId($params['from_model_id']); } if (isset($params['parameter'])) { $notif->setParameter(json_encode((array) $params['parameter'])); } $notif->save(); }); }
private function market() { include Lua::display('model_market', $this->dir); }
private function any() { $tableid = Lua::get('tableid'); $db = array(); if ($tableid) { $db = $this->_table($tableid); } if ($db) { $url = "./piece.htm?action=any&tableid={$tableid}"; $fields = $this->_fields($db['tablename']); $count = Doo::db()->count("select count(*) from " . $db['tablename']); $tpp = 30; $limit = ($this->page - 1) * $tpp . ',' . $tpp; $pri = $this->_pri($fields); $list = Lua::get_more("select * from " . $db['tablename'] . " order by {$pri} desc limit " . $limit); $page = Lua::page($url, $this->page, $count, $tpp); } include Lua::display('piece_any', $this->dir); }
private function _table_db($id) { return Lua::get_one("select * from lua_model_table where id='{$id}'"); }
<head> <meta charset="UTF-8"> <title>Portugol</title> <link rel="stylesheet" href="_css/estiloPrincipal.css"/> </head> <body> <?php //Código recebido $code = $_POST['ncode']; $arquivo = fopen('teste.por', 'w'); fwrite($arquivo, $code); fclose($arquivo); $lua = new Lua(); $imp = $lua->eval(<<<CODE local var = require "parser" local var2 = require "interpretador" var.interpreta("/var/www/html/mportugol/teste/teste.por") local f= var2.retornaSaida() return f CODE ); $L = count($imp); $xxx = 0; if ($L == 1) { echo "<br> A saída é {$imp['1']}. <br>"; } else { for ($i = 1; $i <= $L; $i++) { if ($i == 1) {
private function __import($model_id, $lastid, $table, $path, $id = 0, $new_id = 0, $subid = '', $subval = array()) { foreach ($table as $t) { if ($t['upid'] == $id) { $old_id = $t['id']; unset($t['id']); $t['upid'] = $new_id; $t['createtime'] = time(); $t['model_id'] = $lastid; $table_id = Lua::insert('lua_model_table', $t); // 第五步 导入数据表结构 $file = $path . 'field.' . $model_id . '.' . $old_id . '.php'; include $file; $data = $data[1]; foreach ($data as $v) { unset($v['id']); $v['updatetime'] = time(); $v['model_id'] = $lastid; $v['table_id'] = $table_id; Lua::insert('lua_model_field', $v); } unset($data); // 第六步 导入数据 $file = $path . 'data.' . $old_id . '.php'; include $file; $data = $data[1]; $out = array(); if ($data) { foreach ($data as $v) { $vid = $v['id']; unset($v['id']); if (isset($v[$subid])) { $v[$subid] = $subval[$v[$subid]]; } $nid = Lua::insert($t['tablename'], $v); $out[$vid] = $nid; } } unset($data); $this->__import($model_id, $lastid, $table, $path, $old_id, $table_id, $t['subid'], $out); } } }
private function ajax_change() { $uid = Lua::post('uid'); if ($uid) { $db = Lua::get_one("select gid from lua_admin where uid='{$uid}'"); $rt = $db['gid'] == 1 ? 0 : 1; Doo::db()->query("update lua_admin set gid='{$rt}' where uid='{$uid}'"); Lua::println(); } }
public function _home() { include Lua::display('home', $this->tpl); }
private function save() { $name = Lua::post('name'); $kindof = Lua::post('kindof'); $tplfile = Lua::post('tplfile'); if (empty($name)) { Lua::ajaxmessage('error', '模板名称'); } if (empty($kindof)) { Lua::ajaxmessage('error', '模板类型'); } if (empty($tplfile)) { Lua::ajaxmessage('error', '模板文件名'); } if (file_exists($this->tpl_path . $tplfile)) { Lua::ajaxmessage('error', $tplfile . ' 已存在'); } $query = array('systemname' => SYSNAME, 'name' => $name, 'kindof' => $kindof, 'dateline' => TIMESTAMP, 'lasttime' => TIMESTAMP, 'uid' => $this->user['uid'], 'username' => $this->user['username'], 'tplfile' => $tplfile); Lua::insert('lua_tpls', $query); Lua::ajaxmessage('success', '操作成功', $this->_url($kindof)); }
private function _get() { return Lua::get_more("select * from lua_member_model where systemname='" . SYSNAME . "'"); }
public function _do() { $sql = Lua::post('content'); Doo::db()->query($sql); Lua::ajaxmessage('success', '成功执行', './plugin.htm?action=sql'); }
private function market() { include Lua::display('plugin_market', $this->dir); }
<?php $lua = new Lua(); $lua->eval(<<<CODE print("O LUA-PHP está funcionando"); CODE ); ?>
public function E401() { Lua::admin_msg('权限提示', '你无权操作'); }
public function info() { $ip = $this->clientIP(); $my = Doo::db()->fetchRow("select VERSION()", null, PDO::FETCH_COLUMN); include Lua::display('info', $this->dir); }
},2000); }else{ var obj = eval('(' + data + ')'); $('#ing').html(obj.info); importit(obj.dir, obj.t, obj.p); } }); } function doit(s,p,t,alltotal,fnum){ $.post('./plugin.htm?action=ebak&c=doit',{s:s,p:p,t:t,alltotal:alltotal,fnum:fnum},function(data){ $('#ing').show(); $('#luabox').hide(); if (data == 'success'){ $('#ing').html('备份成功'); setTimeout(function(){ $('#ing').hide(); $('#luabox').show(); location.reload(); },2000); }else{ var obj = eval('(' + data + ')'); $('#ing').html(obj.info); doit(obj.s, obj.p, obj.t, obj.alltotal, obj.fnum); } }); } </script> <?php include Lua::display('_foot', $this->dir);
<?php @(include_once '../vendor/autoload.php') or die('Please execute: php composer.phar update' . PHP_EOL); /** * This file only for micro test, delete it when build */ use mfe\core\core\Page; use mfe\core\mfe as engine; /** @var Page $page */ $page = engine::app()->page; $page->setLayout('test'); $page->_content = "<p>Hello World!</p>"; $page->render(); engine::display($page); if (class_exists('Lua')) { $lua = new \Lua(); $lua->eval("print('Hello World!');"); }