Example #1
0
 /**
  * 发送短信
  *
  * @return bool
  */
 public function sendMobileMessage($mobile, $content)
 {
     $content = Pw::convert($content, 'UTF-8');
     $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'sendSms', 'mobile' => $mobile, 'content' => $content));
     $info = PwApplicationHelper::requestAcloudData($url);
     if (!is_array($info)) {
         return new PwError('APPCENTER:center.connect.fail');
     }
     if ($info['code'] !== '0') {
         return new PwError($info['msg']);
     }
     return true;
 }
Example #2
0
 /**
  * 获取线上补丁列表
  *
  * @return Ambigous <multitype:, boolean, string>
  */
 public function getOnlinePatchList()
 {
     $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getSecurityPatch', 'pwversion' => NEXT_VERSION));
     $r = PwApplicationHelper::requestAcloudData($url);
     if (!is_array($r)) {
         return '无法连接云平台!';
     }
     if ($r['code'] !== '0') {
         return $r['msg'];
     }
     /* $r['info'] = array(
     			array('id' => '9000001', 'name' => '更新', 'desc' => 'blabla', 'time' => '1323333', 'rule' => array(
     				array('filename' => 'src/wekit.php', 'search' => base64_encode('Jianmin Chen'), 'replace' => base64_encode('Shi Long'), 'count' => '1', 'nums' => array('1'))))
     		); */
     $temp = array();
     foreach ($r['info'] as $v) {
         $v['id'] = $v['name'];
         $temp[$v['id']] = $v;
     }
     return $temp;
 }
Example #3
0
 /**
  * 更新成功后备份
  *
  * @return multitype:string
  */
 private function _backSuccess()
 {
     $data_dir = Wind::getRealDir('DATA:');
     $suffix = '[' . Pw::time2str(WEKIT_TIMESTAMP, 'Y-m-d Hi') . ']';
     $up_source = $data_dir . 'upgrade';
     $up_target = $data_dir . 'upgrade' . $suffix;
     PwApplicationHelper::copyRecursive($up_source, $up_target);
     $status = Wekit::cache()->get('system_upgrade');
     $ba_source = $data_dir . 'backup' . DIRECTORY_SEPARATOR . 'phpwind_' . str_replace('.', '', $status['oldversion']) . '_' . $status['oldrelease'];
     $ba_target = $data_dir . 'backup' . $suffix;
     PwApplicationHelper::copyRecursive($ba_source, $ba_target);
     WindFolder::clearRecur($up_source, true);
     WindFolder::clearRecur($ba_source, true);
     return array($up_target, $ba_target);
 }
