Exemplo n.º 1
0
 public function __construct()
 {
     $dsn = "mysql:host=" . $this->host . ";dbname=" . $this->dbname;
     $pro = new PropertyManager();
     $this->host = $pro->getProperty('db_host');
     $this->db_pwd = $pro->getProperty('db_pwd');
     $this->db = new PDO($dsn, 'root', $this->db_pwd);
 }
Exemplo n.º 2
0
 /**
  * Send verify code to user's cellphone.
  *【注册验证】验证码.484933.,您正在注册成为探庐者用户,感谢您的支持!
  * @param String/int $phone 手机号
  * @param String/int $verify_code 后台生成的验证码
  * @return success/fail
  */
 public function sendVerifyCode($phone, $verify_code)
 {
     $pro = new PropertyManager();
     $c = new SmsServer();
     $c->appkey = $pro->getProperty('sms_key');
     $c->secretKey = $pro->getProperty('sms_secret');
     $req = new SendSms();
     $req->setExtend("1010");
     $req->setSmsType("normal");
     $req->setSmsFreeSignName("注册验证");
     $req->setSmsParam("{\"code\":\"{$verify_code}\",\"product\":\"探庐者\"}");
     $req->setRecNum($phone);
     $req->setSmsTemplateCode("SMS_5400651");
     $resp = $c->execute($req);
     if ($resp->result->err_code == '0') {
         return true;
     } else {
         echo $resText;
         return false;
     }
 }
Exemplo n.º 3
0
 /**
  * Run with given args
  *
  * @param   string[] args
  * @param   string in
  * @param   util.PropertySource[] propertySources default array()
  * @return  int
  */
 protected function runWith(array $args, $in = '', $propertySources = array())
 {
     $pm = PropertyManager::getInstance();
     $sources = $pm->getSources();
     $pm->setSources($propertySources);
     $this->in = $this->runner->setIn(new MemoryInputStream($in));
     $this->out = $this->runner->setOut(new MemoryOutputStream());
     $this->err = $this->runner->setErr(new MemoryOutputStream());
     try {
         $res = $this->runner->run(new ParamString($args));
         $pm->setSources($sources);
         return $res;
     } catch (Throwable $t) {
         $pm->setSources($sources);
         throw $t;
     }
 }
Exemplo n.º 4
0
 /**
  * Returns arguments used for injection 
  *
  * @param  lang.reflect.Routine routine
  * @return var[] args
  */
 protected function injectionArgs($routine)
 {
     if ($routine->numParameters() < 1) {
         return array();
     }
     $inject = $routine->getAnnotation('inject');
     $type = isset($inject['type']) ? $inject['type'] : $routine->getParameter(0)->getType()->getName();
     switch ($type) {
         case 'util.log.LogCategory':
             $args = array(isset($inject['name']) ? Logger::getInstance()->getCategory($inject['name']) : $this->cat);
             break;
         case 'util.Properties':
             $args = array(PropertyManager::getInstance()->getProperties($inject['name']));
             break;
         case 'webservices.rest.srv.RestContext':
             $args = array($this);
             break;
         default:
             throw new IllegalStateException('Unkown injection type ' . $type);
     }
     return $args;
 }
 public function setter_injection()
 {
     $prop = new Properties('service.ini');
     PropertyManager::getInstance()->register('service', $prop);
     $class = ClassLoader::defineClass('AbstractRestRouterTest_SetterInjection', 'lang.Object', array(), '{
     public $prop;
     #[@inject(type = "util.Properties", name = "service")]
     public function setServiceConfig($prop) { $this->prop= $prop; }
   }');
     $this->assertEquals($prop, $this->fixture->handlerInstanceFor($class)->prop);
 }
Exemplo n.º 6
0
<script src="//cdn.bootcss.com/jquery/2.1.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="//cdn.bootcss.com/jquery.form/3.51/jquery.form.min.js"></script>
<script src="../js/integration/require.min.js" data-main="js/OssPhotoUploader.js"></script>
<script src="js/jquery.wallform.js"></script>
<script src="js/area_edit.js?rand=<?php 
echo $rand;
?>
"></script>
</head>
<?php 
include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/controllers/check_admin_login_action.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/models/AreaDao.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/models/CasaDao.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/common/PropertyManager.php';
$pm = new PropertyManager();
require_once '../../application/controllers/AreaController.php';
$area = new AreaController();
$message = $area->index();
$picdir = PIC_DIR;
$area_id = $_GET['area_id'];
?>
<body>

