Exemplo n.º 1
0
 function edit($params)
 {
     if (!isset($params['id'])) {
         bail("Must haz id to show you that!");
     }
     $this->data->staff = new Staff($params['id']);
 }
Exemplo n.º 2
0
 function namespaceAlias($alias)
 {
     if (!$alias) {
         bail('You must specify an alias.');
     }
     return '/' . $this->getStaff()->getPermalink() . '/' . $alias;
 }
Exemplo n.º 3
0
function expandversion($vstr)
{
    $v = explode('.', $vstr);
    if ($vstr == '' || count($v) == 0 || count($v) > 4) {
        bail('Bogus version.');
    }
    $vlen = count($v);
    $ret = array();
    $hasplus = 0;
    for ($i = 0; $i < 4; $i++) {
        if ($i > $vlen - 1) {
            // this version chunk was not specified; give 0
            $ret[] = 0;
        } else {
            $s = $v[$i];
            if ($i == 3) {
                // need to check for +
                $slen = strlen($s);
                if ($s[$slen - 1] == '+') {
                    $s = substr($s, 0, $slen - 1);
                    $hasplus = 1;
                }
            }
            $ret[] = intval($s);
        }
    }
    $ret[] = $hasplus;
    return $ret;
}
Exemplo n.º 4
0
 function destroy($params)
 {
     $params['id'] ? $clientuser = new ClientUser($params['id']) : bail('no company selected');
     $name = $clientuser->getName();
     $clientuser->destroy();
     Render::msg($name . ' Deleted.', 'bad');
     $this->redirectTo(array('controller' => 'ClientUser', 'action' => 'index'));
 }
Exemplo n.º 5
0
 function controller_path()
 {
     $path = 'controller/' . $this->controller . '.php';
     if (!file_exists($path)) {
         bail('requested controller "' . $this->controller . '" does not exist.');
     }
     return $path;
 }
Exemplo n.º 6
0
 function show($params)
 {
     if (!isset($params['id'])) {
         bail("id is a required param.");
     }
     $this->data->batch = new InvoiceBatch($params['id']);
     $this->data->invoices = $this->data->batch->getInvoices();
 }
Exemplo n.º 7
0
 function getFieldSetFor($obj)
 {
     if (!is_a($obj, 'ActiveRecord')) {
         bail('Cannot get fields for non-ActiveRecord objects');
     }
     $obj->id ? $fields = new FieldSet($obj) : ($fields = new FieldSet($obj, $this->incrementNewObjectCounterFor($obj)));
     return $fields;
 }
Exemplo n.º 8
0
 function f2b_block_user_enumeration($redirect_url, $requested_url)
 {
     if (intval(@$_GET['author'])) {
         f2b_openlog();
         syslog(LOG_NOTICE, 'Blocked user enumeration attempt from ' . f2b_remote_addr());
         bail();
     }
     return $redirect_url;
 }
Exemplo n.º 9
0
 function destroy($params)
 {
     if (empty($params['id'])) {
         bail('Required parameter id not set.');
     }
     $contact = new Contact($params['id']);
     $contact->destroy();
     $this->redirectTo(array('controller' => 'Contact', 'action' => 'index'));
 }
Exemplo n.º 10
0
 function destroy($params)
 {
     if (!isset($params['id'])) {
         bail("Must haz id to do that!");
     }
     $inv = new Invoice($params['id']);
     $inv->destroy();
     $this->redirectTo(array('controller' => 'Invoice', 'action' => 'index'));
 }
Exemplo n.º 11
0
 function destroy($params)
 {
     if (empty($params['id'])) {
         bail('required param["id"] not set.');
     }
     $bookmark = new bookmark($params['id']);
     $bookmark->destroy();
     $this->redirectBack();
 }
Exemplo n.º 12
0
 function destroy($params)
 {
     if (empty($params['id'])) {
         bail('Required param["id"] not set.');
     }
     $note = new note($params['id']);
     $note->destroy();
     $this->redirectTo(array('controller' => 'Note', 'action' => 'index'));
 }