Example #4
0
 /**
  * 导出压缩包
  *
  */
 public function exportAction()
 {
     $alias = $this->getInput('alias', 'get');
     Wind::import('LIB:utility.PwZip');
     $dir = Wind::getRealDir('EXT:' . $alias);
     if (!is_dir($dir)) {
         $this->showError('fail');
     }
     $target = Wind::getRealPath('DATA:tmp.' . $alias . '.zip', true);
     PwApplicationHelper::zip($dir, $target);
     $timestamp = Pw::getTime();
     $this->getResponse()->setHeader('Last-Modified', gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT');
     $this->getResponse()->setHeader('Expires', gmdate('D, d M Y H:i:s', $timestamp + 86400) . ' GMT');
     $this->getResponse()->setHeader('Cache-control', 'max-age=86400');
     $this->getResponse()->setHeader('Content-type', 'application/x-zip-compressed');
     $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=' . $alias . '.zip');
     $this->getResponse()->sendHeaders();
     @readfile($target);
     WindFile::del($target);
     $this->getResponse()->sendBody();
     exit;
 }
Example #5
0
 public function generate()
 {
     $addons = Wekit::load('APPS:appcenter.service.srv.PwInstallApplication')->getConfig('style-type');
     $base = str_replace('/', '.', $addons[$this->style_type][1]);
     $this->defaultDir = Wind::getRealDir('THEMES:' . $base . '.default');
     if (!is_dir($this->defaultDir)) {
         return new PwError('APPCENTER:generate.style.unsupport');
     }
     $this->baseDir = Wind::getRealDir('THEMES:' . $base . '.' . $this->alias);
     if (is_dir($this->baseDir)) {
         return new PwError('APPCENTER:alias.exist');
     }
     WindFolder::mkRecur($this->baseDir);
     Wind::import('APPS:appcenter.service.srv.helper.PwSystemHelper');
     $writable = PwSystemHelper::checkWriteAble($this->baseDir . '/');
     if (!$writable) {
         return new PwError('APPCENTER:generate.copy.fail');
     }
     PwApplicationHelper::copyRecursive($this->defaultDir, $this->baseDir);
     $file = $this->baseDir . '/Manifest.xml';
     Wind::import('WIND:parser.WindXmlParser');
     $parser = new WindXmlParser();
     $manifest = $parser->parse($file);
     $manifest['application']['name'] = $this->name;
     $manifest['application']['alias'] = $this->alias;
     $manifest['application']['description'] = $this->description;
     $manifest['application']['version'] = $this->version;
     $manifest['application']['pw-version'] = $this->pwversion;
     $manifest['application']['website'] = $this->website;
     $manifest['application']['author-name'] = $this->author;
     $manifest['application']['author-email'] = $this->email;
     $parser = new WindXmlParser();
     $manifest = str_replace('><', ">\n\t<", $parser->parseToXml(array('manifest' => $manifest), Wind::getApp()->getResponse()->getCharset()));
     WindFile::write($this->baseDir . '/Manifest.xml', $manifest);
     return 'THEMES:' . $base . '.' . $this->alias;
 }
Example #6
0
 /**
  * (non-PHPdoc)
  *
  * @see PwInstall::afterInstall()
  * @param PwInstallApplication $install        	
  */
 public function afterInstall($install)
 {
     list(, $pack) = $this->getStyleType($install);
     $alias = $install->getManifest()->getApplication('alias');
     $targetDir = THEMES_PATH . $pack;
     if (!PwSystemHelper::checkWriteAble($targetDir . '/')) {
         return new PwError('APPCENTER:install.mv.fail', array('{{error}}' => 'THEMES:' . str_replace('/', '.', $pack)));
     }
     $target = $targetDir . '/' . $alias;
     PwApplicationHelper::mvSourcePack($install->getTmpPackage(), $target);
     $install->addInstallLog('packs', $target);
     file_put_contents(DATA_PATH . 'tmp/log', 'afterinstall!', FILE_APPEND);
     return true;
 }
Example #7
0
 /**
  * 获取安装流程注入
  *
  * @return array
  */
 protected function resolvedInstallation($file)
 {
     $install = null;
     if ($this->_step && is_file($file)) {
         $service = PwApplicationHelper::readInstallLog($file, 'services');
         $rollback = PwApplicationHelper::readInstallLog($file, 'rollback');
         $install = PwApplicationHelper::readInstallLog($file, 'installation');
         $install = unserialize(base64_decode($install));
     } else {
         $service = $rollback = array();
         $conf = $this->getConfig('install-type', $this->getManifest()->getApplication('type', 'app'));
         if (!empty($conf['step']['before'])) {
             foreach ($conf['step']['before'] as $var) {
                 $var['class'] = $conf['class'];
                 $service[] = $var;
             }
         } else {
             $service[] = $conf;
         }
         $rollback[] = $conf;
         foreach ($this->getManifest()->getInstallationService() as $var) {
             // TODO 从钩子中获取
             $_tmp = $this->getConfig('installation-service', $var);
             if (!$_tmp) {
                 continue;
             }
             $_tmp['_key'] = $var;
             $rollback[] = $service[] = $_tmp;
             $this->addInstallLog('service', $_tmp);
         }
         if (!empty($conf['step']['after'])) {
             foreach ($conf['step']['after'] as $var) {
                 $var['class'] = $conf['class'];
                 $service[] = $var;
             }
         }
         $manifest = $this->getManifest()->getManifest();
         if (isset($manifest['install']) && $manifest['install']) {
             $_tmp = array('class' => $manifest['install']);
             $service[] = $_tmp;
             $this->addInstallLog('service', $_tmp);
         }
         $this->addInstallLog('service', $conf);
         if ($this->_step) {
             PwApplicationHelper::writeInstallLog($file, array('services' => $service, 'rollback' => $rollback, 'installation' => base64_encode(serialize($this))));
         }
         $install = $this;
     }
     return array($service, $rollback, $install);
 }
Example #8
0
 /**
  * 根据现有目录结构调整升级包目录
  *
  * @param array $fileList        	
  */
 public function sortDirectory($fileList)
 {
     $this->_log('start to sort the directory');
     $sourceDir = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target;
     $directoryFile = $sourceDir . DIRECTORY_SEPARATOR . 'conf/directory.php';
     $directory = @(include $directoryFile);
     if (!is_array($directory)) {
         return new PwError('APPCENTER:upgrade.directory.fail');
     }
     $this->_log('the remote directory is:' . var_export($directory, true));
     $root = Wind::getRealDir('ROOT:');
     $sort = array('TPL', 'THEMES', 'ACLOUD', 'WINDID', 'REP', 'SRV', 'LIB', 'HOOK', 'EXT', 'APPS', 'CONF', 'DATA', 'SRC', 'PUBLIC');
     $strtr = array();
     $localDirectory = @(include Wind::getRealPath('CONF:directory.php', true));
     foreach ($sort as $v) {
         if ($directory[$v] == $localDirectory[$v]) {
             continue;
         }
         $search = PwSystemHelper::relative(WEKIT_PATH . str_replace('/', DIRECTORY_SEPARATOR, $directory[$v]));
         $strtr[rtrim($search, '/\\')] = rtrim(Wind::getRootPath($v), '/\\');
     }
     $this->_log('way of moving directory' . var_export($strtr, true));
     if (!($sourceMd5 = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum'))) {
         return new PwError('APPCENTER:upgrade.target.hash.fail');
     }
     $sourceMd5 = PwSystemHelper::resolveMd5($sourceMd5);
     // md5sum
     $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);
     }
     WindFile::write($sourceDir . DIRECTORY_SEPARATOR . 'conf/md5sum', $data);
     $moveList = $newFileList = array();
     $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'getVersionHash', 'pwversion' => $this->local));
     /* 从线上获取当前版本的所有文件md5 */
     /* $result = PwApplicationHelper::requestAcloudData($url);
     		if ($result['code'] !== '0' || !$result['info']) return new PwError(array('APPCENTER:upgrade.version.hash.fail', array($result['msg']))); */
     if (!($tmp = WindFile::read(CONF_PATH . 'md5sum'))) {
         return new PwError('APPCENTER:upgrade.hash.fail');
     }
     $md5List = PwSystemHelper::resolveMd5($tmp);
     $this->_log('obtain the md5 list of current version');
     foreach ($fileList as $v) {
         $v = trim($v, '/');
         $v = str_replace('/', DIRECTORY_SEPARATOR, $v);
         $_v = $root . $v;
         $file = $v;
         foreach ($strtr as $search => $replace) {
             if (0 === strpos($_v, $search)) {
                 $file = str_replace($root, '', $replace . substr($_v, strlen($search)));
                 $file = str_replace('//', '/', $file);
                 $moveList[$v] = $file;
                 break;
             }
         }
         $newFileList[$file] = $md5List[str_replace(DIRECTORY_SEPARATOR, '/', $file)];
     }
     $this->_log('files need to move ' . var_export($moveList, true));
     $relativePath_1 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH, Wind::getRealPath('SRC:wekit'));
     $relativePath_2 = PwSystemHelper::resolveRelativePath(PUBLIC_PATH . 'aCloud', Wind::getRealPath('SRC:wekit'));
     foreach ($moveList as $old => $new) {
         WindFolder::mkRecur(dirname($sourceDir . DIRECTORY_SEPARATOR . $new));
         copy($sourceDir . DIRECTORY_SEPARATOR . $old, $sourceDir . DIRECTORY_SEPARATOR . $new);
         WindFile::del($sourceDir . DIRECTORY_SEPARATOR . $old);
         if ('.php' === substr($old, -4) && !strncasecmp($old, 'www' . DIRECTORY_SEPARATOR, 4)) {
             $content = WindFile::read($sourceDir . DIRECTORY_SEPARATOR . $new);
             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);
             }
             // $content = str_replace('../src/wekit.php',
             // Wind::getRealPath('SRC:wekit'), $content);
             WindFile::write($sourceDir . DIRECTORY_SEPARATOR . $new, $content);
         }
     }
     // 目录文件
     if ($directory != $localDirectory) {
         $directory = array_merge($directory, $localDirectory);
         $temp = "<?php\r\n defined('WEKIT_VERSION') or exit(403);\r\n return ";
         $temp .= WindString::varToString($directory) . ";\r\n?>";
         WindFile::write($directoryFile, $temp);
     }
     Wekit::cache()->set('system_upgrade_replace', 1);
     return $newFileList;
 }