<div id="container" class="container">
    <?php 
include_once 'navigator.php';
?>
    <input type="hidden" id="page" value="area"/>
    <input type="hidden" name="title" value='<?php 
echo $area_id;
Exemplo n.º 7
0
<?php

include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/common/PropertyManager.php';
$pm = new PropertyManager();
echo $pm->getSystem() . '<br/>';
echo $pm->getHost() . '<br/>';
echo $pm->getPhotoFolder() . '<br/>';
 /**
  * Fetch Properties resource
  *
  * @param   string name
  */
 function getProperties($name)
 {
     return PropertyManager::getInstance()->getProperties($name);
 }
 static function __static()
 {
     self::$instance = new self();
 }
Exemplo n.º 10
0
 /**
  * Creates the scriptlet instance for the given URL and runs it
  *
  * @param   string url default '/'
  */
 public function run($url = '/')
 {
     // Determine which scriptlet should be run
     $application = $this->applicationAt($url);
     // Determine debug level
     $flags = $application->getDebug();
     // Initializer logger, properties and connections to property base,
     // defaulting to the same directory the web.ini resides in
     $pm = PropertyManager::getInstance();
     foreach (explode('|', $application->getConfig()) as $element) {
         $expanded = $this->expand($element);
         if (0 == strncmp('res://', $expanded, 6)) {
             $pm->appendSource(new ResourcePropertySource($expanded));
         } else {
             $pm->appendSource(new FilesystemPropertySource($expanded));
         }
     }
     $l = Logger::getInstance();
     $pm->hasProperties('log') && $l->configure($pm->getProperties('log'));
     $cm = ConnectionManager::getInstance();
     $pm->hasProperties('database') && $cm->configure($pm->getProperties('database'));
     // Setup logger context for all registered log categories
     foreach (Logger::getInstance()->getCategories() as $category) {
         if (NULL === ($context = $category->getContext()) || !$context instanceof EnvironmentAware) {
             continue;
         }
         $context->setHostname($_SERVER['SERVER_NAME']);
         $context->setRunner($this->getClassName());
         $context->setInstance($application->getScriptlet());
         $context->setResource($url);
         $context->setParams($_SERVER['QUERY_STRING']);
     }
     // Set environment variables
     foreach ($application->getEnvironment() as $key => $value) {
         $_SERVER[$key] = $this->expand($value);
     }
     // Instantiate and initialize
     $cat = $l->getCategory('scriptlet');
     $instance = NULL;
     $e = NULL;
     try {
         $class = XPClass::forName($application->getScriptlet());
         if (!$class->hasConstructor()) {
             $instance = $class->newInstance();
         } else {
             $args = array();
             foreach ($application->getArguments() as $arg) {
                 $args[] = $this->expand($arg);
             }
             $instance = $class->getConstructor()->newInstance($args);
         }
         if ($flags & WebDebug::TRACE && $instance instanceof Traceable) {
             $instance->setTrace($cat);
         }
         $instance->init();
         // Service
         $response = $instance->process();
     } catch (ScriptletException $e) {
         $cat->error($e);
         // TODO: Instead of checking for a certain method, this should
         // check if the scriptlet class implements a certain interface
         if (method_exists($instance, 'fail')) {
             $response = $instance->fail($e);
         } else {
             $response = $this->fail($e, $e->getStatus(), $flags & WebDebug::STACKTRACE);
         }
     } catch (SystemExit $e) {
         if (0 === $e->getCode()) {
             $response = new HttpScriptletResponse();
             $response->setStatus(HttpConstants::STATUS_OK);
             if ($message = $e->getMessage()) {
                 $response->setContent($message);
             }
         } else {
             $cat->error($e);
             $response = $this->fail($e, HttpConstants::STATUS_INTERNAL_SERVER_ERROR, FALSE);
         }
     } catch (Throwable $e) {
         $cat->error($e);
         // Here, we might not have a scriptlet
         $response = $this->fail($e, HttpConstants::STATUS_PRECONDITION_FAILED, $flags & WebDebug::STACKTRACE);
     }
     // Send output
     $response->isCommitted() || $response->flush();
     $response->sendContent();
     // Call scriptlet's finalizer
     $instance && $instance->finalize();
     // Debugging
     if ($flags & WebDebug::XML && isset($response->document)) {
         flush();
         echo '<xmp>', $response->document->getDeclaration() . "\n" . $response->document->getSource(0), '</xmp>';
     }
     if ($flags & WebDebug::ERRORS) {
         flush();
         echo '<xmp>', $e ? $e->toString() : '', xp::stringOf(xp::$errors), '</xmp>';
     }
 }
