Jump to content

eddedwards

Members
  • Posts

    31
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

eddedwards's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. yes that looks like a good starting point. ill have a proper read of that later. thanks.
  2. Ok, so im thinking of starting up working in development and have started working on some basic php tools that I will use to write peoples websites with, like template system and db wrap etc. Now how would I go about copywriting and licensing if I wanted to make a specific tool open source but still keeping everything outside of that specific tool copywritable to myself and chargeable. How would this work? or could I consider my charges to people as a service rather than licensing the software? In the end I would like the tool to have the following T&C: 1: Free for use and modification but only in a non-commercial environment. 2: Any significant modifications of the free version must have authors permission before public use which will be gained by sending the author the modifications for possible addition into future versions, credit will be given obviously. 3: Commercial use or a commercial version requires authors permission (in the form of a pricetag)
  3. Cheers for the input. Id like some clarification if possible. 1: get_db_handler was in the global scope because I could figure out a way of doing it another way. I need to pass a database type from a config array then load the right extension. I didn't think it would work from inside the db_handler class or its extensions unless something like this is possible: <?php class db_h { var $db_type; function __construct($type) { $class = $type . "_h"; $this->db_type = new $class(); } } class sqlite_h { } $test = new db_h("sqlite"); ?> 2: I can see what you mean about the set_data & the switching though I shall look into tidying that up. Thanks again im going to go test my theory.
  4. Ive been studying abstract classes and interfaces and was trying to come up with a good way of using it for a database handler. I want it for a cms project im doing and would like to know if this is a good way of doing it. c_db_handler.php: 1. Function for getting the handler. 2. Abstract db_handler class. 3+ Supported db extension classes. (Currently working with SQLite and MySql skeleton in place) <?php function get_db_handler ($db_type) { $args = func_get_args(); switch ($args[0]) { case "SQLite" : if (func_num_args() == 3) return new sqlite_handler($args[1],$args[2]); break; case "MySQL" : return new mysql_handler(); break; } } abstract class db_handler { // Possible data connection requirements. protected $db_name; protected $db_path; protected $db_perm; protected $db_server; protected $db_user; protected $db_pass; // DB Handler Variables. protected $handle; protected $result; protected $errors = array(); protected $result_type; abstract protected function connect(); abstract protected function disconnect(); abstract protected function parse_query($sql); abstract protected function parse_query_exec($sql); abstract public function fetch_result($fetch_type); function set_data($name=NULL,$path=NULL,$perm=NULL,$server=NULL,$user=NULL,$pass=NULL,$res_type=SQLITE_ASSOC) { if ($name) $this->db_name = $name; if ($path) $this->db_path = $path; if ($perm) $this->db_perm = $perm; if ($server) $this->db_server = $server; if ($user) $this->db_user = $user; if ($pass) $this->db_pass = $pass; $this->result_type = $res_type; } } class sqlite_handler extends db_handler { function __construct($db_path,$db_name) { $this->set_data($db_name,$db_path,0666,NULL,NULL,NULL); } function connect() { if ($this->handle = sqlite_open($this->db_path . $this->db_name,$this->db_perm,&$this->errors[])) { return true; } else { return false; } } function disconnect() { sqlite_close($this->handle); } function parse_query($sql) { if ($this->result = sqlite_query($this->handle,$sql,$this->result_type,&$this->errors[])) { return true; } else { return false; } } function parse_query_exec ($sql) { if ($this->result = sqlite_exec($this->handle,$sql,&$this->errors[])) { return true; } else { return false; } } function fetch_result($fetch_type) { $data = false; switch (strtolower($fetch_type)) { case "all" : if ($data = sqlite_fetch_all($this->result, $this->result_type)) return $data; break; case "array" : if ($data = sqlite_fetch_array($this->result, $this->result_type)) return $data; break; case "string" OR "single" : if ($data = sqlite_fetch_single($this->result)) return $data; break; } return $data; } } class mysql_handler extends db_handler { function connect() { } function disconnect() { } function parse_query($sql) { } function parse_query_exec ($sql) { } function fetch_result($fetch_type) { } } ?> index.php: Usage code. <?php include_once("./inc/c_db_handler.php"); $sql[1] = <<<SQL BEGIN; CREATE TABLE test ( foo VARCHAR(10), bar VARCHAR(10) ); INSERT INTO test (foo,bar) VALUES ("test1","test2"); COMMIT; SQL; $sql[2] = <<<SQL SELECT * FROM test; SQL; $db = get_db_handler("SQLite",NULL,":memory:"); $db->connect(); $db->parse_query_exec($sql[1]); $db->parse_query($sql[2]); //$end = $db->fetch_result("all"); while ($row = $db->fetch_result("array") ) { $end .= "<pre>" . print_r($row,true) . "</pre>"; } $db->disconnect(); echo "<pre>" . print_r($db,true) . "</pre>"; echo "<pre>" . print_r($end,true) . "</pre>"; ?> output of this test: sqlite_handler Object ( [db_name:protected] => :memory: [db_path:protected] => [db_perm:protected] => 438 [db_server:protected] => [db_user:protected] => [db_pass:protected] => [handle:protected] => Resource id #3 [result:protected] => Resource id #4 [errors:protected] => Array ( [0] => [1] => [2] => ) [result_type:protected] => 1 ) Array ( [foo] => test1 [bar] => test2 )
  5. How are you calling the function? $test = new myclass(); $test->dostuffwithitems(); // this wouldnt work i dont think as your returning an array to nowhere. I think you need to change the function a little. maybee a little like this. function dostuffwithitems() { $stuff = array('asdf','iuayhdiufayhi','yy4nehdu'); $this->items = $stuff; // <------ return true; } or call your function into a variable. $myclass->items = $myclass->dostuffwithitems();
  6. Most of the pages were pretty complicated but I think I can say im gonna stick with the way ive been doing it at least. Cheers for that.
  7. Im wondering what the main differences or limitations there are between the following examples. I think there just 2 ways of doing the same thing but I'm not sure. Should I be using extensions or subclass' or does it even matter. Im currently using the example 1 method and in the same sort of program. <?php // example 1 class DB_Handler { var $subclass, $connection, $result; function __construct($db_type) { switch ($db_type) { case "mysql": $this->subclass = new mysql_database(); break; case "sqlite": $this->subclass = new sqlite_database(); break; } } function query($args) { $this->subclass->query($args); } } $instance = new DB_Handler("sqlite"); $instance->query('foobar'); echo $instance->result; // **************************************************** // example 2 class DB_Handler { var $connection, $result } class mysql_database extends DB_Handler { function query() { // do query stuff } } $instance = new mysql_database(); $instance->query('foobar'); echo $instance->result; ?>
  8. Hi, my names Edd I live in Cambridgeshire UK. Im 25, am single and i have a cat. I pop into this site every now and again to see whats new or find help for some silly mistake ive made. My alter ego to the computer geek is a Turtablist Scratch Geek, I write music although im not good yet, Im currently in a scratch group and practicing for some stuff for myspace and possibly a DMC-Team event. The music I like is dance music, trip-hop, and turntablist experimental music. I like Anime including "Ghost in the Shell", "Patlabor" and the Comic-Book style epic "Broken Saints". I also like reading about theory's and papers on space other planets and the thought that we are not alone. As for programming started programming with VB, HTML and CSS on Windows 2000 (i dislike XP), moved into ASP and quickly started looking for an alternative.  So from that ive been studying PHP for about 4 years and on Linux (ubuntu + debian) for about a year and a half. I have no qualifications in computing although I did start some. I did a year of an Advanced GNVQ in IT which was a waste of time and then did a year of a computer engineering BTEC which was good but finacial problems led me to full time work. So now im just a bedroom coder fiddling with code all day. I would say im getting to the intermediate stage of PHP with thanks to some people on this site. Im currently working on server setups with apache and vhosting, chrooting ect. For PHP im working on PHP5-Sqlite programs for hosts that only allow so many MYSQL dbs. I would like to eventually get into writing a content management system or mmog. I would also like to get into graphic-design for abstract digital art, or comics and animation.
  9. cheers for that. you got some good bits in there. ill have good studying session on that.
  10. I can sort of see what your doing there. I think i might modify my design quite a bit now with some new chains and stuff to accomodate checks. thanks again for the help, i know where i need to go now.
  11. cheers thorpe. ill change my ssh and ive found some snippits of code for some protection too although i think some more reading is needed. ill mark this solved but thought i might post the snippits i found for anyone looking. #Protect against Address Spoofing: iptables -A INPUT -s localhost -i eth0 -j DROP #Protect against Smurf Attack: iptables -A INPUT -p icmp -d 192.168.0.255 -j DENY # broadcast address # Protect against Syn-Flood Attack: iptables -A INPUT -p tcp -syn -m limit --limit 1/s -j ACCEPT # Protect against Ping Flooding Attack: iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT
  12. thanks for the comments. i had a look for a file that you was on about but couldnt find anything other than the iptables programs and loads of random stuff in a /sys/ip_tables/ but im on ubuntu so mine might be different. ill do some more googling to see if i can understand the ubuntu /sys/ folder a bit better and i may find it. ill use this for now as my iptables does nothing otherwise and i want a purely homebrew firewall so i understand it better, and i didnt like way lokkit / firestarter configured it (too much junk). thanks again.
  13. ok ive been googling SH and IPtables for about 4 days and been writing the following script for my firewall. im going to put the file in my startup so its loaded automaticly. ive tested the script and it works but i would like to know about insecurities + ive got basic services running and ive hopefully restricted the comptuers that can use certain ports but have i done it right? i have 2 other machines, a flatmates winxp machine and another ubuntu machine. Both linux machines are runnning apache and thats the main reason i would like someone more experienced to check it over. The start / stop stuff i borrowed from another startup script. i assumed the lib/lsb functions were required. #!/bin/sh # # Notes: # # echo "Starting Firewall..." $ipt -F # Flush All Tables $ipt -Z # Zero All Counters . /lib/lsb/init-functions # Import init functions. do_start () { ipt="/sbin/iptables" # Set Program Directory + Variable safe1="192.168.0.4" # Safe IP Address' (For samba, ssh, xdmcp) safe2="192.168.0.2" myself="192.168.0.3" $ipt -P INPUT DROP # Set Policy of INPUT to DROP $ipt -P FORWARD DROP # Set Policy of FORWARD to DROP $ipt -P OUTPUT ACCEPT # Set Policy of OUTPUT to ACCEPT # CHAIN, TARGET, PROT+OPTIONS, IN/OUT, SOURCE, DESTINATION, MODULES $ipt -A INPUT -j ACCEPT -p tcp -i eth0 -m state --state ESTABLISHED,RELATED $ipt -A INPUT -j ACCEPT -p udp -i eth0 -m state --state ESTABLISHED,RELATED $ipt -A INPUT -j ACCEPT -p tcp --destination-port 22 -i eth0 -s 192.168.0.4 # tcp port 22: ssh Sources: ubuntu2 $ipt -A INPUT -j ACCEPT -p tcp --destination-port 80 --tcp-flags FIN,SYN,ACK,RST SYN -i eth0 # tcp port 80: www $ipt -A INPUT -j ACCEPT -p tcp --destination-port 137:139 -s $safe2 # tcp port 139: samba1 Sources: winxp $ipt -A INPUT -j ACCEPT -p tcp --destination-port 137:139 -s $safe1 # tcp port 139: samba2 Sources: ubuntu2 $ipt -A INPUT -j ACCEPT -p tcp --destination-port 137:139 -s $myself # tcp port 139: samba2 Sources: myself $ipt -A INPUT -j ACCEPT -p udp --destination-port 137:139 -s $safe2 # udp port 139: samba1 Sources: winxp $ipt -A INPUT -j ACCEPT -p udp --destination-port 137:139 -s $safe1 # udp port 139: samba2 Sources: ubuntu2 $ipt -A INPUT -j ACCEPT -p udp --destination-port 137:139 -s $myself # udp port 139: samba2 Sources: myself $ipt -A INPUT -j ACCEPT -p udp --destination-port 177 -i eth0 -s $safe1 # udp port 177: xdmcp $ipt -A INPUT -j ACCEPT -p tcp --destination-port 445 -i eth0 -s $safe2 # tcp port 445: MS-Directory Share Source: winxp $ipt -A INPUT -j ACCEPT -p tcp --destination-port 3306 -i lo # tcp port 3306: Mysql $ipt -A INPUT -j ACCEPT -p tcp --destination-port 6000 -i eth0 -s $safe2 # tcp port 6000: xdmcp Sources: ubuntu2 $ipt -A INPUT -j ACCEPT -p ALL -i lo # loopback $ipt -A INPUT -j LOG --log-level 3 --log-prefix '[ FW_INPUT_FAILURE ]' # log anything that fails to pass through. echo "Firewall Loaded." } case "$1" in start) do_start ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) echo "Stopping Firewall" ;; *) echo "Usage: $0 start" >&2 exit 3 ;; esac
  14. iptables IS your firewall config tool, u just got nothing configured. But anyway it cant be the problem, so sorry it didnt help.
  15. u could use a bash/sh script + cronjob for it too. check out this: Example A-26 on this website might be usefull to you. http://tldp.org/LDP/abs/html/contributed-scripts.html#ARCHIVWEBLOGS
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.