Example #9
0
 /**
  *
  * @param PwInstallApplication $install        	
  */
 public function afterInstall($install)
 {
     $tmp = $install->getTmpPackage();
     WindFile::del($tmp . '/Manifest.xml');
     PwApplicationHelper::copyRecursive($tmp, ROOT_PATH);
 }
Example #10
0
 /**
  * 注册静态资源
  *
  * @param PwInstallApplication $install        	
  * @return PwError true
  */
 public function registeResource($install)
 {
     $manifest = $install->getManifest()->getManifest();
     if (!isset($manifest['res']) || !$manifest['res']) {
         return true;
     }
     $name = $install->getManifest()->getApplication('alias');
     $source = $install->getTmpPackage() . '/' . str_replace('.', '/', $manifest['res']);
     $targetPath = Wind::getRealDir('THEMES:extres', true);
     if (!is_dir($source)) {
         return true;
     }
     $writable = PwSystemHelper::checkWriteAble($targetPath . '/');
     if (!$writable) {
         return new PwError('APPCENTER:install.mv.fail', array('{{error}}' => 'THEMES:extres.' . $name));
     }
     PwApplicationHelper::copyRecursive($source, $targetPath . '/' . $name);
     $install->addInstallLog('packs', $targetPath . '/' . $name);
     file_put_contents(DATA_PATH . 'tmp/log', 'res!', FILE_APPEND);
 }
