Current time: 11-15-2024, 03:09 AM Hello There, Guest! (LoginRegister)


Post Reply 
Writing CronJobs Web int. It's time!
Author Message
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #1
Writing CronJobs Web int. It's time!
Now, boys and girls...
Let's run!

1. Creating mySQL table cron_jobs in DB ispcp
importing cron_jobs.sql
Code:
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";

CREATE TABLE IF NOT EXISTS `cron_jobs` (
  `cron_id` int(10) unsigned NOT NULL auto_increment,
  `admin_id` int(10) unsigned NOT NULL,
  `cron_name` varchar(100) collate utf8_unicode_ci NOT NULL,
  `cron_desc` varchar(200) collate utf8_unicode_ci NOT NULL,
  `min` varchar(4) collate utf8_unicode_ci NOT NULL,
  `hour` varchar(3) collate utf8_unicode_ci NOT NULL,
  `day` varchar(2) collate utf8_unicode_ci NOT NULL,
  `month` varchar(2) collate utf8_unicode_ci NOT NULL,
  `week` varchar(1) collate utf8_unicode_ci NOT NULL,
  `command` text collate utf8_unicode_ci NOT NULL,
  `cron_activ` int(1) unsigned default NULL,
  `cron_status` varchar(255) collate utf8_unicode_ci NOT NULL,
  PRIMARY KEY  (`cron_id`),
  KEY `cron_id` (`cron_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=7 ;

2. Opening webtools.tpl and under
Code:
<!-- EDP: active_awstats -->
insert
Code:
<tr>
             <td>&nbsp;</td>
             <td class="content">
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
               </tr>
                <td width="65"><a href="cronjobs_overview.php"><img src="{THEME_COLOR_PATH}/images/icons/cron_jobs.gif" alt="CronJobs" width="46" height="46" border="0"></a></td>
                <td><a href="cronjobs_overview.php" class="link">CronJobs</a><br />
                   Jobs Plainer</td>
               </tr>
              </table></td>
            </tr>

3. Opening cronjobs_overview.php and cange blunk funktion to
Code:
function gen_cron_jobs(&$tpl, &$sql, $user_id) {

/*
Function writen by Sergey Obookhoff
www.data-stream.ru
Russia, Moscow
*/

    $query = <<<SQL_QUERY
        SELECT
            cron_id, admin_id, cron_name, cron_desc, cron_activ
        FROM
            cron_jobs
        WHERE
            admin_id = $user_id
        ORDER BY
            cron_id
SQL_QUERY;

    $rs = exec_query($sql, $query, array($user_id));

    if ($rs->RecordCount() == 0) {
        $tpl->assign(
            array('NAME' => tr('Jobs list is empty!'),
                'DESCRIPTION' => '',
                'ACTIVE' => ''
                )
            );

    } else {

        $counter = 0;
        while (!$rs->EOF) {
            if ($counter % 2 == 0) {
                $tpl->assign('ITEM_CLASS', 'content');
            } else {
                $tpl->assign('ITEM_CLASS', 'content2');
            }

            if ($rs->fields['cron_activ'] == 1) {$activ = 'Yes';}
            else {$activ = 'No';};
            if ($rs->fields['cron_status'] != 'ok') {$activ = '<img src=/themes/omega_original/images/icons/reload.png>';}
            $tpl->assign(
                array('NAME' => $rs->fields['cron_name'],
                    'DESCRIPTION' => $rs->fields['cron_desc'],
                    'ACTIVE' => $activ,
                    'ID'  => $rs->fields['cron_id']
                    )
                );
            $tpl->parse('CRONJOBS', '.cronjobs');
            $rs->MoveNext();
            $counter++;
        }

    }

} // End of gen_cron_job();

4. creating cronjobs_delete.php
Code:
<?php
/**
* CronJob Web Interface for ispCP
* @copyright     2009 data-stream.ru
* @copyright     
* @version     1.0
* @link         http://data-stream.ru
* @author         Serge Obookhoff for ispCP Team
*
*/

require '../include/ispcp-lib.php';

check_login(__FILE__);

if (isset($_GET['cron_id']) && $_GET['cron_id'] !== '') {
    $cron_id = $_GET['cron_id'];

    $query = "
        SELECT
            `cron_id`
            `cron_name`
        FROM
            `cron_jobs`
        WHERE
            `cron_id` = ?
    ";

    $rs = exec_query($sql, $query, array($cron_id));

    if ($rs -> RecordCount() == 0) {
        user_goto('cronjobs_overview.php');
    }

    check_for_lock_file();

    $query = "
        UPDATE
            `cron_jobs`
        SET
            `cron_status` = 'delete'
        WHERE
            `cron_id` = ?
    ";

    $rs = exec_query($sql, $query, array($cron_id));

    send_request();
    write_log($_SESSION['user_logged'].": delete cronjob ".$cron_name."!");
    set_page_message(tr('Cronjob scheduled for deletion!'));
    header('Location: cronjobs_overview.php');
    exit(0);
} else {
    header('Location: cronjobs_overview.php');
    exit(0);
}

?>

#chown vu2000:apache cronjobs_delete.php
and chmod it...

And now...
I must go to drink same Russian Vodka, and then I can to rewrite another files Wink
To be continued...
(This post was last modified: 01-05-2009 09:10 AM by data-stream_ru.)
01-05-2009 04:50 AM
Visit this user's website Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #2
RE: Writing CronJobs Web int. It's time!
5. rewrite cronjobs_add.php whith
Code:
<?php
/**
* ispCP П‰ (OMEGA) a Virtual Hosting Control System
*
* @copyright     2001-2006 by moleSoftware GmbH
* @copyright     2006-2008 by ispCP | http://isp-control.net
* @version     SVN: $Id$
* @link         http://isp-control.net
* @author         ispCP Team
*
* @license
*   This program is free software; you can redistribute it and/or modify it under
*   the terms of the MPL General Public License as published by the Free Software
*   Foundation; either version 1.1 of the License, or (at your option) any later
*   version.
*   You should have received a copy of the MPL Mozilla Public License along with
*   this program; if not, write to the Open Source Initiative (OSI)
*   http://opensource.org | osi@opensource.org
*/

require '../include/ispcp-lib.php';

check_login(__FILE__);

$tpl = new pTemplate();
$tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/cronjobs_add.tpl');
$tpl->define_dynamic('page_message', 'page');
$tpl->define_dynamic('logged_from', 'page');

$theme_color = Config::get('USER_INITIAL_THEME');

$tpl->assign(
    array('TR_CLIENT_CRONJOBS_TITLE' => tr('ispCP - Client/Cronjob Manager'),
        'THEME_COLOR_PATH' => "../themes/$theme_color",
        'THEME_CHARSET' => tr('encoding'),
        'ISP_LOGO' => get_logo($_SESSION['user_id'])
        )
    );


function add_cron_job(&$tpl, &$sql, $user_id) {

/*
(с) Sergey Obookhoff, www.data-stream.ru
Russia, Moscow
*/
    if (!isset($_POST['Submit'])) {
        return;
    }

    if ((empty($_POST['name']) | empty($_POST['description']) | empty($_POST['command_line']) | empty($_POST['min']) | empty($_POST['hour']) | empty($_POST['day_of_month']) | empty($_POST['month']) | empty($_POST['day_of_week'])) && isset($_POST['Submit'])) {

        set_page_message(tr('Please type All Fields and Values!'));
        return;
    }

    foreach($_POST as $key => $value)
    {
        $a = $key;
        $$a = $value;
    }

       if ($activ == 0) {$cron_status = "ok";}
    else {$cron_status = Config::get('ITEM_ADD_STATUS');}
    // add cron_job in the ispcp DB;
    $query = "
        INSERT INTO `cron_jobs`
            (`admin_id`, `cron_name`, `cron_desc`, `min`, `hour`, `day`, `month`, `week`, `command`, `cron_activ`, `cron_status`)
        VALUES
            (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

    ";

    $rs = exec_query($sql, $query, array($user_id, $name, $description, $min, $hour, $day_of_month, $month, $day_of_week, $command_line, $activ, $cron_status));

    $query = "
        SELECT
            `cron_id`
            `cron_name`
        FROM
            `cron_jobs`
        WHERE
            `cron_name` = ?
    ";

    $rs = exec_query($sql, $query, array($name));
    $cron_name = $rs->fields['cron_name'];

    send_request();
    write_log($_SESSION['user_logged'] . ": add Cron Job: " . $cron_name);
    set_page_message(tr('Cron Job successfully added!'));
    user_goto('cronjobs_overview.php');


} // End of add_cron_job();

function get_cron_domain(&$tpl, &$sql, $user_id) {

    $query = "
        SELECT
            `admin_name`
        FROM
            `admin`
        WHERE
            admin_id = ?
        ";

       $rs = exec_query($sql, $query, array($user_id));

    return $rs->fields['admin_name'];
    
}


/*
*
* static page messages.
*
*/

gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_webtools.tpl');
gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_webtools.tpl');

gen_logged_from($tpl);

check_permissions($tpl);

add_cron_job($tpl, $sql, $_SESSION['user_id']);

$example = Config::get('APACHE_WWW_DIR') . '/' . get_cron_domain($tpl, $sql, $_SESSION['user_id']) . '/htdocs/test.php' ;

$tpl->assign(
    array('TR_CRON_MANAGER' => tr('Cronjob Manager'),
        'TR_ADD_CRONJOB' => tr('Add Cronjob'),
        'TR_NAME' => tr('Name'),
        'TR_DESCRIPTION' => tr('Description'),
        'TR_ACTIVE' => tr('Active'),
        'YES' => tr('Yes'),
        'NO' => tr('No'),
        'TR_CRONJOB' => tr('Cronjob'),
        'TR_COMMAND' => tr('Command to run:'),
        'TR_MIN' => tr('Minute(s):'),
        'TR_HOUR' => tr('Hour(s):'),
        'TR_DAY' => tr('Day(s):'),
        'TR_MONTHS' => tr('Month(s):'),
        'TR_WEEKDAYS' => tr('Weekday(s):'),
        'TR_ADD' => tr('Add'),
        'TR_RESET' => tr('Reset'),
        'TR_CANCEL' => tr('Cancel'),
        'EXAMPLE' => $example,
        )
    );

gen_page_message($tpl);

$tpl->parse('PAGE', 'page');
$tpl->prnt();

if (Config::get('DUMP_GUI_DEBUG'))
    dump_gui_debug();

unset_messages();

6. Do same help for users
open cronjobs_add.tpl
replace
Code:
<td width="25">&nbsp;</td>
                        <td colspan="5" class="content2">{TR_COMMAND}</td>
                      </tr>
                      <tr>
                        <td width="25">&nbsp;</td>
                        <td colspan="5" class="content"><input name="command_line" type="text" class="textinput" id="command_line" style="width:370px"></td>
                      </tr>
with new code
Code:
<tr>
                        <td width="25">&nbsp;</td>
                        <td colspan="5" class="content2">Enter full SERVER PATH to executed script! {TR_COMMAND}</td>
                      </tr>
                      <tr>
                        <td width="25">&nbsp;</td>
                        <td colspan="5" class="content"><input name="command_line" type="text" class="textinput" id="command_line" value={EXAMPLE} style="width:370px"></td>
                      </tr>

7. fixing format bug in tpl.
Open cronjobs_overview.tpl and replace
Code:
        <tr>
                      <!-- BDP: cronjobs -->
                      <td nowrap="nowrap">&nbsp;</td>
                      <td nowrap="nowrap" class="{ITEM_CLASS}"><strong>{NAME}</strong><br>
                        {DESCRIPTION}</td>
                      <td width="100" align="center" nowrap="nowrap" class="{ITEM_CLASS}">{ACTIVE}</td>
                      <td width="100" nowrap="nowrap" class="{ITEM_CLASS}"><img src="{THEME_COLOR_PATH}/images/icons/edit.png" width="16" height="16" align="absmiddle"> <a href="cronjobs_edit.php?cron_id={ID}" class="link">{TR_EDIT}</a></td>
                      <td width="100" nowrap="nowrap" class="{ITEM_CLASS}"><img src="{THEME_COLOR_PATH}/images/icons/delete.png" width="16" height="16" border="0" align="absmiddle"> <a href="#" class="link" onclick="action_delete('cronjobs_delete.php?cron_id={ID}', '{NAME}')">{TR_DELETE}</a></td>
                      <!-- EDP: cronjobs -->
                    </tr>
whith

Code:
<!-- BDP: cronjobs -->
            <tr>
                      <td nowrap="nowrap">&nbsp;</td>
                      <td nowrap="nowrap" class="{ITEM_CLASS}"><strong>{NAME}</strong><br>
                        {DESCRIPTION}</td>
                      <td width="100" align="center" nowrap="nowrap" class="{ITEM_CLASS}">{ACTIVE}</td>
                      <td width="100" nowrap="nowrap" class="{ITEM_CLASS}"><img src="{THEME_COLOR_PATH}/images/icons/edit.png" width="16" height="16" align="absmiddle"> <a href="cronjobs_edit.php?cron_id={ID}" class="link">{TR_EDIT}</a></td>
                      <td width="100" nowrap="nowrap" class="{ITEM_CLASS}"><img src="{THEME_COLOR_PATH}/images/icons/delete.png" width="16" height="16" border="0" align="absmiddle"> <a href="#" class="link" onclick="action_delete('cronjobs_delete.php?cron_id={ID}', '{NAME}')">{TR_DELETE}</a></td>
                    </tr>
                      <!-- EDP: cronjobs -->

8. rewrite cronjobs_edit.php

Ooops! Vodka is over Sad
I must go to the night shop...
(This post was last modified: 01-05-2009 03:25 PM by data-stream_ru.)
01-05-2009 10:34 AM
Visit this user's website Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #3
RE: Writing CronJobs Web int. It's time!
8. rewrite cronjobs_edit.php
Code:
<?php
/**
* ispCP П‰ (OMEGA) a Virtual Hosting Control System
*
* @copyright     2001-2006 by moleSoftware GmbH
* @copyright     2006-2008 by ispCP | http://isp-control.net
* @version     SVN: $Id$
* @link         http://isp-control.net
* @author         ispCP Team
*
* @license
*   This program is free software; you can redistribute it and/or modify it under
*   the terms of the MPL General Public License as published by the Free Software
*   Foundation; either version 1.1 of the License, or (at your option) any later
*   version.
*   You should have received a copy of the MPL Mozilla Public License along with
*   this program; if not, write to the Open Source Initiative (OSI)
*   http://opensource.org | osi@opensource.org
*/

require '../include/ispcp-lib.php';

check_login(__FILE__);

$tpl = new pTemplate();
$tpl->define_dynamic('page', Config::get('CLIENT_TEMPLATE_PATH') . '/cronjobs_edit.tpl');
$tpl->define_dynamic('page_message', 'page');
$tpl->define_dynamic('logged_from', 'page');

$theme_color = Config::get('USER_INITIAL_THEME');

$tpl->assign(
    array('TR_CLIENT_CRONJOBS_TITLE' => tr('ispCP - Client/Cronjob Manager'),
        'THEME_COLOR_PATH' => "../themes/$theme_color",
        'THEME_CHARSET' => tr('encoding'),
        'ISP_LOGO' => get_logo($_SESSION['user_id'])
        )
    );

/* All functions written by Sergey Obookhoff
* (c) 2009
* www.data-stream.ru
* Moscow, Russia
*/
    if (!isset($_GET['cron_id']) && !isset($_POST['Submit'])) {
    set_page_message(tr('Nothing to do!'));
    user_goto('cronjobs_overview.php');
    }

if (isset($_GET['cron_id']) && $_GET['cron_id'] !== '') {
    $cron_id = $_GET['cron_id'];}


function update_cron_job(&$tpl, &$sql, $cron_id, $user_id) {

    foreach($_POST as $key => $value)
    {
        $a = $key;
        $$a = $value;
    }



       if ($activ == 0) {$cron_status = "ok";}
    else {$cron_status = Config::get('ITEM_ADD_STATUS');}

    $query = "
        UPDATE
            cron_jobs
        SET
            cron_name = ?, cron_desc = ?, min = ?, hour = ?, day = ?, month = ?, week = ?, command = ?, cron_activ = ?, cron_status = ?
        WHERE
            cron_id = ?
    ";

    $rs = exec_query($sql, $query, array($name, $description, $min, $hour, $day_of_month, $month, $day_of_week, $command_line, $activ, $cron_status,$cron_id));



    send_request();
    write_log($_SESSION['user_logged'] . ": updeted Cron Job: " . $cron_name);
    set_page_message(tr('Cron Job successfully updated!'));
    user_goto('cronjobs_overview.php');

} // End of update_cron_job();


function gen_cron_job(&$tpl, &$sql, $cron_id, $user_id) {

    $query = "
        SELECT
            `cron_id`, `admin_id`, `cron_name`, `cron_desc`, `min`, `hour`, `day`, `month`, `week`, `command`, `cron_activ`, `cron_status`
        FROM
            `cron_jobs`
        WHERE
            admin_id = $user_id
     AND
         cron_id = $cron_id
    ";

    $rs = exec_query($sql, $query, array($cron_id));

    if ($rs->RecordCount() == 0) {
    set_page_message(tr('No CronJob with this ID!'));
    header('Location: cronjobs_overview.php');
    exit(0);
    }

    if ($rs->fields['cron_status'] != 'ok') {
    set_page_message(tr('Job is shedalled and can not be editing or deleting!'));
    header('Location: cronjobs_overview.php');
    exit(0);


    } else {
    
    if ($rs->fields['cron_activ'] == 1) {$active_yes = 'selected'; $active_no = '';}
    else  {$active_no = 'selected'; $active_yes = '';}
    $tpl->assign(
        array('NAME' => $rs->fields['cron_name'],
            'DESCRIPTION' => $rs->fields['cron_desc'],
            'COMMAND_LINE' => $rs->fields['command'],
            'ACTIVE' => $rs->fields['cron_activ'],
            'ACTIVE_YES' => $active_yes,
            'ACTIVE_NO' => $active_no,
            'ID'  => $rs->fields['cron_id']
            )
        );
    }

} // End of gen_cron_job();

/*
*
* static page messages.
*
*/

gen_client_mainmenu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/main_menu_webtools.tpl');
gen_client_menu($tpl, Config::get('CLIENT_TEMPLATE_PATH') . '/menu_webtools.tpl');

gen_logged_from($tpl);

check_permissions($tpl);

if (isset($_GET['cron_id']) && is_numeric($_GET['cron_id']) && isset($_POST['Submit']))
    update_cron_job($tpl, $sql, $_GET['cron_id'], $_SESSION['user_id']);

gen_cron_job($tpl, $sql, $cron_id, $_SESSION['user_id']);

$tpl->assign(
    array('TR_CRON_MANAGER' => tr('Cronjob Manager'),
        'TR_EDIT_CRONJOB' => tr('Edit Cronjob'),
        'TR_NAME' => tr('Name'),
        'TR_DESCRIPTION' => tr('Description'),
        'TR_ACTIVE' => tr('Active'),
        'YES' => tr('Yes'),
        'NO' => tr('No'),
        'TR_CRONJOB' => tr('Cronjob'),
        'TR_COMMAND' => tr('Command to run:'),
        'TR_MIN' => tr('Minute(s):'),
        'TR_HOUR' => tr('Hour(s):'),
        'TR_DAY' => tr('Day(s):'),
        'TR_MONTHS' => tr('Month(s):'),
        'TR_WEEKDAYS' => tr('Weekday(s):'),
        'TR_UPDATE' => tr('Update'),
        'TR_CANCEL' => tr('Cancel'),
        )
    );

gen_page_message($tpl);

$tpl->parse('PAGE', 'page');
$tpl->prnt();

if (Config::get('DUMP_GUI_DEBUG'))
    dump_gui_debug();

unset_messages();
?>

9. Opening cronjobs_edit.tpl and removing buggs
{DESCTIPTON} change to {DESCRIPTION}
Smile

action="cronjobs_edit.php"
changing to
action="cronjobs_edit.php?cron_id={ID}"

And repllacing code under <td colspan="4" class="content"><select name="activ">
to
<option value="1" {ACTIVE_YES}>{YES}</option>
<option value="0" {ACTIVE_NO}>{NO}</option>

And becouse multi selection not supported we must delete all multiple="multiple"
And in crongobs_add.tpl too.

But in other highlit selections we have a big truble Sad
Code sample

if ($rs->fields['cron_activ'] == 1) {$active_yes = 'selected'; $active_no = '';}
else {$active_no = 'selected'; $active_yes = '';}
......
'ACTIVE_YES' => $active_yes,
'ACTIVE_NO' => $active_no,
And in the template
<option value="1" {ACTIVE_YES}>{YES}</option>
<option value="0" {ACTIVE_NO}>{NO}</option>

It's not good solution for lage selection feeld in forms.
Any idea?
May be in Java...

And now we have full-function web interfeice to mySQL
But we must convert add mySQL table to the cron files.
And we must write sub for ispcp-rqst-mngr Sad
Any perl Coders are preasent, is not it?
Who is next developer for this function?
Wink
(This post was last modified: 01-05-2009 03:45 PM by data-stream_ru.)
01-05-2009 03:44 PM
Visit this user's website Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #4
RE: Writing CronJobs Web int. It's time!
BUT !
At thise solution we have a very ansecured and easy scripts.
We have not eny checks for users comand.

And also we must add checking in domain-manager for existing cronjobs. And force deleting user's cronjobs if admin deleting his account.
If domain deleted cronjobs must be deleted too.

It's easy we must do it self.


AND now I see anowher solution for cronjob engenee - whithout recoding perl scripts jf ispCP.
Today (after lot of Russian Vodka) I find same packet at sourceforge.net - hcrond-0.3.2.tar.gz
It's demonised JobPlaner such as cron, wich working whith mySQL table.
It can be compeled ad use ispCP table.
Yes!
Only DB field names and some litle points must be changed in My php codes.
01-06-2009 02:00 AM
Visit this user's website Find all posts by this user Quote this message in a reply
xister Offline
Member
*
Beta Team

Posts: 405
Joined: Oct 2006
Reputation: 6
Post: #5
RE: Writing CronJobs Web int. It's time!
(01-06-2009 02:00 AM)data-stream_ru Wrote:  AND now I see anowher solution for cronjob engenee - whithout recoding perl scripts jf ispCP.
Today (after lot of Russian Vodka) I find same packet at sourceforge.net - hcrond-0.3.2.tar.gz
It's demonised JobPlaner such as cron, wich working whith mySQL table.
It can be compeled ad use ispCP table.
Yes!
Only DB field names and some litle points must be changed in My php codes.

Sounds very nice.
Go on with your great work Smile
01-06-2009 04:23 AM
Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #6
RE: Writing CronJobs Web int. It's time!
There are no developers? Only a free users? Sad
Ok, let us go further.
But first, I need ideas on which way we go.
1. Overwrite perl ckripts ispcp under the existing web-interface.
2. Use hcrond and convert my php interface to it.

Discuss?

And now I have to accompany my House-Bear to place for walking and then feed him and give a litle of Vodka. Maybe my drunken Bear tell me the right decision?

2xister
Thank you for your desire

But we must remember that in wey number 2 we have a disintegration of ispCP angine. And may by We may encounter a situation when lost control.
But it's easy way. May be...

Oyyy!
Of course, we must create another user for a table ispcp in this case. For another engine. To resolve conflicts. But this is a security issue.

I need my bear on the board to resolve this problem ...
(This post was last modified: 01-06-2009 05:03 AM by data-stream_ru.)
01-06-2009 04:38 AM
Visit this user's website Find all posts by this user Quote this message in a reply
sci2tech Away
Senior Member
****

Posts: 1,285
Joined: Jan 2007
Reputation: 23
Post: #7
RE: Writing CronJobs Web int. It's time!
Really nice job!!! After V1.0 is out I promise, I`ll write perl code for this (if no one else ill write until then Wink ).
01-06-2009 05:27 AM
Visit this user's website Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #8
RE: Writing CronJobs Web int. It's time!
I asked my good coder to preapere same checks to $comand_line ... This is necessary for any option.

And now, My wise Bear said that we can try both ways. And we can start whith hcrond-0.3.2.
But my Dog, which is an authoritative system administrator ( http://hong-lee.bull-doc.ru/images/012.jpg ) , told me that we do not have much time to test all way.

Do not be surprised us all Bear in Russia can write php-scripts and each dog manages the server after slightly Russian Vodka. As well as babies know how to do overclocking and hacking....

About the case...
I see the samthing hcrond at the thirst time. And I dont now anything about this stability and cecuritu.
I need to rapid betta-testers.
And at his point we see 2 pacages at http://sourceforge.net/project/showfiles..._id=474735
My Bear read the "README", but was unable to explain to me the difference Sad

What package we must use for ispSP?
And what about they cecure and stability?
01-06-2009 06:25 AM
Visit this user's website Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #9
RE: Writing CronJobs Web int. It's time!
Code for litle checking $comand_line

Code:
<?php

// Vladimir Sinitsyn aka SenatoR
// Russia, Yekaterinburg
// Русские, привет! =)


#$command_line = "/aaa.php?bb=ccc&e";


$file_type = array('.php','.php4','.php5,'.cgi','.pl','.py'); //List of GOOD files ;-)
// only php, perl and python we let to execute

//Let`s start our work!

$flag = 0; //Use one thing!

  foreach($file_type as $k=>$v) //Start
  {

      if(strpos($command_line,$v) == true) //Works fast!!! (its important)
    {    
        $flag++; //Yeah! Its good!
        
        $file = preg_replace("/(\\".$v.").*/i","\\1",$command_line); //CUT ALL!!! Only filename in $file!
        break; //Stop
    }
  }

if($flag == 0) exit; //Nothing to do!

//Check something...

if(!file_exists($file)) exit; //No file!

if(!is_readable($file)) exit; //Wrong permissions!

if(strpos("cgi",$file) || strpos("pl",$file)) // only for cgi and pl and so..
{
    if(!is_executable($file)) exit; //Wrong permissions!
}

?>

We can add thise simply checks to cronjobs_add.php & cronjobs_edit.php in future.

And now I go to testing hcrond-0.3.2.tar.gz
I do not know what is hcrond-nopid.
(This post was last modified: 01-07-2009 02:30 AM by data-stream_ru.)
01-07-2009 02:29 AM
Visit this user's website Find all posts by this user Quote this message in a reply
data-stream_ru Offline
Moderator
*****
Moderators

Posts: 471
Joined: Jan 2009
Reputation: 7
Post: #10
RE: Writing CronJobs Web int. It's time!
hcrond...
So litle program and so more problems and bugzzzz Sad
Columns gid and uid use Names of user and names of groups, not gid/uid!
Column "machine" is ignored.
Column "andor" can crash job.
But the table have a column "lastrun". Looks nice. We can use it for control of Jobs exucutabling.

During compilation i lost 3-4 hours becouse information about needed preinstalled packes is absent or wrong! -
In new mysqld we do not need libmysqlclient-devel, we need mysql-devel !
And we need "lex" in PATH or properly installed "flex" pacage.

I rewrite Makefile for x64 systems whith lines
CFLAGS=-std=c99 -Wall -W
LDFLAGS= -I'/usr/include/mysql' -L/usr/lib64/mysql -lmysqlclient -ldaemon -lpthread

And I rewrite ./init.d/hcrond for chkconfig
Code:
#!/bin/bash
# hcrond        Startup script for the hcrond
#
# chkconfig: - 90 12
# description: Startup script for hcrond
# processname: hcrond
# config: /etc/hcrondrc
# pidfile: /var/run/hcrond.pid

# Source function library.
. /etc/rc.d/init.d/functions

test -f /usr/bin/hcrond || exit 0

. /lib/lsb/init-functions

pidfile=/var/run/hcrond.pid
lockfile=${LOCKFILE-/var/lock/hcrond}

## TODO get from /etc/hcrondrc

case "$1" in
start)
    echo -n  "Starting hcrond..."
       daemon hcrond
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        ;;
stop)  
    echo -n  "Stopping hcrond..."
       killproc hcrond
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
        ;;
restart)
    echo -n  "ReStarting hcrond..."
       killproc hcrond
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    daemon hcrond
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        ;;
reload|force-reload)
    echo -n  "Reloading configuration files for hcrond..."
        # cron reloads automatically
        echo $?
        ;;
*)      echo "Usage: /etc/init.d/hcrond {start|stop|restart|reload|force-reload}"
        exit 1
        ;;
esac
exit 0

Its worked.

Now I asked my Cooder to do litle add in main.c to posibility use column "activ" for compatibiliti for ispCP templates.

So more truble Sad I do not know can I (whith my Home-Bear) to drink so lot of Russian Vodka for solving this problems or we have a risc to meet a doctors Wink
(This post was last modified: 01-08-2009 05:11 AM by data-stream_ru.)
01-08-2009 04:51 AM
Visit this user's website Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)