Exemplo n.º 11
0
 public function __construct()
 {
     $pro = new PropertyManager();
     $this->appid = $pro->getProperty('wx_appid');
     $this->secret = $pro->getProperty('wx_appsecret');
 }
Exemplo n.º 12
0
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="../css/bootstrap.min.css" rel="stylesheet" media="screen" />
<link href="css/all.css" rel="stylesheet"/>
<script src="../js/integration/jquery.min.js"></script>
<script src="../js/integration/bootstrap.min.js"></script>
<script src="../js/integration/jquery.form.js"></script>
<script src="js/all.js"></script>
<title>探庐者-后台管理</title>
</head>
<body>
<?php 
include '../301.php';
include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/common/PropertyManager.php';
$pm = new PropertyManager();
$shutdown = $pm->getProperty("backstage_shutdown");
?>
<div id="container" style="width:400px; color: #777777">
    <h1>Casarover Management</h1>
    <form action="../../application/controllers/login_admin_action.php" class="login_form" method="post">
        <input id="redirect_url" name="redirect_url" type="hidden" value="<?php 
echo $_GET['redirect_url'];
?>
"/>
        <div class="form-group login-input-m">
            <input id="cellphone_number" name="cellphone_number" type="text" class="form-control"
                <?php 
if ($shutdown) {
    echo "disabled";
}
Exemplo n.º 13
0
<?php

