/**
  * Context-aware call to setcookie().
  *
  * This method is context-aware and will avoid setting cookies if the request
  * context is not HTTP.
  *
  * @param string $name
  * @param string $value
  * @param integer $expire
  * @param string $path
  * @param string $domain
  * @param boolean $secure
  * @param boolean $httponly
  */
 function safeCookie($name, $value = null, $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false)
 {
     static $context = null;
     if (is_null($context)) {
         $context = requestContext();
     }
     if ($context == 'http') {
         setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
     }
 }
Example #2
0
File: func.php Project: aising/ding
/**
 * 获取传递的参数
 * @param string $method 接口方法名
 */
function getParaArr($method, $isCheck = false)
{
    $paraArr = array();
    $paraConf = __loadConfig('config_interface_parame');
    $paraKeyArr = $paraConf[$method];
    sort($paraKeyArr);
    foreach ($paraKeyArr as &$value) {
        $paraArr[$value] = requestContext($value);
    }
    if ($isCheck) {
        //获取公用参数
        $sig = isset($_GET['sig']) && RepPostVar($_GET['sig']) ? RepPostVar($_GET['sig']) : '';
        //校验,先对数组转为字符串,然后加上密钥,再与传递过来的Sig比对
        $verifyStr = arrToStr($paraArr, '') . 'secret=' . SECRET;
        if ($sig != md5($verifyStr)) {
            return 0;
        } else {
            return $paraArr;
        }
    } else {
        return $paraArr;
    }
}
Example #3
0
function readUrl($url)
{
    // Any cURL?
    if (function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
        // Set dynamic request context
        requestContext($url, 'curl', $ch);
        $data = curl_exec($ch);
        curl_close($ch);
    } else {
        $context = requestContext($url);
        // Fallback on default method
        $data = @file_get_contents($url, false, $context);
    }
    return $data;
}
 /**
  * Context-aware call to setcookie().
  *
  * This method is context-aware and will avoid setting cookies if the request
  * context is not HTTP.
  *
  * @param string $name
  * @param string $value
  * @param integer $expire
  * @param string $path
  * @param string $domain
  * @param boolean|null $secure
  * @param boolean $httponly
  */
 function safeCookie($name, $value = null, $expire = 0, $path = null, $domain = null, $secure = null, $httponly = false)
 {
     static $context = null;
     if (is_null($context)) {
         $context = requestContext();
     }
     if ($context == 'http') {
         if ($secure === null && c('Garden.ForceSSL') && Gdn::request()->scheme() === 'https') {
             $secure = true;
         }
         setcookie($name, $value, $expire, $path, $domain, $secure, $httponly);
     }
 }
Example #5
0
function processUpdate($url)
{
    // Archive path
    $name = md5($url) . '.zip';
    $update_dir = JAPPIX_BASE . '/store/update/';
    $path = $update_dir . $name;
    $extract_to = $update_dir . 'jappix/';
    $store_tree = JAPPIX_BASE . '/server/store-tree.php';
    // We must get the archive from the server
    if (!file_exists($path)) {
        echo '<p>» ' . T_("Downloading package...") . '</p>';
        // Create SSL request context
        $ssl_context = requestContext($url);
        // Open the packages
        $local = fopen($path, 'w');
        $remote = fopen($url, 'r', false, $ssl_context);
        // Could not open a socket?!
        if (!$remote) {
            echo '<p>» ' . T_("Aborted: socket error!") . '</p>';
            // Remove the broken local archive
            unlink($path);
            return false;
        }
        // Read the file
        while (!feof($remote)) {
            // Get the buffer
            $buffer = fread($remote, 1024);
            // Any error?
            if ($buffer == 'Error.') {
                echo '<p>» ' . T_("Aborted: buffer error!") . '</p>';
                // Remove the broken local archive
                unlink($path);
                return false;
            }
            // Write the buffer to the file
            fwrite($local, $buffer);
            // Flush the current buffer
            flush();
        }
        // Close the files
        fclose($local);
        fclose($remote);
    }
    // Then, we extract the archive
    echo '<p>» ' . T_("Extracting package...") . '</p>';
    try {
        $zip = new ZipArchive();
        $zip_open = $zip->open($path);
        if ($zip_open === TRUE) {
            $zip->extractTo($update_dir);
            $zip->close();
        } else {
            echo '<p>» ' . T_("Aborted: could not extract the package!") . '</p>';
            // Remove the broken source folder
            removeDir($to_remove);
            return false;
        }
    } catch (Exception $e) {
        echo '<p>» ' . T_("Aborted: could not extract the package!") . '</p>';
        // Remove the broken source folder
        removeDir($to_remove);
        return false;
    }
    // Remove the ./store dir from the source directory
    removeDir($extract_to . 'store/');
    // Then, we remove the Jappix system files
    echo '<p>» ' . T_("Removing current Jappix system files...") . '</p>';
    // Open the general directory
    $dir_base = JAPPIX_BASE . '/';
    $scan = scandir($dir_base);
    // Filter the scan array
    $scan = array_diff($scan, array('.', '..', '.git', 'store'));
    // Check all the files are writable
    foreach ($scan as $scanned) {
        // Element path
        $scanned_current = $dir_base . $scanned;
        // Element not writable
        if (!is_writable($scanned_current)) {
            // Try to change the element rights
            chmod($scanned_current, 0777);
            // Check it again!
            if (!is_writable($scanned_current)) {
                echo '<p>» ' . T_("Aborted: everything is not writable!") . '</p>';
                return false;
            }
        }
    }
    // Process the files deletion
    foreach ($scan as $current) {
        $to_remove = $dir_base . $current;
        // Remove folders
        if (is_dir($to_remove)) {
            removeDir($to_remove);
        } else {
            // Remove files
            unlink($to_remove);
        }
    }
    // Move the extracted files to the base
    copyDir($extract_to, $dir_base);
    // Remove the source directory
    removeDir($extract_to);
    // Regenerates the store tree
    if (file_exists($store_tree)) {
        echo '<p>» ' . T_("Regenerating storage folder tree...") . '</p>';
        // Call the special regeneration script
        include $store_tree;
    }
    // Remove the version package
    unlink($path);
    // The new version is now installed!
    echo '<p>» ' . T_("Jappix is now up to date!") . '</p>';
    return true;
}