Exemplo n.º 13
0
 function destroy($params)
 {
     if (!isset($params['id'])) {
         bail('Required parameter "id" is missing.');
     }
     $inv = new Charge($params['id']);
     $inv->destroy();
     $this->redirectTo(array('controller' => 'Charge', 'action' => 'index'));
 }
Exemplo n.º 14
0
 function setSource($sourcename)
 {
     parent::setSource($sourcename);
     $this->_itemdata_keys = $this->_getColumnNames($this->datatable);
     if (!is_array($this->_itemdata_keys)) {
         bail('This model has no collumns in the database. Check to see if you ran the latest migrations, and make sure you set the correct datatable name on the model');
     }
     $this->_allowed_keys = $this->_itemdata_keys;
 }
Exemplo n.º 15
0
 function destroy($params)
 {
     if (!$params['id']) {
         bail('Required $params["id"] not present.');
     }
     $h = new Hour($params['id']);
     $support_contract_id = $h->get('support_contract_id');
     $h->destroy();
     isset($params['redirect']) ? $redirect = $params['redirect'] : ($redirect = array('controller' => 'SupportContract', 'action' => 'show', 'id' => $support_contract_id));
     $this->redirectTo($redirect);
 }
Exemplo n.º 16
0
function try_query($query)
{
    global $connection;
    decho("Query is: {$query} <BR>\n");
    $result = mysqli_query($connection, "{$query}");
    if (!$result) {
        $epitaph = "unhappy return status from the database";
        bail($epitaph);
    }
    return $result;
}
Exemplo n.º 17
0
 function replace_tags($tags = array())
 {
     if (count($tags) > 0) {
         foreach ($tags as $tag => $data) {
             //                $data = ( file_exists( $data))  ? $this->runFile($data) : $data;
             $this->html = preg_replace("/\\[\\[" . $tag . "\\]\\]/i", $data, $this->html);
         }
         $this->html = preg_replace("/\\[\\[[^\\]]*\\]\\]/", '', $this->html);
     } else {
         bail("No tags designated for replacement.");
     }
 }
Exemplo n.º 18
0
 function show($params)
 {
     if (!$params['id']) {
         bail('Required parameter "id" is not present.');
     }
     $d = $this->data;
     $d->estimate = new Estimate($params['id']);
     $d->project = new Project($d->estimate->get('project_id'));
     $d->new_hour = new Hour();
     $d->new_hour->set(array('estimate_id' => $params['id'], 'staff_id' => Session::getUserId(), 'date' => date('Y-m-d')));
     $d->new_estimate = new Estimate();
     $d->new_estimate->set(array('project_id' => $d->project->id));
     $d->estimates = $d->project->getEstimates();
     $d->hours = getMany('Hour', array('estimate_id' => $params['id'], 'sort' => 'date DESC'));
 }
Exemplo n.º 19
0
 function show($params)
 {
     if (empty($params['id'])) {
         bail('No company selected.');
     }
     $this->data->company = new Company($params['id']);
     $user_id = Session::getUserId();
     $p = new Project();
     $p->set(array('company_id' => $params['id'], 'staff_id' => $user_id));
     $this->data->new_project = $p;
     $this->data->new_note = new Note();
     $this->data->new_note->set(array('date' => date('Y-m-d'), 'staff_id' => Session::getUserId(), 'company_id' => $params['id']));
     $this->data->new_charge = new Charge();
     $this->data->new_charge->set(array('date' => date('Y-m-d'), 'company_id' => $params['id']));
     $this->data->new_payment = new Payment();
     $this->data->new_payment->set(array('date' => date('Y-m-d'), 'company_id' => $params['id']));
     $this->data->new_invoice = new Invoice();
     $this->data->new_invoice->set(array('company_id' => $params['id']));
     $this->data->new_contact = new Contact();
     $this->data->new_contact->set(array('company_id' => $params['id']));
 }