include_once $_SERVER['DOCUMENT_ROOT'] . '/casarover/application/common/PropertyManager.php';
include_once 'oss_php_sdk_20140625/sdk.class.php';
function gmt_iso8601($time)
{
    $expiration = date('Y-m-d\\TH:i:sO', $time);
    $pos = strpos($expiration, '+');
    $expiration = substr($expiration, 0, $pos);
    return $expiration . "Z";
}
$pm = new PropertyManager();
$id = $pm->getProperty("oss_id");
$key = $pm->getProperty("oss_secret");
$host = $pm->getProperty("oss_external");
$now = time();
$expire = 30;
//设置该policy超时时间是10s. 即这个policy过了这个有效时间,将不能访问
$end = $now + $expire;
$expiration = gmt_iso8601($end);
$oss_sdk_service = new alioss($id, $key, $host);
if (isset($_GET["target_folder"])) {
    $dir .= $_GET["target_folder"] . "/";
} else {
    $dir .= "test/";
}
//最大文件大小.用户可以自己设置
$condition = array(0 => 'content-length-range', 1 => 0, 2 => 1024000);
$conditions[] = $condition;
//表示用户上传的数据,必须是以$dir开始, 不然上传会失败,这一步不是必须项,只是为了安全起见,防止用户通过policy上传到别人的目录
$start = array(0 => 'starts-with', 1 => '$key', 2 => $dir);
Exemplo n.º 14
0
$code = $_GET['code'];
$appid = "";
$secret = "";
$get_token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $appid . '&secret=' . $secret . '&code=' . $code . '&grant_type=authorization_code';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $get_token_url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
$res = curl_exec($ch);
curl_close($ch);
$json_obj = json_decode($res, true);
$access_token = $json_obj['access_token'];
$openid = $json_obj['openid'];
/** For your local testing: */
$pm = new PropertyManager();
$dummy_openid = $pm->getDummyOpenid();
if (empty($openid) && isset($dummy_openid)) {
    $openid = $dummy_openid;
}
/** localhost test context END.*/
// Lottery logic
if (isset($openid)) {
    $r = rand(0, 7);
    $gua = rand(0, 3);
    // Draw lottery. 抽奖放在这里
    $wls = new WechatLotteryService();
    // Today's drawing time. 第几次抽奖
    $today_time = $wls->save_onelot($openid);
    $rewardDao = new RewardDao();
    $reward_row = $rewardDao->getByOpenid($openid);
 public function isSingleton()
 {
     $this->assertEquals(PropertyManager::getInstance()->hashCode(), PropertyManager::getInstance()->hashCode());
 }
Exemplo n.º 16
0
 /**
  * Main method
  *
  * @param   util.cmd.ParamString params
  * @return  int
  */
 public function run(ParamString $params)
 {
     // No arguments given - show our own usage
     if ($params->count < 1) {
         self::$err->writeLine(self::textOf(XPClass::forName(xp::nameOf(__CLASS__))->getComment()));
         return 1;
     }
     // Configure properties
     $pm = PropertyManager::getInstance();
     // Separate runner options from class options
     for ($offset = 0, $i = 0; $i < $params->count; $i++) {
         switch ($params->list[$i]) {
             case '-c':
                 if (0 == strncmp('res://', $params->list[$i + 1], 6)) {
                     $pm->appendSource(new ResourcePropertySource(substr($params->list[$i + 1], 6)));
                 } else {
                     $pm->appendSource(new FilesystemPropertySource($params->list[$i + 1]));
                 }
                 $offset += 2;
                 $i++;
                 break;
             case '-cp':
                 ClassLoader::registerPath($params->list[$i + 1], NULL);
                 $offset += 2;
                 $i++;
                 break;
             case '-v':
                 $this->verbose = TRUE;
                 $offset += 1;
                 $i++;
                 break;
             default:
                 break 2;
         }
     }
     // Sanity check
     if (!$params->exists($offset)) {
         self::$err->writeLine('*** Missing classname');
         return 1;
     }
     // Use default path for PropertyManager if no sources set
     if (!$pm->getSources()) {
         $pm->configure(self::DEFAULT_CONFIG_PATH);
     }
     unset($params->list[-1]);
     $classname = $params->value($offset);
     $classparams = new ParamString(array_slice($params->list, $offset + 1));
     // Class file or class name
     if (strstr($classname, xp::CLASS_FILE_EXT)) {
         $file = new File($classname);
         if (!$file->exists()) {
             self::$err->writeLine('*** Cannot load class from non-existant file ', $classname);
             return 1;
         }
         $uri = $file->getURI();
         $path = dirname($uri);
         $paths = array_flip(array_map('realpath', xp::$classpath));
         $class = NULL;
         while (FALSE !== ($pos = strrpos($path, DIRECTORY_SEPARATOR))) {
             if (isset($paths[$path])) {
                 $class = XPClass::forName(strtr(substr($uri, strlen($path) + 1, -10), DIRECTORY_SEPARATOR, '.'));
                 break;
             }
             $path = substr($path, 0, $pos);
         }
         if (!$class) {
             self::$err->writeLine('*** Cannot load class from ', $file);
             return 1;
         }
     } else {
         try {
             $class = XPClass::forName($classname);
         } catch (ClassNotFoundException $e) {
             self::$err->writeLine('*** ', $this->verbose ? $e : $e->getMessage());
             return 1;
         }
     }
     // Check whether class is runnable
     if (!$class->isSubclassOf('lang.Runnable')) {
         self::$err->writeLine('*** ', $class->getName(), ' is not runnable');
         return 1;
     }
     // Usage
     if ($classparams->exists('help', '?')) {
         self::showUsage($class);
         return 0;
     }
     // Load, instantiate and initialize
     $l = Logger::getInstance();
     $pm->hasProperties('log') && $l->configure($pm->getProperties('log'));
     $cm = ConnectionManager::getInstance();
     $pm->hasProperties('database') && $cm->configure($pm->getProperties('database'));
     // Setup logger context for all registered log categories
     foreach (Logger::getInstance()->getCategories() as $category) {
         if (NULL === ($context = $category->getContext()) || !$context instanceof EnvironmentAware) {
             continue;
         }
         $context->setHostname(System::getProperty('host.name'));
         $context->setRunner($this->getClassName());
         $context->setInstance($class->getName());
         $context->setResource(NULL);
         $context->setParams($params->string);
     }
     $instance = $class->newInstance();
     $instance->in = self::$in;
     $instance->out = self::$out;
     $instance->err = self::$err;
     $methods = $class->getMethods();
     // Injection
     foreach ($methods as $method) {
         if (!$method->hasAnnotation('inject')) {
             continue;
         }
         $inject = $method->getAnnotation('inject');
         if (isset($inject['type'])) {
             $type = $inject['type'];
         } else {
             if ($restriction = $method->getParameter(0)->getTypeRestriction()) {
                 $type = $restriction->getName();
             } else {
                 $type = $method->getParameter(0)->getType()->getName();
             }
         }
         try {
             switch ($type) {
                 case 'rdbms.DBConnection':
                     $args = array($cm->getByHost($inject['name'], 0));
                     break;
                 case 'util.Properties':
                     $p = $pm->getProperties($inject['name']);
                     // If a PropertyAccess is retrieved which is not a util.Properties,
                     // then, for BC sake, convert it into a util.Properties
                     if ($p instanceof PropertyAccess && !$p instanceof Properties) {
                         $convert = Properties::fromString('');
                         $section = $p->getFirstSection();
                         while ($section) {
                             // HACK: Properties::writeSection() would first attempts to
                             // read the whole file, we cannot make use of it.
                             $convert->_data[$section] = $p->readSection($section);
                             $section = $p->getNextSection();
                         }
                         $args = array($convert);
                     } else {
                         $args = array($p);
                     }
                     break;
                 case 'util.log.LogCategory':
                     $args = array($l->getCategory($inject['name']));
                     break;
                 default:
                     self::$err->writeLine('*** Unknown injection type "' . $type . '" at method "' . $method->getName() . '"');
                     return 2;
             }
             $method->invoke($instance, $args);
         } catch (TargetInvocationException $e) {
             self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->getCause()->compoundMessage());
             return 2;
         } catch (Throwable $e) {
             self::$err->writeLine('*** Error injecting ' . $type . ' ' . $inject['name'] . ': ' . $e->compoundMessage());
             return 2;
         }
     }
     // Arguments
     foreach ($methods as $method) {
         if ($method->hasAnnotation('args')) {
             // Pass all arguments
             if (!$method->hasAnnotation('args', 'select')) {
                 $begin = 0;
                 $end = $classparams->count;
                 $pass = array_slice($classparams->list, 0, $end);
             } else {
                 $pass = array();
                 foreach (preg_split('/, ?/', $method->getAnnotation('args', 'select')) as $def) {
                     if (is_numeric($def) || '-' == $def[0]) {
                         $pass[] = $classparams->value((int) $def);
                     } else {
                         sscanf($def, '[%d..%d]', $begin, $end);
                         isset($begin) || ($begin = 0);
                         isset($end) || ($end = $classparams->count - 1);
                         while ($begin <= $end) {
                             $pass[] = $classparams->value($begin++);
                         }
                     }
                 }
             }
             try {
                 $method->invoke($instance, array($pass));
             } catch (Throwable $e) {
                 self::$err->writeLine('*** Error for arguments ' . $begin . '..' . $end . ': ', $this->verbose ? $e : $e->getMessage());
                 return 2;
             }
         } else {
             if ($method->hasAnnotation('arg')) {
                 // Pass arguments
                 $arg = $method->getAnnotation('arg');
                 if (isset($arg['position'])) {
                     $name = '#' . ($arg['position'] + 1);
                     $select = intval($arg['position']);
                     $short = NULL;
                 } else {
                     if (isset($arg['name'])) {
                         $name = $select = $arg['name'];
                         $short = isset($arg['short']) ? $arg['short'] : NULL;
                     } else {
                         $name = $select = strtolower(preg_replace('/^set/', '', $method->getName()));
                         $short = isset($arg['short']) ? $arg['short'] : NULL;
                     }
                 }
                 if (0 == $method->numParameters()) {
                     if (!$classparams->exists($select, $short)) {
                         continue;
                     }
                     $args = array();
                 } else {
                     if (!$classparams->exists($select, $short)) {
                         list($first, ) = $method->getParameters();
                         if (!$first->isOptional()) {
                             self::$err->writeLine('*** Argument ' . $name . ' does not exist!');
                             return 2;
                         }
                         $args = array();
                     } else {
                         $args = array($classparams->value($select, $short));
                     }
                 }
                 try {
                     $method->invoke($instance, $args);
                 } catch (TargetInvocationException $e) {
                     self::$err->writeLine('*** Error for argument ' . $name . ': ', $this->verbose ? $e->getCause() : $e->getCause()->compoundMessage());
                     return 2;
                 }
             }
         }
     }
     try {
         $instance->run();
     } catch (Throwable $t) {
         self::$err->writeLine('*** ', $t->toString());
         return 70;
         // EX_SOFTWARE according to sysexits.h
     }
     return 0;
 }
Exemplo n.º 17
0
 public static function removePropertySource()
 {
     PropertyManager::getInstance()->removeSource(self::$propertySource);
 }