Example #11
0
 /**
  * 卸载
  */
 public function uninstallAction()
 {
     $styleid = $this->getInput('styleid');
     /* @var $uninstall PwUninstallApplication */
     if ($styleid[0] !== 'L') {
         $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'uninstallApp', 'appid' => $styleid));
         $info = PwApplicationHelper::requestAcloudData($url);
         if ($info['code'] !== '0') {
             $this->showError($info['msg']);
         } else {
             $this->showMessage('success');
         }
     } else {
         $uninstall = Wekit::load('APPCENTER:service.srv.PwUninstallApplication');
         $r = $uninstall->uninstall($styleid);
         if ($r === true) {
             $this->showMessage('success');
         }
         $this->showError($r->getError());
     }
 }
 /**
  * 复制资源文件
  *
  * @param unknown_type $alias        	
  * @param unknown_type $manifest        	
  * @return boolean
  */
 private function _copyRes($alias, $manifest)
 {
     $this->app = $this->_appDs()->findByAlias($alias);
     $this->app_id = $this->app['app_id'];
     $this->manifest = new PwManifest($manifest);
     $man_array = $this->manifest->getManifest();
     $log = array();
     if ($man_array['res']) {
         $source = dirname($manifest) . DIRECTORY_SEPARATOR . str_replace('.', DIRECTORY_SEPARATOR, $man_array['res']);
         $targetPath = Wind::getRealDir('THEMES:extres.' . $alias, true);
         if (!is_dir($source)) {
             return false;
         }
         PwApplicationHelper::copyRecursive($source, $targetPath);
         $app_log = $this->_loadInstallLog()->findByAppId($this->app_id);
         $packs_log = array();
         foreach ($app_log as $v) {
             if ($v['log_type'] == 'packs') {
                 $packs_log = $v['data'];
             }
         }
         if (!in_array($targetPath, $packs_log)) {
             $packs_log[] = $targetPath;
         }
         $log[] = array('app_id' => $this->app_id, 'log_type' => 'packs', 'data' => $packs_log, 'created_time' => WEKIT_TIMESTAMP, 'modified_time' => WEKIT_TIMESTAMP);
     }
     $log && $this->_loadInstallLog()->batchAdd($log);
 }
 public function generate()
 {
     $this->baseDir = Wind::getRealDir('EXT:' . $this->alias);
     if (is_dir($this->baseDir)) {
         return new PwError('APPCENTER:alias.exist');
     }
     WindFolder::mkRecur($this->baseDir);
     Wind::import('APPCENTER:service.srv.helper.PwSystemHelper');
     $writable = PwSystemHelper::checkWriteAble($this->baseDir . '/');
     if (!$writable) {
         return new PwError('APPCENTER:generate.copy.fail');
     }
     PwApplicationHelper::copyRecursive($this->defaultDir, $this->baseDir, array('service'));
     $manifest = WindFile::read($this->baseDir . '/Manifest.xml');
     $this->manifest = $this->_strtr($manifest);
     $this->_generateAdmin();
     WindFile::write($this->baseDir . '/Manifest.xml', $this->manifest);
     $this->_resolveTemplate();
     $this->_generateService();
     return true;
 }