Exemplo n.º 20
0
 function getHistory($o = array())
 {
     if (!empty($o['types'])) {
         $types = array_intersect($o['types'], $this->history_types);
         unset($o['types']);
     } else {
         $types = $this->history_types;
     }
     $history = array();
     foreach ($types as $type) {
         $method_name = 'get' . $type;
         if (!method_exists($this, $method_name)) {
             bail('Method ' . get_class($this) . '::' . $method_name . ' not found.');
         }
         $history_objects = $this->{$method_name}();
         if (!$history_objects) {
             continue;
         }
         $history = array_merge($history, $history_objects);
     }
     usort($history, array($this, 'compareHistoryDates'));
     return $history;
 }
Exemplo n.º 21
0
 function find($view_function_name)
 {
     if (isset($this->custom_locations[$view_function_name])) {
         return $this->custom_locations[$view_function_name];
     }
     $probable_filename = snake_case($view_function_name);
     $reg_ex = '/[^_]*/';
     preg_match($reg_ex, $probable_filename, $matches);
     $folder_name = $matches[0];
     $default_path = 'view' . DIRECTORY_SEPARATOR . $folder_name . DIRECTORY_SEPARATOR . $probable_filename . '.php';
     if (file_exists($default_path)) {
         return $default_path;
     }
     $i = 0;
     $test_filename = array();
     foreach ($this->_view_paths as $test_path) {
         $i++;
         $test_filename[$i] = $test_path . DIRECTORY_SEPARATOR . $probable_filename . '.php';
         if (file_exists($test_filename[$i])) {
             return $test_filename[$i];
         }
     }
     bail("View {$view_function_name} could not be found.<br>GTD looked in the following locations:<br>{$default_path}<br>" . array_dump($test_filename));
 }
Exemplo n.º 22
0
}
if (array_key_exists('l', $options)) {
    foreach ($squirrel->listAccounts() as $id => $name) {
        echo 'Account ID: ', $id, ' - ', $name, "\n";
    }
    exit(0);
}
if (array_key_exists('a', $options) && array_key_exists('f', $options)) {
    if (file_exists($options['f']) === false) {
        bail('The file containing your forecast expenses does not exists');
    }
    include $options['f'];
    $transactions = $squirrel->extractAndForecast($options['a'], $expenses_monthly);
} else {
    $transactions = $squirrel->loadTransactions();
}
if (array_key_exists('o', $options)) {
    $squirrel->setOutputFile($options['o']);
    $squirrel->saveToFile($transactions);
} else {
    bail('Please indicate the output file name with the -o flag');
}
function bail($msg = '')
{
    if (empty($msg)) {
        echo "\nUsage:\n    php extract.php -d/path/to/database\n    php extract.php -l -d/path/to/database # list accounts\n    php extract.php -l -oextract.csv -d/path/to/database\n    php extract.php -l -aACCOUNTID -oextract.csv -d/path/to/database\n\nExamples:\n    php extract.php -a3 -fexpenses.php -ofoo.csv -ddatabase.squirrel #extracts transactions for account 3, from the list accounts";
    } else {
        echo "{$msg}\n";
    }
    exit(1);
}
Exemplo n.º 23
0
 private function getPageController()
 {
     require_once $this->router->controller_path();
     return class_exists($this->router->controller) ? new $this->router->controller() : bail("Requested controller <b>{$this->router->controller}</b> does not exist, but controller path <b>{$this->router->controller_path()}</b> <i>does</i> exist.  Maybe the controller name is misspelled?");
 }
