/** * 初始化安装程序 */ public function __construct() { $this->_appId = 'L000' . time() . WindUtility::generateRandStr(4); $this->_config = @(include Wind::getRealPath(self::CONF_PATH, true)); $this->tmpPath = Wind::getRealPath($this->getConfig('tmp_dir') . '.' . Pw::getTime(), false); $this->tmpInstallLog = Wind::getRealPath($this->getConfig('log_dir'), false); }
/** * 发表帖子 钩子 */ public function addThread($tid) { $data = $this->inputData; if (intval($data['isopen'] != 1)) { return false; } $tid = intval($tid); if ($tid < 1) { return false; } $token = strtolower(WindUtility::generateRandStr(10)); $dm = $this->_getEncryptPostsDm(); $dm->setTid($tid)->setToken($token); return $this->_getEncryptPostsDs()->add($dm); }
public function addAction() { $struct = $this->getInput('struct', 'post'); $model = $this->getInput('model', 'post'); $pageid = $this->getInput('pageid', 'post'); if (!$model) { $this->showError('operate.fail'); } Wekit::load('design.PwDesignPermissions'); $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid, $pageid); if ($permissions < PwDesignPermissions::IS_DESIGN) { $this->showError("DESIGN:permissions.fail"); } Wind::import('SRV:design.bo.PwDesignModelBo'); $bo = new PwDesignModelBo($model); if (!$bo->isModel()) { $this->showError('operate.fail'); } $cls = sprintf('PwDesign%sDataService', ucwords($model)); Wind::import('SRV:design.srv.model.' . $model . '.' . $cls); $service = new $cls(); $decorator = $service->decorateAddProperty($model); $_models = array(); $service = $this->_getDesignService(); $types = $service->getDesignModelType(); $models = $service->getModelList(); foreach ($models as $k => $v) { $_models[$v['type']][] = array('name' => $v['name'], 'model' => $k); } $ds = $this->_getModuleDs(); $pageInfo = $this->_getPageDs()->getPage($pageid); $module['module_name'] = $pageInfo['page_name'] . '_' . WindUtility::generateRandStr(4); $cache['expired'] = 15; $this->setOutput($cache, 'cache'); $this->setOutput($module, 'module'); $this->setOutput($types, 'types'); $this->setOutput($_models, 'models'); $this->setOutput($bo->getProperty(), 'property'); $this->setOutput($bo->getModel(), 'modelInfo'); $this->setOutput($decorator, 'decorator'); $this->setOutput($model, 'model'); $this->setOutput($pageid, 'pageid'); $this->setOutput($struct, 'struct'); }
public function dorunAction() { $this->getRequest()->isPost() || $this->showError('operate.fail'); list($windid, $serverUrl, $clientId, $clientKey, $connect) = $this->getInput(array('windid', 'serverUrl', 'clientId', 'clientKey', 'connect'), 'post'); if ($windid == 'local') { $serverUrl = Wekit::C('site', 'info.url') . '/windid'; $clientId = 1; !$clientKey && ($clientKey = md5(WindUtility::generateRandStr(10))); $connect = 'db'; } $config = new PwConfigSet('windid'); $config->set('windid', $windid)->set('serverUrl', $serverUrl)->set('clientId', $clientId)->set('clientKey', $clientKey)->set('connect', $connect); if ($windid == 'client') { list($dbhost, $dbport, $dbuser, $dbpwd, $dbname, $dbprefix, $dbcharset) = $this->getInput(array('dbhost', 'dbport', 'dbuser', 'dbpwd', 'dbname', 'dbprefix', 'dbcharset'), 'post'); $config->set('db.host', $dbhost)->set('db.port', $dbport)->set('db.user', $dbuser)->set('db.pwd', $dbpwd)->set('db.name', $dbname)->set('db.prefix', $dbprefix)->set('db.charset', $dbcharset); } $config->flush(); if ($clientId) { Wekit::C()->reload('windid'); $service = WindidApi::api('app'); WindidApi::getDm('app'); if (!$service->getApp($clientId)) { $charset = Wekit::V('charset'); $charset = str_replace('-', '', strtolower($charset)); if (!in_array($charset, array('gbk', 'utf8', 'big5'))) { $charset = 'utf8'; } $dm = new WindidAppDm(); $dm->setId($clientId)->setApiFile('windid.php')->setIsNotify(1)->setIsSyn(1)->setAppName(Wekit::C('site', 'info.name'))->setSecretkey($clientKey)->setAppUrl(Wekit::C('site', 'info.url'))->setAppIp(Wind::getComponent('request')->getClientIp())->setCharset($charset); $service->addApp($dm); } elseif ($clientKey) { $dm = new WindidAppDm($clientId); $dm->setSecretkey($clientKey)->setAppUrl(Wekit::C('site', 'info.url'))->setCharset($charset); $service->editApp($dm); } } $_avatarUrl = WindidApi::api('avatar')->getAvatarUrl(); if ($_avatarUrl != WindidError::SERVER_ERROR) { Wekit::C()->setConfig('site', 'avatarUrl', $_avatarUrl); } $this->showMessage('ADMIN:success'); }
public function addAction() { $rand = WindUtility::generateRandStr(10); $this->setOutput(md5($rand), 'rand'); $this->setOutput('windid.php', 'apifile'); }
public function createOrderNo() { return '3' . str_pad(Wekit::getLoginUser()->uid, 10, "0", STR_PAD_LEFT) . Pw::time2str(Pw::getTime(), 'YmdHis') . WindUtility::generateRandStr(5); }
public function doaddAction() { $model = $this->getInput('model', 'post'); if (!$model) { $this->showError('operate.fail'); } Wind::import('SRV:design.bo.PwDesignModelBo'); $bo = new PwDesignModelBo($model); if (!$bo->isModel()) { $this->showError('operate.fail'); } $name = trim($this->getInput('module_name', 'post')); if (empty($name)) { $this->showError('DESIGN:module.name.empty'); } $cache = $this->getInput('cache', 'post'); $property = $this->getInput('property', 'post'); if ($property['limit'] > 200) { $this->showError('DESIGN:maxlimit.error'); } $cls = sprintf('PwDesign%sDataService', ucwords($model)); Wind::import('SRV:design.srv.model.' . $model . '.' . $cls); $service = new $cls(); if (method_exists($service, 'decorateSaveProperty')) { $property = $service->decorateSaveProperty($property); if ($property instanceof PwError) { $this->showError($property->getError()); } } $ds = $this->_getModuleDs(); Wind::import('SRV:design.dm.PwDesignModuleDm'); $dm = new PwDesignModuleDm(); $dm->setFlag($model)->setName($name)->setProperty($property)->setCache($cache)->setModuleType(PwDesignModule::TYPE_SCRIPT)->setIsused(1); if ($property['html_tpl']) { $dm->setModuleTpl($property['html_tpl']); } $resource = $ds->addModule($dm); if ($resource instanceof PwError) { $this->showError($resource->getError()); } $moduleid = (int) $resource; Wind::import('SRV:design.srv.data.PwAutoData'); $srv = new PwAutoData($moduleid); $srv->addAutoData(); //调用模块token $token = WindUtility::generateRandStr(10); $this->_getScriptDs()->addScript((int) $moduleid, $token, 0); $tab = array('property', 'template'); Wind::import('SRV:design.bo.PwDesignModelBo'); $bo = new PwDesignModelBo($model); $modelInfo = $bo->getModel(); if (is_array($modelInfo['tab'])) { foreach ($tab as $k => $v) { if (in_array($v, $modelInfo['tab'])) { $_tab[] = $tab[$k]; } } $tab = $_tab; } if (in_array('template', $tab)) { $this->showMessage("operate.success", "design/template/edit?isscript=1&moduleid=" . $moduleid, true); } else { $this->showMessage("operate.success", "design/module/run?type=api", true); } }
public function after($fileList, $useFtp, $oldList) { if (Wekit::cache()->get('system_upgrade_replace')) { return true; } $relativePath_1 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH, Wind::getRealPath('SRC:wekit')); $relativePath_2 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH . 'aCloud', Wind::getRealPath('SRC:wekit')); $strtr = $this->getMoveWay(); $move = array(); $entrance = array('index.php', 'read.php', 'install.php', 'windid.php', 'admin.php', 'alipay.php', 'pay99bill.php', 'paypal.php', 'tenpay.php'); if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { foreach ($oldList as $v) { $v = trim($v, '/'); $v = str_replace('/', DIRECTORY_SEPARATOR, $v); $_v = ROOT_PATH . $v; $file = $v; foreach ($strtr as $search => $replace) { if (0 === strpos($_v, $search)) { $file = str_replace(ROOT_PATH, '', $replace . substr($_v, strlen($search))); $file = str_replace('//', '/', $file); break; } } $move[$file] = $_v; if (in_array(basename($_v), $entrance)) { $content = WindFile::read($_v); if (strpos($content, '../../src/wekit.php')) { $content = str_replace('../../src/wekit.php', $relativePath_2, $content); } else { $content = str_replace('../src/wekit.php', $relativePath_1, $content); } $tmp = tempnam($this->tmpPath, basename($_v) . WindUtility::generateRandStr(3)); WindFile::write($tmp, $content); $move[$file] = $tmp; } } } else { foreach ($fileList as $f => $hash) { $_v = ROOT_PATH . $f; if (in_array(basename($_v), $entrance)) { $content = WindFile::read($_v); if (strpos($content, '../../src/wekit.php')) { $content = str_replace('../../src/wekit.php', $relativePath_2, $content); } else { $content = str_replace('../src/wekit.php', $relativePath_1, $content); } $tmp = tempnam($this->tmpPath, basename($_v) . WindUtility::generateRandStr(3)); WindFile::write($tmp, $content); $move[$f] = $tmp; } } } // MD5SUM $md5File = WindFile::read(CONF_PATH . 'md5sum'); $sourceMd5 = PwSystemHelper::resolveMd5($md5File); $data = ''; foreach ($sourceMd5 as $v => $md5) { $v = trim($v, '/'); $v = str_replace('/', DIRECTORY_SEPARATOR, $v); $_v = ROOT_PATH . $v; $file = $v; foreach ($strtr as $search => $replace) { if (0 === strpos($_v, $search)) { $file = str_replace(ROOT_PATH, '', $replace . substr($_v, strlen($search))); $file = str_replace('//', '/', $file); break; } } $data .= PwSystemHelper::md5content($md5, $file); } $tmp = tempnam($this->tmpPath, 'md5temp'); WindFile::write($tmp, $data); $move[str_replace(ROOT_PATH, '', CONF_PATH . 'md5sum')] = $tmp; // 入口文件 if ($useFtp) { try { $ftp = $useFtp['sftp'] ? new PwSftpSave($useFtp) : new PwFtpSave($useFtp); } catch (WindFtpException $e) { return new PwError(array('APPCENTER:upgrade.ftp.fail', array($e->getMessage()))); } } foreach ($move as $k => $v) { if ($useFtp) { try { $r = $ftp->upload($v, $k); if ($useFtp['sftp'] && !$r && ($e = $ftp->getError())) { return new PwError('APPCENTER:upgrade.upload.fail', array($v . var_export($e, true))); } } catch (WindFtpException $e) { return new PwError(array('APPCENTER:upgrade.ftp.fail', array($e->getMessage()))); } } else { copy($v, ROOT_PATH . $k); } } $useFtp && $ftp->close(); return true; }
/** * 获取加密字符串,防止伪造请求 */ public function getSignSting() { return WindUtility::generateRandStr(10); }
/** * 获取唯一标识符串,标识符串的长度为16个字节,128位. * 根据当前时间与sessionID,混合生成一个唯一的串. * * @return string GUID串,16个字节 */ public static function generateGUID() { return substr(md5(WindUtility::generateRandStr(8) . microtime()), -16); }
private static function _outFlash() { if (!class_exists('SWFBitmap')) { return false; } self::_getCodeLenth(); self::_creatImage(); self::_setRandBackground(); self::_creatBackground(); //self::_setPicBackground(); self::_setRandFont(); self::_setRandGraph(); self::_writeImage(); self::_setRandDistortion(); $_tmpPath = Wind::getRealDir('DATA:tmp.'); $_tmp = $_tmpPath . WindUtility::generateRandStr(8) . '.png'; imagepng(self::$_image, $_tmp); if (!WindFile::isFile($_tmp)) { return false; } imagedestroy(self::$_image); $bit = new SWFBitmap($_tmp); $shape = new SWFShape(); $shape->setRightFill($shape->addFill($bit)); $shape->drawLine($bit->getWidth(), 0); $shape->drawLine(0, $bit->getHeight()); $shape->drawLine(-$bit->getWidth(), 0); $shape->drawLine(0, -$bit->getHeight()); $movie = new SWFMovie(); $movie->setDimension($bit->getWidth(), $bit->getHeight()); $flash = $movie->add($shape); header("Pragma:no-cache"); header("Cache-control:no-cache"); header('Content-type: application/x-shockwave-flash'); $movie->output(); WindFolder::clear($_tmpPath); }
/** * windid更新 * * @return boolean */ private function _writeWindid() { $baseUrl = Wekit::url()->base; $key = md5(WindUtility::generateRandStr(10)); $charset = Wekit::V('charset'); $charset = str_replace('-', '', strtolower($charset)); if (!in_array($charset, array('gbk', 'utf8', 'big5'))) { $charset = 'utf8'; } $config = new PwConfigSet('windid'); $config->set('windid', 'local')->set('serverUrl', $baseUrl . '/windid')->set('clientId', 1)->set('clientKey', $key)->set('connect', 'db')->flush(); Wekit::C()->reload('windid'); Wind::import('WINDID:service.app.dm.WindidAppDm'); $dm = new WindidAppDm(); $dm->setApiFile('windid.php')->setIsNotify('1')->setIsSyn('1')->setAppName('phpwind9.0')->setSecretkey($key)->setAppUrl($baseUrl)->setCharset($charset)->setAppIp(''); $service = WindidApi::api('app'); $result = $service->addApp($dm); if ($result instanceof WindidError) { $this->showError('INSTALL:windid.init.fail'); } return true; }
protected function importStructure($structs) { Wind::import('SRV:design.dm.PwDesignStructureDm'); foreach ($structs as $k => $v) { //TODO structname 唯一性检查 $name = 'I_' . WindUtility::generateRandStr(6); $dm = new PwDesignStructureDm(); $style = unserialize($v['struct_style']); $dm->setStructTitle(unserialize($v['struct_title']))->setStructname($name)->setStructStyle($style['font'], $style['link'], $style['border'], $style['margin'], $style['padding'], $style['background'], $style['styleclass']); $resource = $this->_getStructureDs()->replaceStruct($dm); if ($resource instanceof PwError) { return $resource; } $this->_structures[] = $name; $this->_oldstruct[] = $v['struct_name']; } return true; }
protected function _beforeUpdate() { Wind::import("WSRV:user.validator.WindidUserValidator"); if (!$this->uid) { return new WindidError(WindidError::FAIL); } if (isset($this->_data['username'])) { $result = WindidUserValidator::checkName($this->_data['username'], $this->uid); if ($result !== true) { return $result; } } if (isset($this->_data['email'])) { $result = WindidUserValidator::checkEmail($this->_data['email'], $this->uid); if ($result !== true) { return $result; } } if (isset($this->_data['old_password'])) { $result = WindidUserValidator::checkOldPassword($this->_data['old_password'], $this->uid); if ($result !== true) { return $result; } } if (isset($this->_data['password'])) { $this->_data['salt'] = WindUtility::generateRandStr(6); $this->_data['password'] = WindidUtility::buildPassword($this->_data['password'], $this->_data['salt']); } if (isset($this->_data['question']) && isset($this->_data['answer'])) { $this->_data['safecv'] = $this->_data['question'] ? substr(md5($this->_data['question'] . $this->_data['answer']), 8, 8) : ''; } return true; }
/** * windid更新 * * @return boolean */ private function _writeWindid() { $baseUrl = Wind::getApp()->getRequest()->getBaseUrl(true); $key = md5(WindUtility::generateRandStr(10)); $charset = Wind::getApp()->getResponse()->getCharset(); $charset = str_replace('-', '', strtolower($charset)); if (!in_array($charset, array('gbk', 'utf8', 'big5'))) { $charset = 'utf8'; } Wind::import('WINDID:service.app.dm.WindidAppDm'); $dm = new WindidAppDm(); $dm->setApiFile('windid.php')->setIsNotify('1')->setIsSyn('1')->setAppName('phpwind9.0')->setSecretkey($key)->setAppUrl($baseUrl)->setCharset($charset)->setAppIp(''); $result = Windid::load('app.WindidApp')->addApp($dm); if ($result instanceof WindidError) { $this->showError('INSTALL:windid.init.fail'); } $config = array('windid' => 'local', 'serverUrl' => $baseUrl, 'clientId' => (int) $result, 'clientKey' => $key, 'clientDb' => 'mysql', 'clientCharser' => $charset); WindFile::savePhpData(Wind::getRealPath('ROOT:conf.windidconfig.php', true), $config); return true; }
public function synEditUser($uid, $changepwd = 0) { if (!($data = $this->_getWindid()->getUser($uid, 1, PwUser::FETCH_ALL))) { return false; } $changepwd && ($data['password'] = md5(WindUtility::generateRandStr(16))); return $this->_getDao(self::FETCH_ALL)->editUser($uid, $data); }
protected function _beforeUpdate() { if (!$this->uid) { return new WindidError(WindidError::FAIL); } if (isset($this->_data['password'])) { $this->_data['salt'] = WindUtility::generateRandStr(6); $this->_data['password'] = WindidUtility::buildPassword($this->_data['password'], $this->_data['salt']); } if (isset($this->_data['question']) && isset($this->_data['answer'])) { $this->_data['safecv'] = $this->_data['question'] ? substr(md5($this->_data['question'] . $this->_data['answer']), 8, 8) : ''; } if (isset($this->_data['old_password'])) { $user = Windid::load('user.WindidUser')->getUserByUid($this->uid, WindidUser::FETCH_MAIN); if (WindidUtility::buildPassword($this->_data['old_password'], $user['salt']) != $user['password']) { return new WindidError(WindidError::PASSWORD_ERROR); } } return true; }
/** * @see PwUploadAction.getSaveName */ function getSaveName(PwUploadFile $file) { $prename = substr(md5(Pw::getTime() . $file->id . WindUtility::generateRandStr(8)), 10, 15); $filename = $this->forum->fid . "_{$this->user->uid}_{$prename}." . $file->ext; return $filename; }
/** * 设置用户密码 * * @param string $password 新密码 * @return PwUserInfoDm */ public function setPassword($password) { $this->getDm()->setPassword($password); $this->_password = $password; $this->_data['password'] = md5(WindUtility::generateRandStr(16)); return $this; }
/** * 创始密码人加密 * * @param string $password * @return string */ public function encryptPwd($password) { $salt = WindUtility::generateRandStr(6); return md5($password . $salt) . '|' . $salt; }
/** * @see PwUploadAction.getSaveName */ public function getSaveName(PwUploadFile $file) { $prename = substr(md5(Pw::getTime() . WindUtility::generateRandStr(8)), 10, 15); $this->filename = $prename . '.' . $file->ext; return $this->filename; }
/** * @param array $matches * @return string */ private function _variable($matches) { $key = WindUtility::generateRandStr(10); $this->_variables[$key] = $matches[0]; return $key; }
public function tagModule() { $ds = $this->_getPageDs(); Wind::import('SRV:design.dm.PwDesignPageDm'); $dm = new PwDesignPageDm(); $dm->setType(PwDesignPage::SYSTEM)->setName('话题')->setRouter('tag/index/run')->setSegments(array('huatidemo')); $pageid = $ds->addPage($dm); if ($pageid instanceof PwError) { return false; } Wind::import('SRV:design.srv.vo.PwDesignComponentSo'); $vo = new PwDesignComponentSo(); $vo->setCompname('话题封面 [ 间隔 ]'); $comp = Wekit::load('design.PwDesignComponent')->searchComponent($vo); if (!$comp) { return false; } $comp = array_shift($comp); $tpl = $comp['comp_tpl']; $property = array("islogo" => 1, "order" => 5, "limit" => 18, "timefmt" => "m-d"); $cache = array('expired' => 15, 'start_hour' => 0, 'start_minute' => 0, 'end_hour' => 0, 'end_minute' => 0); Wind::import('SRV:design.dm.PwDesignModuleDm'); $moduleDm = new PwDesignModuleDm(); $moduleDm->setFlag('tag')->setPageId($pageid)->setName('演示:热门话题')->setModuleTpl($tpl)->setProperty($property)->setCache($cache)->setCompid($comp['comp_id'])->setIsused(1); $moduleid = Wekit::load('design.PwDesignModule')->addModule($moduleDm); if ($moduleid instanceof PwError) { return false; } $dm = new PwDesignPageDm($pageid); $dm->setModuleIds(array($moduleid)); $ds->updatePage($dm); $rand = WindUtility::generateRandStr(8); $tpl = <<<TPL <div id="{$rand}" class="design_layout_style J_mod_layout box_no" role="structure_{$rand}" data-lcm="100">\t\t\t <h2 class="design_layout_hd cc J_layout_hd" role="titlebar"></h2>\t\t\t <div id="J_mod_{$moduleid}" class="design_layout_ct mod_box J_mod_box" data-id="{$moduleid}"> <design id="D_mod_{$moduleid}" role="module"> </design> </div> </div> TPL; Wekit::load('design.PwDesignSegment')->replaceSegment('huatidemo', $pageid, $tpl); Wind::import('SRV:design.srv.data.PwAutoData'); $srv = new PwAutoData($moduleid); $srv->addAutoData(); return true; }
/** * 生成文件前缀 * * @return string */ public function getDirectoryName() { $version = str_replace('.', '-', $this->_version); //return 'pw_' . $version . '_' . Pw::time2str(Pw::getTime(), 'YmdHis') . '_' . WindUtility::generateRandStr(5); return WindUtility::generateRandStr(8) . '_pw_' . $version . '_' . Pw::time2str(Pw::getTime(), 'YmdHis'); }
/** * 获得切分后块编译缓存Key值,Key值为一个50位的随机字符串,当产生重复串时继续查找 * * @return string */ protected function getCompiledBlockKey() { $key = WindUtility::generateRandStr(50); if (key_exists($key, $this->compiledBlockData)) { return $this->getCompiledBlockKey(); } return $key; }
/** * 生成邀请码 * * @param int $uid 用户ID * @return string */ public function createInviteCode($uid) { $time = Pw::getTime(); $string = WindUtility::generateRandStr(32 - strlen($uid) - strlen($time)); return $uid . $string . $time; }