Example #14
0
 public function loginAlipayAction()
 {
     $alipay = $this->getInput('alipay');
     Wind::import('APPCENTER:service.srv.helper.PwApplicationHelper');
     $url = PwApplicationHelper::acloudUrl(array('a' => 'forward', 'do' => 'alipayAuth', 'callback' => WindUrlHelper::createUrl('app/verify/index/verifyAlipay', array('uid' => $this->loginUser->uid)), 'account' => $alipay));
     $info = PwApplicationHelper::requestAcloudData($url);
     if ($info['code'] !== '0') {
         $this->showError($info['msg']);
     }
     $this->setOutput(array('referer' => $info['info']), 'data');
     $this->showMessage('success');
 }
 /**
  * 下载
  * 1、下载zip包
  * 2、单个文件下载
  */
 public function download($downloadUrl, $hash, $file = '')
 {
     if ($this->useZip) {
         list($bool, $package) = PwSystemHelper::download($downloadUrl, $this->tmpPath . '/' . basename($downloadUrl));
         if (!$bool) {
             return new PwError($package);
         }
         if ($hash !== md5_file($package)) {
             $this->_log('check Package fail. expected hash:' . $hash . 'real hash :' . md5_file($package));
             return new PwError('APPCENTER:install.checkpackage.fail');
         }
         $this->_log('download zip success, dir:' . $package);
         $this->tmpPackage = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target;
         $r = PwApplicationHelper::extract($package, $this->tmpPath);
         if ($r === false) {
             $this->_log('extract Package fail. ');
             return new PwError('APPCENTER:install.checkpackage.format.fail', array('{{error}}' => $r));
         }
         if ($r != realpath($this->tmpPackage)) {
             PwApplicationHelper::copyRecursive($r, $this->tmpPackage);
         }
         $this->_log('extract zip success, dir:' . $this->tmpPackage);
         return true;
     } else {
         $_file = $this->tmpPath . DIRECTORY_SEPARATOR . $this->target . DIRECTORY_SEPARATOR . $file;
         $dir = dirname($_file);
         list($bool, $_file) = PwSystemHelper::download($downloadUrl . '/' . $file . 'wind', $_file);
         if (!$bool) {
             return new PwError($_file);
         }
         if ($hash !== md5_file($_file)) {
             $this->_log('check file fail. expected hash:' . $hash . 'real hash :' . md5_file($_file));
             return new PwError('APPCENTER:upgrade.check.file.fail');
         }
         $this->_log('download file success, file:' . $_file);
         return true;
     }
 }