Exemplo n.º 24
0
if (defined('WP_FAIL2BAN_BLOCKED_USERS')) {
    add_action('authenticate', function ($user, $username, $password) {
        if (!empty($username) && preg_match('/' . WP_FAIL2BAN_BLOCKED_USERS . '/i', $username)) {
            openlog();
            \syslog(LOG_NOTICE, "Blocked authentication attempt for {$username} from " . remote_addr());
            bail();
        }
        return $user;
    }, 1, 3);
}
if (defined('WP_FAIL2BAN_BLOCK_USER_ENUMERATION') && true === WP_FAIL2BAN_BLOCK_USER_ENUMERATION) {
    add_filter('redirect_canonical', function ($redirect_url, $requested_url) {
        if (intval(@$_GET['author'])) {
            openlog();
            \syslog(LOG_NOTICE, 'Blocked user enumeration attempt from ' . remote_addr());
            bail();
        }
        return $redirect_url;
    }, 10, 2);
}
add_action('wp_login', function ($user_login, $user) {
    openlog();
    \syslog(LOG_INFO, "Accepted password for {$user_login} from " . remote_addr());
}, 10, 2);
add_action('wp_login_failed', function ($username) {
    openlog();
    \syslog(LOG_NOTICE, "Authentication failure for {$username} from " . remote_addr());
});
if (defined('WP_FAIL2BAN_LOG_PINGBACKS') && true === WP_FAIL2BAN_LOG_PINGBACKS) {
    add_action('xmlrpc_call', function ($call) {
        if ('pingback.ping' == $call) {
Exemplo n.º 25
0
 function calculateMonthlyBaseRate($month = null, $legacy_month = true)
 {
     if (!$month) {
         bail('calculateMonthlyBaseRate called without a valid month');
     }
     if (!$legacy_month) {
         $month = str_replace('-', '', $month);
     }
     $start_date = $this->get('start_date');
     $start_month = Util::is_a_date($start_date) ? date('Ym', strtotime($start_date)) : false;
     // Check to see ifcurrent month is the starting month of the contract
     if ($month == $start_month) {
         $monthly_rate = $this->get('monthly_rate') * Util::percent_of_month_from_end($start_date);
         return $monthly_rate;
     }
     $end_date = $this->get('end_date');
     $end_month = Util::is_a_date($end_date) ? date('Ym', strtotime($end_date)) : false;
     // Check to see ifcurrent month is the ending month of the contract
     if ($month == $end_month) {
         $monthly_rate = $this->get('monthly_rate') * Util::percent_of_month_from_start($end_date);
         return $monthly_rate;
     }
     $monthly_rate = $this->get('monthly_rate');
     return $monthly_rate;
 }
Exemplo n.º 26
0
    }
    echo "Try {$scriptName} --help\n";
    exit;
}
if (array_key_exists('help', $opts)) {
    usage();
    exit;
}
$missing = array();
foreach (array('email', 'password', 'pkey', 'ekey') as $k) {
    if (!isset($opts[$k]) || !$opts[$k]) {
        $missing[] = $k;
    }
}
if (count($missing)) {
    bail('Missing options: ' . implode(', ', $missing));
}
try {
    if (isset($opts['url']) && $opts['url']) {
        $url = $opts['url'];
    } else {
        $url = API_ENDPOINT_URL;
    }
    echo "Using {$url}\n";
    echo "Instantiating client ... \n";
    $fuze = new Fuze_Client($url, $opts['pkey'], $opts['ekey']);
    echo "Checking keys ... ";
    $keysOk = $fuze->checkKeys();
    echo ($keysOk ? 'passed.' : 'failed!') . "\n";
    if (!$keysOk) {
        exit(1);
Exemplo n.º 27
0
function download_url($url, $destfile = null, $proxy = null)
{
    $use_suggested_filename = $destfile === null;
    if ($use_suggested_filename) {
        $destfile = basename($url);
    }
    $tmp = parse_url($url);
    if (empty($tmp['port'])) {
        $tmp['port'] = 80;
    }
    if (empty($proxy)) {
        $fp = fsockopen($tmp['host'], $tmp['port'], $errno, $errstr);
        //print "\nconnecting to $tmp[host]:$tmp[port]\n";
    } else {
        $tmp_proxy = parse_url($proxy);
        $phost = $tmp_proxy['host'];
        $pport = $tmp_proxy['port'];
        $fp = fsockopen($phost, $pport, $errno, $errstr);
        //print "\nconnecting to $phost:$pport\n";
    }
    if (!$fp) {
        bail("download of {$url} failed: {$errstr} ({$errno})\n");
    }
    if (empty($proxy)) {
        $path = $tmp['path'];
    } else {
        $path = "http://{$tmp['host']}:{$tmp['port']}{$tmp['path']}";
    }
    if (isset($tmp['query'])) {
        $path .= "?{$tmp['query']}";
    }
    if (isset($tmp['fragment'])) {
        $path .= "#{$tmp['fragment']}";
    }
    $request = "GET {$path} HTTP/1.0\r\nHost: {$tmp['host']}:{$tmp['port']}\r\n" . "User-Agent: go-pear\r\n";
    if (!empty($proxy) && $tmp_proxy['user'] != '') {
        $request .= 'Proxy-Authorization: Basic ' . base64_encode($tmp_proxy['user'] . ':' . $tmp_proxy['pass']) . "\r\n";
        //        print "\nauthenticating against proxy with : user = ${tmp_proxy['user']} \n";
        //        print "and pass = ${tmp_proxy['pass']}\n";
    }
    // if
    $request .= "\r\n";
    fwrite($fp, $request);
    $cdh = "content-disposition:";
    $cdhl = strlen($cdh);
    $content_length = 0;
    while ($line = fgets($fp, 2048)) {
        if (trim($line) == '') {
            break;
        }
        if (preg_match('/^Content-Length: (.*)$/i', $line, $matches)) {
            $content_length = trim($matches[1]);
        }
        if ($use_suggested_filename && !strncasecmp($line, $cdh, $cdhl)) {
            if (eregi('filename="([^"]+)"', $line, $matches)) {
                $destfile = basename($matches[1]);
            }
        }
    }
    if ($content_length) {
        displayHTMLSetDownload($destfile);
    }
    $wp = fopen($destfile, "wb");
    if (!$wp) {
        bail("could not open {$destfile} for writing\n");
    }
    $bytes_read = 0;
    $progress = 0;
    while ($data = fread($fp, 2048)) {
        fwrite($wp, $data);
        $bytes_read += strlen($data);
        if ($content_length != 0 && floor($bytes_read * 10 / $content_length) != $progress) {
            $progress = floor($bytes_read * 10 / $content_length);
            displayHTMLDownloadProgress($progress * 10);
        }
    }
    fclose($fp);
    fclose($wp);
    return $destfile;
}
Exemplo n.º 28
0
 function sendEmail()
 {
     if (!isset($this->id)) {
         bail("must haz id to do that!");
     }
     //trigger_error('Invoice #'.$this->id.' preparing to send email');
     $d = new PHP5_Accessor();
     $d->invoice = $this;
     $d->company = $this->getCompany();
     $r = getRenderer();
     $htmlcontent = $r->view('invoiceEmail', $d);
     $plaincontent = $r->view('invoiceEmailPlain', $d);
     $email_address = $this->getBillingEmailAddress() . $this->getAdditionalRecipients();
     if ($this->getType() == 'dated') {
         $subject = 'Radical Designs Invoice ' . Util::pretty_date($this->get('end_date'));
     } else {
         $subject = 'Radical Designs Invoice ' . Util::pretty_date($this->get('date'));
     }
     $boundary = "nextPart";
     $headers = 'From: ' . BILLING_EMAIL_ADDRESS . "\n";
     $headers .= "MIME-Version: 1.0\n";
     $headers .= "Content-Type: multipart/alternative; boundary = {$boundary}\n\n";
     $headers .= "This is a MIME encoded message.\n\n";
     $headers .= "\n--{$boundary}\n";
     // beginning \n added to separate previous content
     $headers .= "Content-type: text/plain; charset=iso-8859-1\n";
     $headers .= $plaincontent;
     $headers .= "\n\n--{$boundary}\n";
     $headers .= "Content-type: text/html; charset=iso-8859-1\n";
     $headers .= $htmlcontent;
     $email_sent = mail($email_address, $subject, "", $headers);
     if ($email_sent) {
         $this->set(array('sent_date' => Util::date_format(), 'status' => 'sent'));
         Render::msg('Email Sent');
     } else {
         $this->set(array('status' => 'failed'));
         Render::msg('Email Failed To Send', 'bad');
     }
     $this->save();
 }
Exemplo n.º 29
0
function temp_dir($default = false)
{
    global $ptmp, $prefix;
    if ($default) {
        if (!@is_dir($default)) {
            if (!mkdir_p($default)) {
                return false;
            }
        }
        /* try it really, is_writable is buggy with openbasedir */
        $fh = @fopen(realpath($default) . "/test", "wb");
        if ($fh) {
            $ptmp = $default;
            return true;
        } else {
            $ptmp = "failed";
            return false;
        }
    }
    $_temp = false;
    if (WINDOWS) {
        if (my_env('TEMP')) {
            $_temp = my_env('TEMP');
        } elseif (my_env('TMP')) {
            $_temp = my_env('TMP');
        } elseif (my_env('windir')) {
            $_temp = my_env('windir') . '\\temp';
        } elseif (my_env('SystemRoot')) {
            $_temp = my_env('SystemRoot') . '\\temp';
        }
        // handle ugly ENV var like \Temp instead of c:\Temp
        $dirs = explode("\\", realpath($_temp));
        if (strpos($_temp, ":") != 1) {
            unset($_temp);
            $_dirs = array();
            foreach ($dirs as $val) {
                if ((bool) $val) {
                    $_dirs[] = str_replace("/", "", $val);
                }
            }
            unset($dirs);
            $dirs = $_dirs;
            array_unshift($dirs, "c:");
            $_temp = $dirs[0];
            for ($i = 1; $i < count($dirs); $i++) {
                $_temp .= "//" . $dirs[$i];
            }
        }
        $ptmp = $_temp;
    } else {
        $_temp = my_env('TMPDIR');
        if (!$_temp) {
            if (is_writable('/tmp')) {
                $_temp = '/tmp';
            }
        }
    }
    // If for some reason the user has no rights to access to
    // the standard tempdir, we assume that he has the right
    // to access his prefix and choose $prefix/tmp as tempdir
    if (!$_temp) {
        print "System's Tempdir failed, trying to use \$prefix/tmp ...";
        $res = mkdir_p($prefix . '/tmp');
        if (!$res) {
            bail('mkdir ' . $prefix . '/tmp' . ' ... failed');
        }
        $ptmp = $prefix . '/tmp';
        $_temp = tempnam($prefix . '/tmp', 'gope');
        rm_rf($_temp);
        mkdir_p($_temp, 0700);
        $ok = @chdir($ptmp);
        if (!$ok) {
            // This should not happen, really ;)
            bail('chdir ' . $ptmp . ' ... failed');
        }
        print "ok\n";
        // Adjust TEMPDIR envvars
        if (!isset($_ENV)) {
            $_ENV = array();
        }
        $_ENV['TMPDIR'] = $_ENV['TEMP'] = $prefix . '/tmp';
    } else {
        $_temp = tempnam($_temp . '/tmp', 'gope');
    }
    $temp_dir = $ptmp = $_temp;
    return true;
}
Exemplo n.º 30
0
if (array_key_exists('help', $opts)) {
    usage();
    exit;
}
$missing = array();
foreach (array('f', 'email', 'password', 'pkey', 'ekey') as $k) {
    if (!isset($opts[$k]) || !$opts[$k]) {
        $missing[] = $k;
    }
}
if (count($missing)) {
    bail('Missing options: ' . implode(', ', $missing));
}
$filePathName = @realpath($opts['f']);
if (!is_readable($filePathName)) {
    bail("File {$filePathName} missing or not readable");
}
try {
    if (isset($opts['url']) && $opts['url']) {
        $url = $opts['url'];
    } else {
        $url = API_ENDPOINT_URL;
    }
    echo "Instantiating client ({$url})... \n";
    $fuze = new Fuze_Client($url, $opts['pkey'], $opts['ekey']);
    echo "Checking keys ... ";
    $keysOk = $fuze->checkKeys();
    echo ($keysOk ? 'passed.' : 'failed!') . "\n";
    if (!$keysOk) {
        exit(1);
    }